Team Ai
Modelpublic

apple/DFN5B-CLIP-ViT-H-14

sourceHugging Faceapple-amlrupdated 2y agoView on Hugging Face
47likes32kdownloads
Model Card

A CLIP (Contrastive Language-Image Pre-training) model trained on DFN-5B. Data Filtering Networks (DFNs) are small networks used to automatically filter large pools of uncurated data. This model was trained on 5B images that were filtered from a pool of 43B uncurated image-text pairs (12.8B image-text pairs from CommonPool-12.8B + 30B additional public image-text pairs).

This model has been converted to PyTorch from the original JAX checkpoints from Axlearn (https://github.com/apple/axlearn). These weights are directly usable in OpenCLIP (image + text).

Model Details

  • —Model Type: Contrastive Image-Text, Zero-Shot Image Classification.
  • —Dataset: DFN-5b
  • —Papers:
  • —Data Filtering Networks: https://arxiv.org/abs/2309.17425
  • —Samples Seen: 39B

Model Metrics

Eval DatasetMetric
ImageNet 1k0.8344
Caltech-1010.954935
CIFAR-100.9878
CIFAR-1000.9051
CLEVR Counts0.2966
CLEVR Distance0.2124
Country2110.343981
Describable Textures0.706383
EuroSAT0.654815
FGVC Aircraft0.714055
Food-1010.956792
GTSRB0.677514
ImageNet Sketch0.727308
ImageNet v20.773
ImageNet-A0.6988
ImageNet-O0.381
ImageNet-R0.929367
KITTI Vehicle Distance0.336146
MNIST0.8579
ObjectNet0.765156
Oxford Flowers-1020.899534
Oxford-IIIT Pet0.965515
Pascal VOC 20070.818309
PatchCamelyon0.653625
Rendered SST20.546403
RESISC450.750476
Stanford Cars0.957592
STL-100.989
SUN3970.769149
SVHN0.676168
Flickr0.8645
MSCOCO0.631112
WinoGAViL0.556329
iWildCam0.205549
Camelyon170.705034
FMoW0.207482
Dollar Street0.699766
GeoDE0.928184
Average0.698347

Model Usage

With OpenCLIP

import torch
import torch.nn.functional as F
from urllib.request import urlopen
from PIL import Image
from open_clip import create_model_from_pretrained, get_tokenizer 

model, preprocess = create_model_from_pretrained('hf-hub:apple/DFN5B-CLIP-ViT-H-14')
tokenizer = get_tokenizer('ViT-H-14')

image = Image.open(urlopen(
    'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
image = preprocess(image).unsqueeze(0)

labels_list = ["a dog", "a cat", "a donut", "a beignet"]
text = tokenizer(labels_list, context_length=model.context_length)

with torch.no_grad(), torch.cuda.amp.autocast():
    image_features = model.encode_image(image)
    text_features = model.encode_text(text)
    image_features = F.normalize(image_features, dim=-1)
    text_features = F.normalize(text_features, dim=-1)

    text_probs = torch.sigmoid(image_features @ text_features.T * model.logit_scale.exp() + model.logit_bias)

zipped_list = list(zip(labels_list, [round(p.item(), 3) for p in text_probs[0]]))
print("Label probabilities: ", zipped_list)

Citation

bibtex
@article{fang2023data,
  title={Data Filtering Networks},
  author={Fang, Alex and Jose, Albin Madappally and Jain, Amit and Schmidt, Ludwig and Toshev, Alexander and Shankar, Vaishaal},
  journal={arXiv preprint arXiv:2309.17425},
  year={2023}
}