apple-aiml-research/ml-mobileclip

This repository contains the official implementation of the research papers, "MobileCLIP" CVPR 2024 and "MobileCLIP2" TMLR August 2025

📦 What is MobileCLIP?

MobileCLIP(및 최신 버전인 MobileCLIP2)은 스마트폰과 같이 연산 능력이 제한된 기기에서 제로샷 분류 및 캡션 생성을 수행하도록 설계된 소형, 고속 이미지-텍스트 모델입니다. 이 모델들은 대규모 이미지-텍스트 데이터(DataCompDR, DFNDR)와 CoCa 모델로 생성된 합성 캡션을 혼합한 multi-modal reinforced training 방식을 통해 훈련되었습니다. 목표는 2-5배 적은 파라미터훨씬 낮은 지연 시간(특히 iPhone 하드웨어에서)을 사용하면서도 대형 CLIP 스타일 모델의 정확도에 필적하는 정확도를 달성하는 것입니다.


🎯 Key Features & Highlights (from the README)

| Feature | Detail | |---|---|| | Model families | MobileCLIP-S0…S4, MobileCLIP-B, MobileCLIP-L/14 및 최신 MobileCLIP2-S0…S4, MobileCLIP2-B, MobileCLIP2-L/14 | | Speed / size | 가장 작은 변체(MobileCLIP-S0)는 OpenAI의 ViT-B/16보다 4.8배 빠르고 2.8배 작으며, 유사한 제로샷 성능을 유지합니다. MobileCLIP2-S4는 iPhone 12 Pro Max에서 약 20ms(이미지 + 텍스트)로 실행되어, 훨씬 더 큰 모델에 필적하는 정확도를 제공합니다. | | Accuracy | MobileCLIP-B (LT)는 ImageNet-1k 제로샷에서 77.2% top-1에 도달합니다. MobileCLIP2-S4는 단 13B개의 샘플을 보고 **81.9%**를 달성합니다. | | Training data | DataCompDR-1B 데이터셋(MobileCLIP용) 및 DFNDR 데이터셋(MobileCLIP2용)으로 훈련되었습니다. | | Open-source tooling | 추론, 훈련 및 평가 스크립트가 제공됩니다. 모델은 작은 패치를 통해 OpenCLIP과도 호환됩니다. | | Mobile demo | iOS 앱(ios_app/)이 기기 내 실시간 제로샷 분류를 보여줍니다. | | Model releases | 사전 학습된 체크포인트는 HuggingFace(예: apple/MobileCLIP2-S0)에 호스팅됩니다. |


🚀 Getting Started (quick-start)

  1. Create a conda environment
    conda create -n clipenv python=3.10
    conda activate clipenv
    pip install -e .
    
  2. Download a checkpoint (example for the smallest MobileCLIP2 model)
    hf download apple/MobileCLIP2-S0   # stores the .pt file locally
    
  3. Run a one-liner inference
    import torch, open_clip
    from PIL import Image
    from mobileclip.modules.common.mobileone import reparameterize_model
    
    model_name = "MobileCLIP2-S0"
    model_path = "/path/to/MobileCLIP2-S0.pt"
    model, _, preprocess = open_clip.create_model_and_transforms(
        model_name, pretrained=model_path)
    tokenizer = open_clip.get_tokenizer(model_name)
    model.eval()
    model = reparameterize_model(model)   # required for batch-norm based models
    
    img = preprocess(Image.open("docs/fig_accuracy_latency.png").convert("RGB")).unsqueeze(0)
    txt = tokenizer(["a diagram", "a dog", "a cat"])
    with torch.no_grad(), torch.cuda.amp.autocast():
        img_feat = model.encode_image(img)
        txt_feat = model.encode_text(txt)
        img_feat = img_feat / img_feat.norm(dim=-1, keepdim=True)
        txt_feat = txt_feat / txt_feat.norm(dim=-1, keepdim=True)
        probs = (100.0 * img_feat @ txt_feat.T).softmax(dim=-1)
    print("Label probs:", probs)
    
    이 코드는 세 가지 텍스트 프롬프트에 대한 확률을 출력합니다.

📚 Training & Evaluation

  • Training – 이 저장소에는 OpenCLIP 코드베이스를 사용하여 MobileCLIP/2 모델을 훈련하는 training/ 폴더가 포함되어 있습니다. README는 대규모 멀티모달 강화 데이터셋을 생성하기 위한 별도의 저장소(ml-mobileclip-dr)를 가리킵니다.
  • Evaluation – 제로샷 ImageNet-1k 평가는 다음과 같이 실행할 수 있습니다:
    python eval/zeroshot_imagenet.py --model-arch mobileclip_s0 \
        --model-path /path/to/mobileclip_s0.pt
    
    전체 38개 데이터셋 벤치마킹을 수행하려면 datacomp 저장소를 따르십시오.

📱 iOS Demo

ios_app/ 디렉토리는 MobileCLIP 모델을 로드하여 카메라 프레임에서 실시간 분류를 수행하는 최소한의 iOS 애플리케이션을 포함하고 있습니다. 이는 모델의 온디바이스 지연 시간을 입증합니다.


📦 Model Zoo (selected checkpoints)

Model Params (M) Latency (ms) img+txt ImageNet-1k Zero-Shot
MobileCLIP2-S0 11.4 + 63.4 1.5 + 3.3 71.5
MobileCLIP2-S2 35.7 + 63.4 3.6 + 3.3 77.2
MobileCLIP2-B 86.3 + 63.4 10.4 + 3.3 79.4
MobileCLIP2-S4 321.6 + 123.6 19.6 + 6.6 81.9
MobileCLIP-B (LT) 86.3 + 63.4 10.4 + 3.3 77.2

모든 체크포인트는 README에 링크된 HuggingFace 컬렉션에서 다운로드할 수 있습니다.


🧩 CoCa Caption Models

이 저장소는 DFNDR-2B 데이터셋을 위한 합성 캡션을 생성하는 데 사용된 CoCa 모델도 함께 제공합니다. 이 모델들은 CLIP 모델과 동일한 방식으로 OpenCLIP을 통해 로드할 수 있으며, 캡션 생성에 대한 짧은 예제가 제공됩니다.


📜 License

  • Code – MIT License
  • Model weights – Apple ML Research Model Terms of Use (허용적인 연구 전용 라이선스)
  • Data – CC-BY-NC-ND 4.0 (비상업적, 저작물 변경 불가)

📖 Citation

연구에서 MobileCLIP 또는 MobileCLIP2를 사용하는 경우, README에 나열된 두 개의 논문을 인용하십시오 (CVPR 2024 및 TMLR 2025).


TL;DR

MobileCLIP은 모바일 기기에 최적화된 소형, 고속 CLIP 스타일의 시각 언어 모델 제품군입니다. 이 저장소는 사용 가능한 사전 학습된 체크포인트, 훈련 스크립트(OpenCLIP을 통해), 평가 도구 및 iOS 데모를 제공하며, 모두 허용적인 라이선스 하에 있습니다.

관련

  • 프로젝트
  • 프로젝트
  • 프로젝트
  • 프로젝트