Scaling up contrastive language-image pretraining (CLIP) is critical for empowering both vision and multimodal models. We present EVA-CLIP-18B, the largest and most powerful open-source CLIP model to date, with 18-billion parameters. With only 6-billion training samples seen, EVA-CLIP-18B achieves an exceptional
80.7%
zero-shot top-1 accuracy averaged across 27 widely recognized image classification benchmarks, outperforming its forerunner EVA-CLIP (5-billion parameters) and other open-source CLIP models by a large margin. Remarkably, we observe a consistent performance improvement with the model size scaling of EVA-CLIP, despite maintaining a constant training dataset of 2-billion image-text pairs from LAION-2B and COYO-700M. This dataset is openly available and much smaller than the in-house datasets (e.g., DFN-5B, WebLI-10B) employed in other state-of-the-art CLIP models. EVA-CLIP-18B demonstrates the potential of EVA-style weak-to-strong visual model scaling. With our model weights made publicly available, we hope to facilitate future research in vision and multimodal foundation models.
Scaling behavior of EVA-CLIP with zero-shot classification performance averaged across 27 image classification benchmarks, compared with the current state-of-the-art and largest CLIP models (224px). The diameter of each circle demonstrates the forward GFLOPs × the number of training samples seen. The performance of EVA-CLIP consistently improves as scaling up.
To construct Merged-2B, we merged 1.6 billion samples from
LAION-2B
dataset with 0.4 billion samples from
COYO-700M
.
The Merged-2B+ consists of all samples from Merged-2B, along with 20 millions samples from
LAION-COCO
and 23 millions samples from Merged-video including
VideoCC
,
InternVid
and
WebVid-10M
. Merged-video was added at the end of the training process.
It's important to note that all results presented in the paper are evaluated using PyTorch weights. There may be differences in performance when using Hugging Face (hf) models.
Zero-Shot Evaluation
We use
CLIP-Benchmark
to evaluate the zero-shot performance of EVA-CLIP models. Following
vissl
, we evauate the zero-shot video classification using 1 middle frame. Further details regarding the evaluation datasets can be found in our paper, particularly in Table 11.
Usage
Huggingface Version
from PIL import Image
from transformers import AutoModel, AutoConfig
from transformers import CLIPImageProcessor, pipeline, CLIPTokenizer
import torch
import torchvision.transforms as T
from torchvision.transforms import InterpolationMode
image_path = "CLIP.png"
model_name_or_path = "BAAI/EVA-CLIP-18B"# or /path/to/local/EVA-CLIP-18B
image_size = 224
processor = CLIPImageProcessor.from_pretrained("openai/clip-vit-large-patch14")
# use image processor with conig# processor = CLIPImageProcessor(size={"shortest_edge":image_size}, do_center_crop=True, crop_size=image_size)## you can also directly use the image processor by torchvision## squash# processor = T.Compose(# [# T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),# T.Resize((image_size, image_size), interpolation=InterpolationMode.BICUBIC),# T.ToTensor(),# T.Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))# ]# )## shortest## processor = T.Compose(# [# T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),# T.Resize(image_size, interpolation=InterpolationMode.BICUBIC),# T.CenterCrop(image_size),# T.ToTensor(),# T.Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))# ]# )
model = AutoModel.from_pretrained(
model_name_or_path,
torch_dtype=torch.float16,
trust_remote_code=True).to('cuda').eval()
image = Image.open(image_path)
captions = ["a diagram", "a dog", "a cat"]
tokenizer = CLIPTokenizer.from_pretrained(model_name_or_path)
input_ids = tokenizer(captions, return_tensors="pt", padding=True).input_ids.to('cuda')
input_pixels = processor(images=image, return_tensors="pt", padding=True).pixel_values.to('cuda')
with torch.no_grad(), torch.cuda.amp.autocast():
image_features = model.encode_image(input_pixels)
text_features = model.encode_text(input_ids)
image_features /= image_features.norm(dim=-1, keepdim=True)
text_features /= text_features.norm(dim=-1, keepdim=True)
label_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
print(f"Label probs: {label_probs}")
import torch
from eva_clip import create_model_and_transforms, get_tokenizer
from PIL import Image
model_name = "EVA-CLIP-18B"
pretrained = "eva_clip"# or "/path/to/EVA_CLIP_18B_psz14_s6B.fp16.pt"
image_path = "CLIP.png"
caption = ["a diagram", "a dog", "a cat"]
device = "cuda"if torch.cuda.is_available() else"cpu"
model, _, processor = create_model_and_transforms(model_name, pretrained, force_custom_clip=True)
tokenizer = get_tokenizer(model_name)
model = model.to(device)
image = processor(Image.open(image_path)).unsqueeze(0).to(device)
text = tokenizer(["a diagram", "a dog", "a cat"]).to(device)
with torch.no_grad(), torch.cuda.amp.autocast():
image_features = model.encode_image(image)
text_features = model.encode_text(text)
image_features /= image_features.norm(dim=-1, keepdim=True)
text_features /= text_features.norm(dim=-1, keepdim=True)
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
print("Label probs:", text_probs)
You can leverage
deepspeed.zero.Init()
with deepspeed zero stage 3 if you have limited CPU memory. For loading a pretrained checkpoint in the context of using deepspeed.zero.Init(), it's advised to use the
load_zero_partitions()
function in
eva_clip/factory.py
.
BibTeX & Citation
@article{EVA-CLIP-18B,
title={EVA-CLIP-18B: Scaling CLIP to 18 Billion Parameters},
author={Quan Sun and Jinsheng Wang and Qiying Yu and Yufeng Cui and Fan Zhang and Xiaosong Zhang and Xinlong Wang},
journal={arXiv preprint arXiv:2402.04252},
year={2023}
}
Runs of BAAI EVA-CLIP-18B on huggingface.co
708
Total runs
34
24-hour runs
-10
3-day runs
-38
7-day runs
-313
30-day runs
More Information About EVA-CLIP-18B huggingface.co Model
EVA-CLIP-18B huggingface.co is an AI model on huggingface.co that provides EVA-CLIP-18B's model effect (), which can be used instantly with this BAAI EVA-CLIP-18B model. huggingface.co supports a free trial of the EVA-CLIP-18B model, and also provides paid use of the EVA-CLIP-18B. Support call EVA-CLIP-18B model through api, including Node.js, Python, http.
EVA-CLIP-18B huggingface.co is an online trial and call api platform, which integrates EVA-CLIP-18B's modeling effects, including api services, and provides a free online trial of EVA-CLIP-18B, you can try EVA-CLIP-18B online for free by clicking the link below.
BAAI EVA-CLIP-18B online free url in huggingface.co:
EVA-CLIP-18B is an open source model from GitHub that offers a free installation service, and any user can find EVA-CLIP-18B on GitHub to install. At the same time, huggingface.co provides the effect of EVA-CLIP-18B install, users can directly use EVA-CLIP-18B installed effect in huggingface.co for debugging and trial. It also supports api for free installation.