Skip to content
imaged

Image and text embeddings

CLIP ViT-B/32

Puts photos and text in one space of vectors: search photos by describing them, or label them with any words you choose. OpenAI's original CLIP.

MITclipimage embeddingstext embeddingszero-shot classificationimage searchopenaimit
Choose a variant

About this model

CLIP turns a photo and a piece of text into vectors of 512 numbers that are close when they match. Compare a photo with a few descriptions to label it with words chosen at run time (zero-shot classification), or compare one description with many photos to search them.

This is OpenAI's ViT-B/32 model: an image encoder (88 million parameters) and a text encoder (63 million), trained on 400 million image and text pairs from the internet. It comes as two packs. The text pack carries CLIP's tokenizer, so the app passes plain text.

Slab prepares the photo as OpenAI's CLIP does (short side to 224 pixels, bicubic, center crop, CLIP's mean and standard deviation) and tokenizes the text as CLIP's tokenizer does (lowercase, byte-level BPE, 77 tokens with the start and end tokens).

What you can build

  • Search a photo library with words
  • Label photos with categories chosen at run time, without training
  • Find similar or duplicate photos (compare image embeddings)
  • Sort or filter photos by what they show

Zero-shot labels: golden retriever dog

f16
Input
Golden-retriever-dog-1362597631o6g

Karen Arnold, CC0, https://commons.wikimedia.org/wiki/File:Golden-retriever-dog-1362597631o6g.jpg

Output
The photo against ten labels ("a photo of a dog", "a photo of a cat", ... "a photo of a flower"), scored as softmax over 100 × cosine similarity, on Metal. Top three: a dog 1.00, a cat 0.00, a musical instrument 0.00.

Zero-shot labels: sailboat

f16
Input
Kite sailboat dinghy

Kbuihner, Public domain, https://commons.wikimedia.org/wiki/File:Kite_sailboat_dinghy.jpg

Output
The photo against ten labels ("a photo of a dog", "a photo of a cat", ... "a photo of a flower"), scored as softmax over 100 × cosine similarity, on Metal. Top three: a boat 1.00, a musical instrument 0.00, a bird 0.00.

Zero-shot labels: acoustic guitar

f16
Input
Man playing an acoustic brazilian guitar (Violão) on Marco Zero Square, Refice, Pernambuco, Brazil

Wilfredor, CC0, https://commons.wikimedia.org/wiki/File:Man_playing_an_acoustic_brazilian_guitar_(Viol%C3%A3o)_on_Marco_Zero_Square,_Refice,_Pernambuco,_Brazil.jpg

Output
The photo against ten labels ("a photo of a dog", "a photo of a cat", ... "a photo of a flower"), scored as softmax over 100 × cosine similarity, on Metal. Top three: a musical instrument 0.99, a bicycle 0.00, a boat 0.00.

Photo search: "something to drink coffee from"

f16
Input
something to drink coffee from
Output
The query against the 53 gallery photos (public-domain and CC0, Wikimedia Commons), by cosine similarity, on Metal. Best three: coffee mug (b19-coffee-mug.jpg, 0.280); espresso cup (a02-espresso-cup.jpg, 0.270); teapot (b20-teapot.jpg, 0.257).

Photo search: "a vehicle for fighting fires"

f16
Input
a vehicle for fighting fires
Output
The query against the 53 gallery photos (public-domain and CC0, Wikimedia Commons), by cosine similarity, on Metal. Best three: pickup truck (b49-pickup-truck.jpg, 0.286); fire truck (b31-fire-truck.jpg, 0.250); horse (b04-horse.jpg, 0.240).

Photo search: "an animal that lives in the sea"

f16
Input
an animal that lives in the sea
Output
The query against the 53 gallery photos (public-domain and CC0, Wikimedia Commons), by cosine similarity, on Metal. Best three: jellyfish (b11-jellyfish.jpg, 0.267); goldfish (b00-goldfish.jpg, 0.263); drum kit (b29-drum-kit.jpg, 0.235).

Variants & downloads

Choose the build for your app

Model files are hosted on Google Drive. Large files may open a confirmation page before downloading.

Small

Slab

Weights stored as int8 in blocks of 64, decoded to float when loading, so it runs at the same speed. About 45% smaller; embeddings move slightly more (see Accuracy).

Platforms: macos · android

clip-vit-b-32-image-int8.slab

92.4 MB · Hosted download

Download
SHA-256 checksum
d980004f57cced0fd3d117210d4ec1fdb1bab57ebe8ed5c898e4fbe6bbe78dcd

clip-vit-b-32-text-int8.slab

68.4 MB · Hosted download

Download
SHA-256 checksum
29082d70d267dace0cf242a464dc5e18efd4db1fbdc23920ea5920723e910ab6

LICENSE-CLIP.txt

1 KB

Download
SHA-256 checksum
987e63b32f6c89ff5160e429458a872ff048e6860b590a3912e938f9da8f14db
Conversion details
command
hf download openai/clip-vit-base-patch32 --revision 3d74acf9a28c67741b2f4f2ea7635f0aaf6f0268 --local-dir clip-vit-base-patch32 --include "*.json" --include pytorch_model.bin python -c "import torch; from transformers import AutoModel; torch.set_grad_enabled(False); m = AutoModel.from_pretrained('clip-vit-base-patch32').eval(); I = type('I', (torch.nn.Module,), {'forward': lambda s, pixel_values: s.m.get_image_features(pixel_values=pixel_values).pooler_output}); T = type('T', (torch.nn.Module,), {'forward': lambda s, input_ids: s.m.get_text_features(input_ids=input_ids).pooler_output}); i = I(); i.m = m; t = T(); t.m = m; torch.onnx.export(i, (torch.zeros(1, 3, 224, 224),), 'clip-vit-b-32-image.onnx', input_names=['pixel_values'], output_names=['image_embeds'], opset_version=17, dynamo=False); torch.onnx.export(t, (torch.zeros(1, 77, dtype=torch.long),), 'clip-vit-b-32-text.onnx', input_names=['input_ids'], output_names=['text_embeds'], opset_version=17, dynamo=False)" slab-load convert clip-vit-b-32-image.onnx clip-vit-b-32-image.slab --input pixel_values=1x3x224x224 --meta task=embed --meta resize=center_crop --meta resize_size:i64=224 --meta interpolation=bicubic --meta antialias:bool=true --meta normalize=clip --meta color=rgb slab-load convert clip-vit-b-32-text.onnx clip-vit-b-32-text.slab --input input_ids=1x77 --meta task=embed slab-load quantize clip-vit-b-32-image.slab clip-vit-b-32-image-int8.slab slab-load quantize clip-vit-b-32-text.slab clip-vit-b-32-text-int8.slab slab-load tokenizer clip-vit-b-32-text-int8.slab clip-vit-base-patch32/tokenizer.json --pad "<|endoftext|>" slab-load meta set clip-vit-b-32-image-int8.slab default_backend.macos=gpu slab-load meta set clip-vit-b-32-text-int8.slab default_backend.macos=gpu

Integration examples

Python

python

import numpy as np, slab

cfg = slab.Config(cache_dir="/tmp/slab_cache", license=open("license.slablic.txt").read())
images = slab.Session(cfg, "clip-vit-b-32-image-f16.slab")
texts = slab.Session(cfg, "clip-vit-b-32-text-f16.slab")   # carries the tokenizer

def embed(session, inp):
    out = session.run(inp)
    out.normalize_l2()
    return out.numpy(0).reshape(-1)

photo = embed(images, slab.Input(frame=slab.Frame.open("photo.jpg")))
labels = ["a photo of a dog", "a photo of a cat", "a photo of a car"]
sims = np.array([photo @ embed(texts, slab.Input(text=t)) for t in labels])   # cosine similarities
logits = 100 * sims
probs = np.exp(logits - logits.max()); probs /= probs.sum()   # softmax, as CLIP
print({l: round(float(p), 3) for l, p in zip(labels, probs)})

Device & backend compatibility

Pack default: macos / GPU. The fastest backend on the Mac that prepares quickly: an image in 7.3 ms and a short text in 6.5 ms. The Neural Engine runs only the image pack and takes about 7 s to prepare it.

Available execution backends for CLIP ViT-B/32
PlatformEngineStatusPrecision
apple

CPU

CPU

Supported

Measured on macOS: both packs.

f32
apple

Metal

GPU

Supported

Measured on macOS: both packs. The default.

f32
apple

Apple Neural Engine

NPU

Supported

Measured on macOS: the image pack only (it computes in FP16 and takes about 7 s to prepare). The text pack takes token ids, which the Neural Engine path does not accept.

f16
android

CPU

CPU

Supported

Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17.

f32
android

Vulkan

GPU

Supported

Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17.

f32
android

Qualcomm Hexagon NPU (QNN)

NPU

Not supported

Tried on a Samsung Galaxy S23 Ultra (Hexagon v73): QNN rejects one of the image encoder's StridedSlice nodes (validateOpConfig error 3110).

—

Performance

Results depend on the device, runtime, and test conditions. Each measurement keeps its own context.

Mac with Apple M1 Max

Slab · CPU

macOS 26.6.2

25.3 ms

Measured time · scope below

int8Session open (ms): 68 Platform: macos Runs: 100 Input: 1, 3, 224, 224 (image encoder) Measured: 2026-10-30

Image encoder: median of 100 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 26.5 ms median of 20. Peak memory after opening and one run: 416 MB.

Mac with Apple M1 Max

Slab · GPU

macOS 26.6.2

7.0 ms

Measured time · scope below

int8Session open (ms): 164 Platform: macos Runs: 100 Input: 1, 3, 224, 224 (image encoder) Measured: 2026-10-30

Image encoder: median of 100 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 11.2 ms median of 20. Peak memory after opening and one run: 1137 MB.

Mac with Apple M1 Max

Slab · NPU

macOS 26.6.2

3.7 ms

Measured time · scope below

int8Session open (ms): 6686 Platform: macos Runs: 100 Input: 1, 3, 224, 224 (image encoder) Measured: 2026-10-30

Image encoder: median of 100 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 5.9 ms median of 20. Peak memory after opening and one run: 1137 MB.

Mac with Apple M1 Max

Slab · CPU

macOS 26.6.2

20.9 ms

Measured time · scope below

int8Session open (ms): 90 Platform: macos Runs: 100 Input: 1, 77 (text encoder) Measured: 2026-10-30

Text encoder: Input(text="a photo of a dog"), tokenizing included, median of 100. Peak memory after opening and one run: 339 MB.

Mac with Apple M1 Max

Slab · GPU

macOS 26.6.2

6.2 ms

Measured time · scope below

int8Session open (ms): 176 Platform: macos Runs: 100 Input: 1, 77 (text encoder) Measured: 2026-10-30

Text encoder: Input(text="a photo of a dog"), tokenizing included, median of 100. Peak memory after opening and one run: 969 MB.

Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)

Slab · CPU

Android 17

162.0 ms

Measured time · scope below

int8Session open (ms): 146 Platform: android Runs: 79 Input: 1, 3, 224, 224 (image encoder) Measured: 2026-11-06

Image encoder: median of 79 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, preprocessing included: 159 ms median. open_ms: opening the session. Peak memory (resident) after the runs: 388 MB. Text encoder, Input(text="a photo of a dog"): 106 ms median of 100.

Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)

Slab · GPU

Android 17

75.4 ms

Measured time · scope below

int8Session open (ms): 166 Platform: android Runs: 100 Input: 1, 3, 224, 224 (image encoder) Measured: 2026-11-06

Image encoder: median of 100 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, preprocessing included: 67.7 ms median. open_ms: opening the session with the GPU programs already in the cache folder (the first open on a device compiles them, about 0.3 s more). Peak memory (resident) after the runs: 406 MB. Text encoder, Input(text="a photo of a dog"): 41.7 ms median of 100.

Accuracy checks

macos · CPU · int8

The upstream PyTorch model against Hugging Face's CLIPProcessor, which rounds the center crop down where OpenAI's pipeline rounds it to nearest (a pixel's shift on some photos), on 53 public-domain and CC0 photos (Wikimedia Commons) and the same texts; Slab's image path starts from the photo file (Frame)

Image embeddings: cosine similarity 0.999099 on average, 0.990607 on the worst of 53 photos. Text embeddings: 0.9994906 on average, 0.9988761 at worst (58 prompts and sentences in several languages). Zero-shot: the same label as upstream for 52 of 53 photos (each photo against all 53 labels as "a photo of a ..."); right for 45 (upstream 45).

macos · GPU · int8

The upstream PyTorch model against Hugging Face's CLIPProcessor, which rounds the center crop down where OpenAI's pipeline rounds it to nearest (a pixel's shift on some photos), on 53 public-domain and CC0 photos (Wikimedia Commons) and the same texts; Slab's image path starts from the photo file (Frame)

Image embeddings: cosine similarity 0.999099 on average, 0.990607 on the worst of 53 photos. Text embeddings: 0.9994906 on average, 0.9988761 at worst (58 prompts and sentences in several languages). Zero-shot: the same label as upstream for 52 of 53 photos (each photo against all 53 labels as "a photo of a ..."); right for 45 (upstream 45).

macos · NPU · int8

The upstream PyTorch model against Hugging Face's CLIPProcessor, which rounds the center crop down where OpenAI's pipeline rounds it to nearest (a pixel's shift on some photos), on 53 public-domain and CC0 photos (Wikimedia Commons) and the same texts; Slab's image path starts from the photo file (Frame)

Image embeddings: cosine similarity 0.999070 on average, 0.990275 on the worst of 53 photos. The text pack does not run on the Neural Engine.

Before you choose this model

  • English only.
  • OpenAI's model card puts any deployed use, commercial or not, out of scope unless the model is tested thoroughly for that use, and surveillance and face recognition always out of scope. The code and weights are MIT-licensed; weigh the model card before shipping.
  • Weak at fine detail: counting, small text, fine-grained species or car models.
  • Text beyond 77 tokens (about 55 words) is cut.
  • Learned from internet data, with its biases (see OpenAI's model card).
  • The text pack takes token ids, which Slab's Neural Engine path does not accept: it runs on the GPU or CPU. The image pack runs on all three.