CLIP ViT-L/14 task experts: 8 vision tasks, 10 epochs

Full fine-tunes of the image encoder of openai/clip-vit-large-patch14 on the 8-task vision benchmark commonly used for model merging and task arithmetic: SUN397, Stanford Cars, RESISC45, EuroSAT, GTSRB, DTD, Food101 and FER2013. There are 8 runs, one per task, all at learning rate 3e-5. Every epoch was checkpointed, so the repo also supports checkpoint-selection and training-duration studies.

Training recipe

All runs use the same recipe, at learning rate 3e-5.

  • Model: a CLIP image encoder followed by a linear head, logits = head(normalize(clip.get_image_features(x))).
  • Head: initialized from the zero-shot text embeddings of the class prompts times logit_scale, with zero bias, and frozen. Only the image tower (vision_model and visual_projection) is trained. The text tower in the checkpoint is unchanged from the base model.
  • Optimizer: AdamW (torch fused), betas (0.9, 0.999), weight decay 0, max grad norm 1.0.
  • Schedule: linear decay with 10% warmup over 10 epochs, batch size 32, fp16 mixed precision, seed 42.
  • Preprocessing: the CLIP image processor only (resize to 224, center crop, normalize), with no data augmentation. The training log prints Data augmentation: True, but that flag is not applied anywhere.
  • Evaluation: once per epoch on the evaluation split (the test split, or validation for Food101, which has no test split).
  • Model selection: load_best_model_at_end=True with metric_for_best_model=accuracy, evaluated on that same split.
  • Software: transformers 4.57.6 and torch 2.9.1.

Note on model selection. The top-level model.safetensors of each run is the best epoch by accuracy on the evaluation split, and that split is the test set for 7 of the 8 tasks. Its accuracy is therefore an optimistic number. For a selection-free comparison, use a fixed epoch (for example checkpoint-<10 x steps/epoch>, the last epoch) from the tables below.

Layout

<task>_openai_clip-vit-large-patch14_ep10_bs32_lr<LR>/
  model.safetensors          # best epoch (see table), weights of the wrapper: model.* = CLIPModel, classifier.* = frozen head
  checkpoint-<step>/         # one per epoch, step = epoch x steps/epoch; weights + trainer_state.json (optimizer state not saved)
  train.log                  # raw training log
  runs/                      # tensorboard events
  preprocessor_config.json, tokenizer files, training_args.bin

Results

Accuracy is in %, on the evaluation split described above.

Folder Task LR Train Eval Steps/epoch model.safetensors acc Best epoch Epoch-10 acc
dtd_openai_clip-vit-large-patch14_ep10_bs32_lr3e-5/ dtd 3e-5 3,760 1,880 (test) 118 82.82 10 (checkpoint-1180) 82.82
eurosat_openai_clip-vit-large-patch14_ep10_bs32_lr3e-5/ eurosat 3e-5 21,600 2,700 (test) 675 99.26 9 (checkpoint-6075) 99.19
fer2013_openai_clip-vit-large-patch14_ep10_bs32_lr3e-5/ fer2013 3e-5 28,709 7,178 (test) 898 74.70 10 (checkpoint-8980) 74.70
food101_openai_clip-vit-large-patch14_ep10_bs32_lr3e-5/ food101 3e-5 75,750 25,250 (validation) 2368 92.80 10 (checkpoint-23680) 92.80
gtsrb_openai_clip-vit-large-patch14_ep10_bs32_lr3e-5/ gtsrb 3e-5 26,640 12,630 (test) 833 99.41 6 (checkpoint-4998) 99.08
resisc45_openai_clip-vit-large-patch14_ep10_bs32_lr3e-5/ resisc45 3e-5 18,900 6,300 (test) 591 96.30 9 (checkpoint-5319) 96.30
stanford-cars_openai_clip-vit-large-patch14_ep10_bs32_lr3e-5/ stanford-cars 3e-5 8,144 8,041 (test) 255 92.35 10 (checkpoint-2550) 92.35
sun397_openai_clip-vit-large-patch14_ep10_bs32_lr3e-5/ sun397 3e-5 19,850 19,850 (test) 621 78.77 9 (checkpoint-5589) 78.76

Accuracy per epoch

Task LR ep1 ep2 ep3 ep4 ep5 ep6 ep7 ep8 ep9 ep10
dtd 3e-5 71.06 73.94 77.13 77.98 78.51 79.63 82.45 81.97 82.61 82.82
eurosat 3e-5 92.67 96.19 97.63 98.78 97.96 98.74 98.15 99.11 99.26 99.19
fer2013 3e-5 66.30 70.13 70.79 72.57 72.89 72.99 73.56 73.77 74.03 74.70
food101 3e-5 84.74 88.72 89.17 89.37 89.43 90.33 91.28 91.63 92.55 92.80
gtsrb 3e-5 97.19 97.92 97.93 98.00 98.99 99.41 99.22 98.90 98.90 99.08
resisc45 3e-5 87.24 91.76 93.10 93.75 93.67 96.16 96.02 95.87 96.30 96.30
stanford-cars 3e-5 79.01 79.44 84.45 82.15 87.36 88.50 90.29 91.61 92.18 92.35
sun397 3e-5 69.74 73.08 73.11 73.10 74.77 75.85 77.07 78.22 78.77 78.76

Loading

import torch
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
from transformers import CLIPModel, CLIPImageProcessor

repo = "theblackcat102/clip-vit-large-patch14-task-experts-ep10"
run = "dtd_openai_clip-vit-large-patch14_ep10_bs32_lr3e-5"   # or f"{run}/checkpoint-<step>/model.safetensors"
sd = load_file(hf_hub_download(repo, f"{run}/model.safetensors"))

clip = CLIPModel.from_pretrained("openai/clip-vit-large-patch14")
clip.load_state_dict({k[len("model."):]: v for k, v in sd.items() if k.startswith("model.")})
W, b = sd["classifier.weight"], sd["classifier.bias"]          # [num_classes, 768], frozen zero-shot head
processor = CLIPImageProcessor.from_pretrained("openai/clip-vit-large-patch14")

@torch.no_grad()
def predict(images):
    x = processor(images=[im.convert("RGB") for im in images], return_tensors="pt")["pixel_values"]
    f = clip.get_image_features(pixel_values=x)
    return ((f / f.norm(dim=-1, keepdim=True)) @ W.T + b).argmax(-1)

We checked this snippet on the DTD run: it gets 82.87% on the 1,880 DTD test images, against 82.82% in the training log (fp16 eval). The class order follows the label feature of each dataset listed above.

For task vectors, use the difference between vision_model.* / visual_projection.* and the same keys of openai/clip-vit-large-patch14.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for theblackcat102/clip-vit-large-patch14-task-experts-ep10

Finetuned
(165)
this model

Datasets used to train theblackcat102/clip-vit-large-patch14-task-experts-ep10