com.sky.sentis.siglip2-base16
Google SigLIP 2 Base/16 (224 x 224) (google/siglip2-base-patch16-224) converted to Unity Inference Engine (Sentis) 2.6.1 with Float16 weights. Text and image crops become 768-d unit-length vectors; their dot product is the cosine similarity, for zero-shot search ("a person wearing a red jacket") over detector boxes.
Install as a UPM package (git URL, or copy the folder into Packages/); depends on com.unity.ai.inference 2.6.1.
Files
Models~/siglip2_b16_vision_fp16.sentis 185 MB pixels [1, 3, 224, 224] RGB 0-1 -> image_embeds [1, 768]
Models~/siglip2_b16_text_fp16.sentis 172 MB token_embeds [1, 64, 768] -> text_embeds [1, 768]
Models~/siglip2_b16_token_embed_fp16.bin 393 MB token-embedding table [256000, 768], raw little-endian float16
Models~/tokenizer.json 34 MB upstream Gemma tokenizer (unmodified)
Runtime/Siglip2Base16.cs self-contained inference wrapper (namespace SentisModels)
Usage
using SentisModels;
using Unity.InferenceEngine;
var siglip = new Siglip2Base16(BackendType.GPUCompute); // falls back to CPU without compute shaders
siglip.Load(Path.GetFullPath("Packages/com.sky.sentis.siglip2-base16/Models~"));
siglip.Warmup();
float[] query = siglip.EmbedText("a photo of a person wearing a red jacket"); // blocking, once per query
float[][] crops = await siglip.EmbedCropsAsync(frameTexture, personBoxes); // boxes in source pixels, top-left origin
float score = Siglip2Base16.Dot(query, crops[0]); // cosine similarity
float p = Siglip2Base16.Probability(query, crops[0]); // SigLIP's calibrated sigmoid
| Member | |
|---|---|
Dim = 768, InputSize = 224, ContextLength = 64 | |
EmbedText(string) | unit-length text embedding (blocking) |
EmbedCropsAsync(Texture, Rect[]) | unit-length embedding per box; one crop scheduled per frame, callback AsyncGPUReadback |
LastCropsMs | wall time of the last EmbedCropsAsync (first schedule to result) |
Tokenize(string) | the 64 token ids the text tower sees |
LogitScale = 112.6689, LogitBias = -16.7717 | the model's learned logit_scale.exp() / logit_bias |
Probability(text, image) | sigmoid(LogitScale * cos + LogitBias) |
Scores: cosine vs probability
SigLIP is trained with a sigmoid loss, not a softmax over a batch: each image-text pair gets an independent
logit logit_scale.exp() * cos + logit_bias = 112.67 * cos - 16.77, and sigmoid(logit) is the model's own
probability that the pair matches. Cosines are small in absolute terms (a good match is ~0.12-0.18 here) because of
that large scale; the ranking is identical whether you sort by cosine or by probability. Use Probability when you need
an absolute threshold (e.g. "is there anyone lying on the ground at all?"); it reaches 0.5 at cos ≈ 0.149. Unlike
CLIP, do not softmax the cosines across candidate labels.
Preprocessing (done by the wrapper)
Vision. Each box is widened by 15% of its width on each side and 5% of its height top and bottom, clamped to the
texture, then letterboxed (aspect kept, centred, mid-grey 0.5 padding) into the 224 x 224 input on the GPU
(sRGB render texture, TextureTransform().SetCoordOrigin(CoordOrigin.TopLeft)). The SigLIP normalisation
(x - 0.5) / 0.5 is baked into the graph, so the input is plain RGB in [0, 1]. (The upstream processor squashes the
whole image to 224 x 224; letterboxing keeps people's proportions in tall boxes.) The padding is cleared with
s_Pad.linear in a Linear colour-space project: GL.Clear takes its colour as linear and sRGB-encodes it into the
canvas, so a plain 0.5 would reach the model as 0.737. Measured pad value: 0.4980 (Linear), 0.5020 (Gamma).
Text. As the SigLIP 2 processor expects:
- lowercase the text (
tokenizer_config.jsonhasdo_lower_case: true; the model was trained on lowercased text, and the transformersGemmaTokenizerdoes not apply it by itself), - Gemma SentencePiece-BPE (256k vocab, byte fallback) via Unity's built-in
HuggingFaceParseron the upstreamtokenizer.json,<eos>(id 1) appended, no<bos>, - truncate to 64 tokens keeping
<eos>last, pad with<pad>(id 0) to exactly 64 (padding="max_length"). The text tower has no attention mask and pools the last position, so the padding is part of the input: always 64.
The token-embedding table (256000 x 768, 197M of the text tower's 282M parameters) is kept out of the graph: the
wrapper reads the 64 needed rows from siglip2_b16_token_embed_fp16.bin with a FileStream and feeds
[1, 64, 768] to the text graph, which adds the position embeddings and runs the encoder, final LayerNorm and head.
This keeps 0.8 GB of mostly unused weights off the GPU: Sentis Float16 weights are cast back to fp32 at run time, so an
in-graph table would also need a full fp32 copy on every query.
Measured (Unity 6000.3, Sentis 2.6.1, Apple M5 Max, editor)
Parity, cosine (min over 5 crops from the police demo recordings / 5 sentences, same input bytes on every path):
| Edge | Vision | Text |
|---|---|---|
| A: PyTorch (transformers) vs ONNX Runtime | 1.000000 (max abs 2.5e-5) | 1.000000 (max abs 1.5e-5) |
| fp16 token table vs fp32 table (PyTorch) | 1.000000 (max abs 1.0e-3) | |
| B: ORT vs Sentis fp32, CPU / GPUCompute | 1.000000 / 1.000000 | 1.000000 / 1.000000 |
| B: ORT vs Sentis fp16 (shipped), CPU / GPUCompute | 0.999996 / 0.999996 | 1.000000 / 1.000000 |
Tokenizer: 0 mismatching ids over 14 strings (punctuation, double / leading spaces, tabs and newlines, Korean,
accents, emoji, all caps, digits, a 100-word string that truncates) vs transformers GemmaTokenizer.
Zero-shot through the package API (EmbedText + EmbedCropsAsync on 1920 x 1080 recording frames, Linear
colour-space project like the police demo), cosine:
| red jacket | lying | white car | blue car | blonde walker | |
|---|---|---|---|---|---|
| a photo of a person wearing a red jacket | +0.120 | +0.044 | +0.032 | +0.029 | +0.079 |
| a photo of a person lying on the ground | +0.102 | +0.158 | +0.062 | +0.054 | +0.106 |
| a photo of a white car | +0.023 | +0.023 | +0.123 | +0.104 | +0.016 |
| a photo of a blue car | +0.028 | +0.029 | +0.093 | +0.126 | +0.034 |
| a photo of a person with blonde hair, walking | +0.134 | +0.134 | +0.061 | +0.054 | +0.179 |
Same ranking on CPU and GPUCompute, and in a Gamma project (all within ±0.006 of these). The GPU letterbox (bilinear, no mipmaps) differs slightly from a PIL resize of the same box (cosine 0.976-0.993 between the two image embeddings); rankings are unchanged.
Warm timings (average of 20 calls after Warmup, Linear project):
| GPUCompute | CPU | |
|---|---|---|
EmbedText per sentence (incl. tokenize 0.1 ms + table lookup) | 13.1 ms | 67.5 ms |
EmbedCropsAsync, 1 box (schedule to readback) | 17.8 ms | 166 ms |
EmbedCropsAsync, 4 boxes (one per frame) | 66 ms | 663 ms |
Load (two workers + 34 MB tokenizer.json parse) | 2.0 s | 1.6 s |
Warmup | 0.16 s (17 s on the first run after a colour-space switch: shader compilation) | 0.26 s |
Conversion notes
- Source:
google/siglip2-base-patch16-224(transformersSiglipModel,attn_implementation="eager"), safetensors sha256612923381c76…fadee6a0b. - Vision graph =
vision_model(pixel_values=(x - 0.5) / 0.5).pooler_output(MAP attention-pooling head). Text graph = position embeddings + encoder +final_layer_norm+headon the last position, taking token embeddings as input. Both exported withtorch.onnx.export(dynamo=False, opset_version=17), fixed shapes, weights inline; thegelu_pytorch_tanhactivations decompose into primitives at opset 17 (noGelu(approximate="tanh")node, which Sentis would run as exact-erf GELU). No graph surgery. - Imported into Sentis,
ModelQuantizer.QuantizeWeights(QuantizationType.Float16)and saved withModelWriter.Save. - The vision tower takes a single 224 x 224 image (the fixed-resolution SigLIP 2 checkpoint, not NaFlex).
License & attribution
Model weights: Apache-2.0, © Google LLC — google/siglip2-base-patch16-224,
paper SigLIP 2 (arXiv:2502.14786). The files under Models~ are converted
(not retrained) from those weights; see LICENSE.md for the modifications. The wrapper code is MIT, © 2026 Sky Kim.