Upload folder using huggingface_hub
Browse files- LICENSE +88 -0
- README.md +75 -0
- config.json +30 -0
- fig_accuracy_latency_v2.png +0 -0
- mobileclip2_coca_dfn2b_s13b_dci-complete_s12m_context77.pt +3 -0
    	
        LICENSE
    ADDED
    
    | @@ -0,0 +1,88 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            Disclaimer: IMPORTANT: This Apple Machine Learning Research Model is
         | 
| 2 | 
            +
            specifically developed and released by Apple Inc. ("Apple") for the sole purpose
         | 
| 3 | 
            +
            of scientific research of artificial intelligence and machine-learning
         | 
| 4 | 
            +
            technology. “Apple Machine Learning Research Model” means the model, including
         | 
| 5 | 
            +
            but not limited to algorithms, formulas, trained model weights, parameters,
         | 
| 6 | 
            +
            configurations, checkpoints, and any related materials (including
         | 
| 7 | 
            +
            documentation).
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            This Apple Machine Learning Research Model is provided to You by
         | 
| 10 | 
            +
            Apple in consideration of your agreement to the following terms, and your use,
         | 
| 11 | 
            +
            modification, creation of Model Derivatives, and or redistribution of the Apple
         | 
| 12 | 
            +
            Machine Learning Research Model constitutes acceptance of this Agreement. If You
         | 
| 13 | 
            +
            do not agree with these terms, please do not use, modify, create Model
         | 
| 14 | 
            +
            Derivatives of, or distribute this Apple Machine Learning Research Model or
         | 
| 15 | 
            +
            Model Derivatives.
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            * License Scope: In consideration of your agreement to abide by the following
         | 
| 18 | 
            +
              terms, and subject to these terms, Apple hereby grants you a personal,
         | 
| 19 | 
            +
              non-exclusive, worldwide, non-transferable, royalty-free, revocable, and
         | 
| 20 | 
            +
              limited license, to use, copy, modify, distribute, and create Model
         | 
| 21 | 
            +
              Derivatives (defined below) of the Apple Machine Learning Research Model
         | 
| 22 | 
            +
              exclusively for Research Purposes. You agree that any Model Derivatives You
         | 
| 23 | 
            +
              may create or that may be created for You will be limited to Research Purposes
         | 
| 24 | 
            +
              as well. “Research Purposes” means non-commercial scientific research and
         | 
| 25 | 
            +
              academic development activities, such as experimentation, analysis, testing
         | 
| 26 | 
            +
              conducted by You with the sole intent to advance scientific knowledge and
         | 
| 27 | 
            +
              research. “Research Purposes” does not include any commercial exploitation,
         | 
| 28 | 
            +
              product development or use in any commercial product or service.
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            * Distribution of Apple Machine Learning Research Model and Model Derivatives:
         | 
| 31 | 
            +
              If you choose to redistribute Apple Machine Learning Research Model or its
         | 
| 32 | 
            +
              Model Derivatives, you must provide a copy of this Agreement to such third
         | 
| 33 | 
            +
              party, and ensure that the following attribution notice be provided: “Apple
         | 
| 34 | 
            +
              Machine Learning Research Model is licensed under the Apple Machine Learning
         | 
| 35 | 
            +
              Research Model License Agreement.” Additionally, all Model Derivatives must
         | 
| 36 | 
            +
              clearly be identified as such, including disclosure of modifications and
         | 
| 37 | 
            +
              changes made to the Apple Machine Learning Research Model. The name,
         | 
| 38 | 
            +
              trademarks, service marks or logos of Apple may not be used to endorse or
         | 
| 39 | 
            +
              promote Model Derivatives or the relationship between You and Apple. “Model
         | 
| 40 | 
            +
              Derivatives” means any models or any other artifacts created by modifications,
         | 
| 41 | 
            +
              improvements, adaptations, alterations to the architecture, algorithm or
         | 
| 42 | 
            +
              training processes of the Apple Machine Learning Research Model, or by any
         | 
| 43 | 
            +
              retraining, fine-tuning of the Apple Machine Learning Research Model.
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            * No Other License: Except as expressly stated in this notice, no other rights
         | 
| 46 | 
            +
              or licenses, express or implied, are granted by Apple herein, including but
         | 
| 47 | 
            +
              not limited to any patent, trademark, and similar intellectual property rights
         | 
| 48 | 
            +
              worldwide that may be infringed by the Apple Machine Learning Research Model,
         | 
| 49 | 
            +
              the Model Derivatives or by other works in which the Apple Machine Learning
         | 
| 50 | 
            +
              Research Model may be incorporated.
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            * Compliance with Laws: Your use of Apple Machine Learning Research Model must
         | 
| 53 | 
            +
              be in compliance with all applicable laws and regulations.
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            * Term and Termination: The term of this Agreement will begin upon your
         | 
| 56 | 
            +
              acceptance of this Agreement or use of the Apple Machine Learning Research
         | 
| 57 | 
            +
              Model and will continue until terminated in accordance with the following
         | 
| 58 | 
            +
              terms. Apple may terminate this Agreement at any time if You are in breach of
         | 
| 59 | 
            +
              any term or condition of this Agreement. Upon termination of this Agreement,
         | 
| 60 | 
            +
              You must cease to use all Apple Machine Learning Research Models and Model
         | 
| 61 | 
            +
              Derivatives and permanently delete any copy thereof. Sections 3, 6 and 7 will
         | 
| 62 | 
            +
              survive termination.
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            * Disclaimer and Limitation of Liability: This Apple Machine Learning Research
         | 
| 65 | 
            +
              Model and any outputs generated by the Apple Machine Learning Research Model
         | 
| 66 | 
            +
              are provided on an “AS IS” basis. APPLE MAKES NO WARRANTIES, EXPRESS OR
         | 
| 67 | 
            +
              IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
         | 
| 68 | 
            +
              NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
         | 
| 69 | 
            +
              REGARDING THE APPLE MACHINE LEARNING RESEARCH MODEL OR OUTPUTS GENERATED BY
         | 
| 70 | 
            +
              THE APPLE MACHINE LEARNING RESEARCH MODEL. You are solely responsible for
         | 
| 71 | 
            +
              determining the appropriateness of using or redistributing the Apple Machine
         | 
| 72 | 
            +
              Learning Research Model and any outputs of the Apple Machine Learning Research
         | 
| 73 | 
            +
              Model and assume any risks associated with Your use of the Apple Machine
         | 
| 74 | 
            +
              Learning Research Model and any output and results. IN NO EVENT SHALL APPLE BE
         | 
| 75 | 
            +
              LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
         | 
| 76 | 
            +
              IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF
         | 
| 77 | 
            +
              THE APPLE MACHINE LEARNING RESEARCH MODEL AND ANY OUTPUTS OF THE APPLE MACHINE
         | 
| 78 | 
            +
              LEARNING RESEARCH MODEL, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
         | 
| 79 | 
            +
              TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS
         | 
| 80 | 
            +
              BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
         | 
| 81 | 
            +
             | 
| 82 | 
            +
            * Governing Law: This Agreement will be governed by and construed under the laws
         | 
| 83 | 
            +
              of the State of California without regard to its choice of law principles. The
         | 
| 84 | 
            +
              Convention on Contracts for the International Sale of Goods shall not apply to
         | 
| 85 | 
            +
              the Agreement except that the arbitration clause and any arbitration hereunder
         | 
| 86 | 
            +
              shall be governed by the Federal Arbitration Act, Chapters 1 and 2. 
         | 
| 87 | 
            +
             | 
| 88 | 
            +
            Copyright (C) 2025 Apple Inc. All Rights Reserved.
         | 
    	
        README.md
    ADDED
    
    | @@ -0,0 +1,75 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            license: apple-amlr
         | 
| 3 | 
            +
            license_name: apple-ascl
         | 
| 4 | 
            +
            license_link: https://github.com/apple/ml-mobileclip/blob/main/LICENSE_weights_data
         | 
| 5 | 
            +
            library_name: mobileclip
         | 
| 6 | 
            +
            ---
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            # MobileCLIP2: Improving Multi-Modal Reinforced Training
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            MobileCLIP2 was introduced in [MobileCLIP2: Improving Multi-Modal Reinforced Training]() (TMLR 2025), by Fartash Faghri, Pavan Kumar Anasosalu Vasu, Cem Koc, Vaishaal Shankar, Alexander T Toshev, Oncel Tuzel, Hadi Pouransari.
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            This repository contains the **CoCa** checkpoint pretrained on DFN-2B dataset and fine-tuned on varying datasets.
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            ### Highlights
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            * `MobileCLIP2-S4` matches the accuracy of SigLIP-SO400M/14 with 2x fewer parameters and surpasses DFN ViT-L/14 at 2.5x lower latency measured on iPhone12 Pro Max.
         | 
| 19 | 
            +
            * `MobileCLIP-S3/S4` are our new architectures trained on MobileCLIP’s training dataset, DataCompDR-1B (dashed lines).
         | 
| 20 | 
            +
            * Our smallest variant `MobileCLIP-S0` obtains similar zero-shot performance as [OpenAI](https://arxiv.org/abs/2103.00020)'s ViT-B/16 model while being 4.8x faster and 2.8x smaller.
         | 
| 21 | 
            +
            * `MobileCLIP-S2` obtains better avg zero-shot performance than [SigLIP](https://arxiv.org/abs/2303.15343)'s ViT-B/16 model while being 2.3x faster and 2.1x smaller, and trained with 3x less seen samples.
         | 
| 22 | 
            +
            * `MobileCLIP-B (LT)` attains zero-shot ImageNet performance of **77.2%** which is significantly better than recent works like [DFN](https://arxiv.org/abs/2309.17425) and [SigLIP](https://arxiv.org/abs/2303.15343) with similar architectures or even [OpenAI's ViT-L/14@336](https://arxiv.org/abs/2103.00020).
         | 
| 23 | 
            +
             | 
| 24 | 
            +
             | 
| 25 | 
            +
            ## Checkpoints
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            | Model                                                     | # Seen <BR>Samples (B) | # Params (M) <BR> (img + txt) | Latency (ms) <BR> (img + txt) | IN-1k Zero-Shot <BR> Top-1 Acc. (%) | Avg. Perf. (%) <BR> on 38 datasets |
         | 
| 28 | 
            +
            |:----------------------------------------------------------|:----------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------------:|:----------------------------------:|
         | 
| 29 | 
            +
            | [MobileCLIP2-S0](https://hf.co/apple/MobileCLIP2-S0)      |           13           |          11.4 + 42.4          |           1.5 + 1.6           |               71.5                 |                59.7                 |
         | 
| 30 | 
            +
            | [MobileCLIP2-S2](https://hf.co/apple/MobileCLIP2-S2)      |           13           |          35.7 + 63.4          |           3.6 + 3.3           |               77.2                 |                64.1                 |
         | 
| 31 | 
            +
            | [MobileCLIP2-B](https://hf.co/apple/MobileCLIP2-B)        |           13           |          86.3 + 63.4          |          10.4 + 3.3           |               79.4                 |                65.8                 |
         | 
| 32 | 
            +
            | [MobileCLIP2-S3](https://hf.co/apple/MobileCLIP2-S3)      |           13           |         125.1 + 123.6         |           8.0 + 6.6           |               80.7                 |                66.8                 |
         | 
| 33 | 
            +
            | [MobileCLIP2-L/14](https://hf.co/apple/MobileCLIP2-L-14)  |           13           |         304.3 + 123.6         |          57.9 + 6.6           |               81.9                 |                67.8                 |
         | 
| 34 | 
            +
            | [MobileCLIP2-S4](https://hf.co/apple/MobileCLIP2-S4)      |           13           |         321.6 + 123.6         |          19.6 + 6.6           |               81.9                 |                67.5                 |
         | 
| 35 | 
            +
            | [MobileCLIP-S0](https://hf.co/apple/MobileCLIP-S0)        |           13           |          11.4 + 42.4          |           1.5 + 1.6           |               67.8                 |                58.1                 |
         | 
| 36 | 
            +
            | [MobileCLIP-S1](https://hf.co/apple/MobileCLIP-S1)        |           13           |          21.5 + 63.4          |           2.5 + 3.3           |               72.6                 |                61.3                 |
         | 
| 37 | 
            +
            | [MobileCLIP-S2](https://hf.co/apple/MobileCLIP-S2)        |           13           |          35.7 + 63.4          |           3.6 + 3.3           |               74.4                 |                63.7                 |
         | 
| 38 | 
            +
            | [MobileCLIP-B](https://hf.co/apple/MobileCLIP-B)          |           13           |          86.3 + 63.4          |          10.4 + 3.3           |               76.8                 |                65.2                 |
         | 
| 39 | 
            +
            | [MobileCLIP-B (LT)](https://hf.co/apple/MobileCLIP-B-LT)  |           36           |          86.3 + 63.4          |          10.4 + 3.3           |               77.2                 |                65.8                 |
         | 
| 40 | 
            +
            | [MobileCLIP-S3](https://hf.co/apple/MobileCLIP-S3)        |           13           |         125.1 + 123.6         |           8.0 + 6.6           |               78.3                 |                66.3                 |
         | 
| 41 | 
            +
            | [MobileCLIP-L/14](https://hf.co/apple/MobileCLIP-L-14)    |           13           |         304.3 + 123.6         |          57.9 + 6.6           |               79.5                 |                66.9                 |
         | 
| 42 | 
            +
            | [MobileCLIP-S4](https://hf.co/apple/MobileCLIP-S4)        |           13           |         321.6 + 123.6         |          19.6 + 6.6           |               79.4                 |                68.1                 |
         | 
| 43 | 
            +
             | 
| 44 | 
            +
             | 
| 45 | 
            +
            ## How to Use
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            First, download the desired checkpoint visiting one of the links in the table above, then click the `Files and versions` tab, and download the PyTorch checkpoint.
         | 
| 48 | 
            +
            For programmatic downloading, if you have `huggingface_hub` installed, you can also run:
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            ```
         | 
| 51 | 
            +
            hf download apple/mobileclip2_coca_dfn2b_s13b_<finetune-dataset>_context<length>
         | 
| 52 | 
            +
            ``` 
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            For models length with context lengths 128/256, copy `config.json` to `src/open_clip/model_configs/coca_ViT-L-14-context$len.json` and change the model name in below example to `coca_ViT-L-14-context$len`.
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            ```py
         | 
| 57 | 
            +
            import torch
         | 
| 58 | 
            +
            import open_clip
         | 
| 59 | 
            +
            from PIL import Image
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            model, _, preprocess = open_clip.create_model_and_transforms('coca_ViT-L-14', pretrained='/path/to/mobileclip2_coca.pt')
         | 
| 62 | 
            +
            model.eval()
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            image = preprocess(Image.open("docs/fig_accuracy_latency.png").convert('RGB')).unsqueeze(0)
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            with torch.no_grad(), torch.cuda.amp.autocast():
         | 
| 67 | 
            +
                syn_text = model.generate(
         | 
| 68 | 
            +
                    image,
         | 
| 69 | 
            +
                    generation_type="top_p",
         | 
| 70 | 
            +
                    top_p=0.9,
         | 
| 71 | 
            +
                    fixed_output_length=True
         | 
| 72 | 
            +
                )[0]
         | 
| 73 | 
            +
                syn_text = open_clip.decode(syn_text).split("<end_of_text>")[0].split("<start_of_text>")[-1].split(".")[0].rstrip()
         | 
| 74 | 
            +
            print("Caption:", syn_text)
         | 
| 75 | 
            +
            ```
         | 
    	
        config.json
    ADDED
    
    | @@ -0,0 +1,30 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "embed_dim": 768,
         | 
| 3 | 
            +
                "vision_cfg": {
         | 
| 4 | 
            +
                    "image_size": 224,
         | 
| 5 | 
            +
                    "layers": 24,
         | 
| 6 | 
            +
                    "width": 1024,
         | 
| 7 | 
            +
                    "patch_size": 14,
         | 
| 8 | 
            +
                    "attentional_pool": true,
         | 
| 9 | 
            +
                    "attn_pooler_heads": 8,
         | 
| 10 | 
            +
                    "output_tokens": true
         | 
| 11 | 
            +
                },
         | 
| 12 | 
            +
                "text_cfg": {
         | 
| 13 | 
            +
                    "context_length": 76,
         | 
| 14 | 
            +
                    "vocab_size": 49408,
         | 
| 15 | 
            +
                    "width": 768,
         | 
| 16 | 
            +
                    "heads": 12,
         | 
| 17 | 
            +
                    "layers": 12,
         | 
| 18 | 
            +
                    "embed_cls": true,
         | 
| 19 | 
            +
                    "output_tokens": true
         | 
| 20 | 
            +
                },
         | 
| 21 | 
            +
                "multimodal_cfg": {
         | 
| 22 | 
            +
                    "context_length": 76,
         | 
| 23 | 
            +
                    "vocab_size": 49408,
         | 
| 24 | 
            +
                    "width": 768,
         | 
| 25 | 
            +
                    "heads": 12,
         | 
| 26 | 
            +
                    "layers": 12,
         | 
| 27 | 
            +
                    "attn_pooler_heads": 12
         | 
| 28 | 
            +
                },
         | 
| 29 | 
            +
                "custom_text": true
         | 
| 30 | 
            +
            }
         | 
    	
        fig_accuracy_latency_v2.png
    ADDED
    
    |   | 
    	
        mobileclip2_coca_dfn2b_s13b_dci-complete_s12m_context77.pt
    ADDED
    
    | @@ -0,0 +1,3 @@ | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            version https://git-lfs.github.com/spec/v1
         | 
| 2 | 
            +
            oid sha256:2732d7807aae210d06d6f9763db0e91ce34b4facfa7c73de751d9e852184de9b
         | 
| 3 | 
            +
            size 2554125740
         | 
