Ficha del modelo
Browse files
README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: google/siglip2-so400m-patch14-384
|
| 4 |
+
tags:
|
| 5 |
+
- coreml
|
| 6 |
+
- siglip2
|
| 7 |
+
- image-encoder
|
| 8 |
+
- apple-silicon
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# SigLIP2-so400m image encoder, Core ML
|
| 12 |
+
|
| 13 |
+
The image tower of SigLIP2-so400m converted to Core ML (fp16), so it can run
|
| 14 |
+
with hardware acceleration on Macs. The weights are Google's, untouched — only
|
| 15 |
+
the format changed.
|
| 16 |
+
|
| 17 |
+
Converted from [`open_clip`](https://github.com/mlfoundations/open_clip),
|
| 18 |
+
model `ViT-SO400M-14-SigLIP2-378`, pretrained tag `webli`.
|
| 19 |
+
|
| 20 |
+
This is the **image tower only**. For image↔text search you also need the
|
| 21 |
+
matching text tower, which is not in this repository.
|
| 22 |
+
|
| 23 |
+
## Interface
|
| 24 |
+
|
| 25 |
+
| | |
|
| 26 |
+
|---|---|
|
| 27 |
+
| Input | `image`, an image of **378 × 378** |
|
| 28 |
+
| Output | `embedding`, **1152** dimensions, **float16**, already L2-normalized |
|
| 29 |
+
| Size | 815 MB |
|
| 30 |
+
| Minimum target | macOS 14 |
|
| 31 |
+
|
| 32 |
+
Two things are easy to get wrong, and neither one fails loudly — you just get
|
| 33 |
+
worse search results:
|
| 34 |
+
|
| 35 |
+
**The input is 378, not 384.** The original model is named `patch14-384`, but
|
| 36 |
+
its patch embedding is a 14×14 convolution with stride 14: 27 patches fit, and
|
| 37 |
+
the last 6 pixels of each dimension are dropped. So the model effectively looks
|
| 38 |
+
at the top-left 378×378 region of a 384-resized image, which is also what it
|
| 39 |
+
saw during training. If you resize your image to 378 directly instead of
|
| 40 |
+
resizing to 384 and cropping to 378, cosine similarity against the original
|
| 41 |
+
model drops from 0.998 to 0.970.
|
| 42 |
+
|
| 43 |
+
**The output is float16.** Reading the `MLMultiArray` buffer as float32 gives
|
| 44 |
+
you a plausible-looking vector that has nothing to do with the real embedding —
|
| 45 |
+
we measured 0.02 cosine similarity against the reference. Check `dataType`
|
| 46 |
+
rather than assuming.
|
| 47 |
+
|
| 48 |
+
Normalization is baked into the model (scale 2/255, bias −1, i.e. SigLIP2's
|
| 49 |
+
mapping to [−1, 1]), so pass raw pixels; do not normalize them yourself.
|
| 50 |
+
|
| 51 |
+
## Fidelity, and which compute unit to use
|
| 52 |
+
|
| 53 |
+
Measured on an M2 Pro against the fp16 ONNX export of the same model
|
| 54 |
+
([onnx-community/siglip2-so400m-patch14-384-ONNX](https://huggingface.co/onnx-community/siglip2-so400m-patch14-384-ONNX)),
|
| 55 |
+
over 134 frames drawn from 30 different videos, with identical preprocessing on
|
| 56 |
+
both sides. "Top-10 overlap" is how much the ranking of those 134 frames agrees
|
| 57 |
+
with the ONNX ranking across 30 real search queries — which is what a user
|
| 58 |
+
actually notices.
|
| 59 |
+
|
| 60 |
+
| Compute units | ms/image | Mean cosine | Min | Below 0.99 | Top-10 overlap |
|
| 61 |
+
|---|---|---|---|---|---|
|
| 62 |
+
| **`.cpuAndGPU`** | **224** | **0.9999** | **0.9991** | 0/134 | **98 %** |
|
| 63 |
+
| `.cpuOnly` | 353 | 0.9990 | 0.9817 | 2/134 | 96 % |
|
| 64 |
+
| `.cpuAndNeuralEngine` | 184 | 0.9946 | 0.9442 | 14/134 | 82 % |
|
| 65 |
+
|
| 66 |
+
**Use `.cpuAndGPU`.** The Neural Engine is the fastest of the three, but at
|
| 67 |
+
400M parameters its fp16 arithmetic drifts far enough to reorder search
|
| 68 |
+
results, and `.all` will pick it. The GPU is 20 % slower and reproduces the
|
| 69 |
+
original almost exactly.
|
| 70 |
+
|
| 71 |
+
For reference, the same ONNX model on CPU runs at 1395 ms/image, so the GPU
|
| 72 |
+
path is about 6× faster.
|
| 73 |
+
|
| 74 |
+
If you are converting a *smaller* SigLIP2 (the 86M-parameter base model, for
|
| 75 |
+
instance), this does not apply: there the Neural Engine is both the fastest and
|
| 76 |
+
lossless, and `.all` is the right choice. The lesson is to measure the
|
| 77 |
+
distribution and the ranking, not the mean cosine — the mean hid this.
|
| 78 |
+
|
| 79 |
+
## How it was converted
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
uv run convert_to_coreml.py ViT-SO400M-14-SigLIP2-378
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
Using the script published in
|
| 86 |
+
[batmac/ViT-B-16-SigLIP2-Image-CoreML](https://huggingface.co/batmac/ViT-B-16-SigLIP2-Image-CoreML):
|
| 87 |
+
it loads the model through `open_clip`, wraps it so the output comes out
|
| 88 |
+
L2-normalized, traces it with `torch.jit.trace`, and converts with
|
| 89 |
+
`coremltools` (`minimum_deployment_target=macOS14`).
|
| 90 |
+
|
| 91 |
+
Note that the script's own `--verify` step fails on this model: it builds a
|
| 92 |
+
fixed 224×224 test image, and Core ML rejects any size other than 378. Verify
|
| 93 |
+
against a reference implementation instead.
|
| 94 |
+
|
| 95 |
+
## License
|
| 96 |
+
|
| 97 |
+
Apache 2.0, inherited from the original model. This is a derivative work; the
|
| 98 |
+
only modifications are the format (PyTorch → Core ML) and the precision (fp16).
|