Views
No views yet
.mlpackage files:| Model | Inputs | Output | Size |
|---|---|---|---|
MedSigLIP_VisionEncoder.mlpackage | pixel_values — (1, 3, 448, 448) float32, normalized to [-1, 1] | image_embeds — (1, 1152) float16, L2-normalized | ~815 MB |
MedSigLIP_TextEncoder.mlpackage | input_ids — (1, 64) int32, padded with token ID 1; attention_mask — (1, 64) int32 | text_embeds — (1, 1152) float16, L2-normalized | ~858 MB |
1import coremltools as ct
2import numpy as np
3
4vision_model = ct.models.MLModel("MedSigLIP_VisionEncoder.mlpackage")
5text_model = ct.models.MLModel("MedSigLIP_TextEncoder.mlpackage")
6
7# Vision encoder
8pixel_values = np.random.randn(1, 3, 448, 448).astype(np.float32)
9image_embeds = vision_model.predict({"pixel_values": pixel_values})["image_embeds"]
10
11# Text encoder — input_ids and attention_mask must be float32 for CoreML predict()
12input_ids = np.array([[523, 87, 1] + [1] * 61], dtype=np.float32)
13attention_mask = np.array([[1, 1, 1] + [0] * 61], dtype=np.float32)
14text_embeds = text_model.predict({
15 "input_ids": input_ids,
16 "attention_mask": attention_mask,
17})["text_embeds"]
18
19# Cosine similarity (embeddings are already L2-normalized)
20similarity = np.dot(image_embeds.flatten(), text_embeds.flatten())1import CoreML
2
3let config = MLModelConfiguration()
4config.computeUnits = .cpuAndNeuralEngine
5
6let visionModel = try await MedSigLIP_VisionEncoder.load(configuration: config)
7let textModel = try await MedSigLIP_TextEncoder.load(configuration: config)
8
9// Run predictions off the main thread
10let imageEmbeds = try await Task.detached {
11 try visionModel.prediction(pixel_values: pixelValuesArray)
12}.value
13
14let textEmbeds = try await Task.detached {
15 try textModel.prediction(input_ids: inputIdsArray, attention_mask: maskArray)
16}.value.mlpackage), requires iOS 17+ / macOS 14+torch.export.export(strict=False) + run_decompositions(), converted with coremltools.convert()eager (SDPA not supported by coremltools)torch.backends.mha.set_fastpath_enabled(False))tokenizer_class set to "T5Tokenizer" in tokenizer_config.json (functionally identical to SiglipTokenizer)</s>)pixel / 255 * 2 - 1score * 10.0 before softmax (learned logit_scale = exp(2.3))| Difference |
|---|
| Float16 vs float32 |
| Bilinear vs BICUBIC image resampling (iOS) |
| Tokenizer class name override |