siglip2-base-patch16-224-onnx
This is an ONNX conversion of google/siglip2-base-patch16-224 at revision 75de2d55ec2d0b4efc50b3e9ad70dba96a7b2fa2, made with api/tools/export_onnx.py from VBLIS for use in the VBLIS app. It is not an official release of Google. The weights are unchanged (fp32 values of the source model).
What was changed
- The vision tower and the text tower are two separate graphs (
vision.onnx,text.onnx), converted with the PyTorch dynamo exporter (torch.onnx.export(..., dynamo=True)), ONNX opset 18, fp32, dynamic batch size. The weights are stored invision.onnx.dataandtext.onnx.data. - Every
Reshapenode hasallowzero=0instead of the exporter'sallowzero=1. The result is the same, because no reshape shape contains a literal 0. The export fails if one does. - The graphs return the un-normalised features (
image_features,text_features). L2-normalise them before comparing.
No other change was made to the model. config.json, preprocessor_config.json and the tokenizer files are copied unchanged from the source.
Inputs and outputs
vision.onnx
| name | dtype | shape | note | |
|---|---|---|---|---|
| input | pixel_values |
float32 | (batch, 3, 224, 224) | from the processor |
| output | image_features |
float32 | (batch, 768) | un-normalised, 768 values per item |
text.onnx
| name | dtype | shape | note | |
|---|---|---|---|---|
| input | input_ids |
int64 | (batch, 64) | from the processor |
| output | text_features |
float32 | (batch, 768) | un-normalised, 768 values per item |
Text is lower-cased, tokenised with padding="max_length" and truncated to 64 tokens. logit_scale and logit_bias of the source model are stored in vblis_onnx.json; the SigLIP score is sigmoid(exp(logit_scale) * cosine + logit_bias).
Usage
import numpy as np
import onnxruntime as ort
from huggingface_hub import snapshot_download
from PIL import Image
from transformers import AutoProcessor
path = snapshot_download("opoeci6/siglip2-base-patch16-224-onnx")
processor = AutoProcessor.from_pretrained(path, use_fast=False)
providers = ["CPUExecutionProvider"]
vision = ort.InferenceSession(f"{path}/vision.onnx", providers=providers)
text = ort.InferenceSession(f"{path}/text.onnx", providers=providers)
def normalize(x):
return x / np.linalg.norm(x, axis=-1, keepdims=True)
image = Image.open("photo.jpg").convert("RGB")
inputs = processor(images=[image], return_tensors="np")
image_features = normalize(vision.run(None, {i.name: inputs[i.name] for i in vision.get_inputs()})[0])
tokens = processor(text="a photo of a cat".lower(), return_tensors="np", padding="max_length", truncation=True, max_length=64)
text_features = normalize(text.run(None, {i.name: tokens[i.name] for i in text.get_inputs()})[0])
print(image_features @ text_features.T) # cosine similarity
Files
| File | Size (bytes) | SHA-256 |
|---|---|---|
config.json |
253 | fe8b5fe6d5734360678fd71c11c21e1ea3364bd8598d34295d9206335973ffd7 |
LICENSE |
11357 | c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4 |
preprocessor_config.json |
394 | 9b36b57ebaf20f09bf4c22100ccc21877ea6bfe5aead0c00c59f8af8ccefacfc |
special_tokens_map.json |
636 | baec30ea10906f16adb8c18af7a34023002c1746542612b8b41c9f09e1351351 |
text.onnx |
1609868 | 0e3bb05031216abe4763344d7e3b458b93d42c5bdc930abc2f02747e3178cdad |
text.onnx.data |
1129215488 | c96b29c9df939786d13c418ce2269fd1342eb292337b32f1a0b3ffa8b9108f3a |
tokenizer.json |
34363039 | cb9140fae3ac5122c972d37adf83e1248471a38147ad76f8215c8872c6fd8322 |
tokenizer.model |
4241003 | 61a7b147390c64585d6c3543dd6fc636906c9af3865a5548f27f31aee1d4c8e2 |
tokenizer_config.json |
47164 | 14afe629fe4959b9e0d51e1852b8d9f7ad074f90a1a7125a4fcdd17f06e78fc8 |
vision.onnx |
1627271 | b8dc75efb1da1f4122e8083c8c1aa630f47f7e6336082cfdbd8682d4b3f852c3 |
vision.onnx.data |
371538464 | 1e919a7ee4d28f41272e6b610bcf724b4fa69ecfa8faf75ddfc29598f9ed68bc |
vblis_onnx.json (the manifest, schema 1) lists the same files and the export settings; it also holds the SHA-256 of this README.
Parity check
ONNX Runtime 1.24.3 (CPU) against the PyTorch model on 12 generated pictures and 8 texts: minimum cosine similarity 1.00000000 (pictures) and 1.00000000 (texts).
License
The original model is released by Google under the Apache License 2.0; this conversion is distributed under the same licence (see LICENSE). The original model card and licence apply: https://huggingface.co/google/siglip2-base-patch16-224
- Downloads last month
- 25
Model tree for opoeci6/siglip2-base-patch16-224-onnx
Base model
google/siglip2-base-patch16-224