SigLIP 2 base (patch16, 224) β€” ONNX, separate vision and text encoders

ONNX export of google/siglip2-base-patch16-224 (revision 75de2d55ec2d0b4efc50b3e9ad70dba96a7b2fa2), released under the same Apache 2.0 license (full text in LICENSE). Changes from the original: the PyTorch weights were converted into two ONNX graphs (vision, text); no retraining, no quantization. Original model by Google, SigLIP 2 (arXiv:2502.14786). Intended for CPU inference without torch (onnxruntime + tokenizers + Pillow/numpy).

Files

File Input Output Size
onnx/vision_model.onnx pixel_values (n, 3, 224, 224) float32 image_embeds (n, 768), not normalized 372 MB
onnx/text_model.onnx input_ids (n, 64) int64 text_embeds (n, 768), not normalized 1.13 GB

fp32, opset 17, dynamic batch size. L2-normalize the outputs before computing cosine similarity. The two encoders are independent: load only the one you need.

sha256 File
df44d95cbc8b9a1b1772a811c56da421b6b548a3e59f4d24f430592b575290a0 onnx/vision_model.onnx
8685bd8f3dc5e42e55712c3569cf02c7298eea5531cffb971cfb2965de838a19 onnx/text_model.onnx

Preprocessing (no torch, no torchvision)

  • Image: convert("RGB"), resize to 224Γ—224 (bilinear), Γ—1/255, then (x βˆ’ 0.5) / 0.5, CHW float32 (see preprocessor_config.json).
  • Text: tokenizer.json, truncation and padding to exactly 64 tokens with <pad>. Padding is required: the text head pools the last position. No attention_mask, no lowercasing.
  • Sigmoid similarity score (image-text): sigmoid(cos Γ— 112.6689 βˆ’ 16.7717), using the model's logit_scale and logit_bias. It is a squashed similarity, not a calibrated probability.

Usage

# pip install onnxruntime tokenizers pillow numpy huggingface_hub
import numpy as np
import onnxruntime as ort
from huggingface_hub import snapshot_download
from PIL import Image
from tokenizers import Tokenizer

path = snapshot_download("pompompom/siglip2-base-patch16-224-onnx")  # pin a revision= for reproducibility

def l2(x):
    return x / np.linalg.norm(x, axis=-1, keepdims=True)

# Image embeddings
vision = ort.InferenceSession(f"{path}/onnx/vision_model.onnx", providers=["CPUExecutionProvider"])
def embed_images(paths):
    batch = []
    for p in paths:
        im = Image.open(p).convert("RGB").resize((224, 224), Image.Resampling.BILINEAR)
        a = (np.asarray(im, np.float32) / 255.0 - 0.5) / 0.5
        batch.append(a.transpose(2, 0, 1))
    return l2(vision.run(["image_embeds"], {"pixel_values": np.stack(batch)})[0])

# Text embeddings (padding to exactly 64 tokens is required)
text = ort.InferenceSession(f"{path}/onnx/text_model.onnx", providers=["CPUExecutionProvider"])
tok = Tokenizer.from_file(f"{path}/tokenizer.json")
tok.enable_truncation(64)
tok.enable_padding(length=64, pad_id=tok.token_to_id("<pad>"), pad_token="<pad>")
def embed_texts(texts):
    ids = np.asarray([e.ids for e in tok.encode_batch(texts)], dtype=np.int64)
    return l2(text.run(["text_embeds"], {"input_ids": ids})[0])

cos = embed_images(["cat.jpg"]) @ embed_texts(["a photo of a cat", "a photo of a dog"]).T
score = 1 / (1 + np.exp(-(cos * 112.6689 - 16.7717)))  # sigmoid similarity score

Validation against PyTorch

20 synthetic images (various sizes and aspect ratios, RGBA, grayscale, noise) and 20 French and English texts (casing, accents, emojis, one text longer than 64 tokens). The full pipeline (Pillow + numpy preprocessing, tokenizers, onnxruntime) was compared with transformers:

Check Min cosine
Vision 0.9999998
Text 0.9999999

Preprocessing: max absolute difference 1.2e-7 vs SiglipImageProcessor; token IDs identical to the HF tokenizer on 20/20 texts. Details in report.json, provenance in export_info.json (torch 2.15.0, transformers 5.24.1).

Downloads last month
17
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for pompompom/siglip2-base-patch16-224-onnx

Quantized
(28)
this model

Paper for pompompom/siglip2-base-patch16-224-onnx