Model Card for SAM 3.1 image detector β€” Apple Core AI, 8-bit palettized (W8)

Conversion of the image + text detector of Meta's facebook/sam3.1 to Apple Core AI (.aimodel, portable) with 8-bit weight palettization of the encoders, at the original 1008Γ—1008 resolution. Given an image and a short noun phrase ("car", "person", "license plate"), it returns every matching instance (masks, boxes, scores). Tested on macOS 27 (Apple M5) in Python and Swift; not tested on iOS.

Model Details

Model Description

SAM 3 (Segment Anything with Concepts) detects, segments and tracks every instance of an open-vocabulary concept given as text or visual exemplars; SAM 3.1 adds Object Multiplex for faster multi-object video tracking. This repository contains only the image detector driven by text: image encoder, text encoder and detector/mask head, as three functions of one portable Core AI asset. The video tracker, geometric prompts (points, boxes) and visual exemplars are not included.

  • Original model developed by: Meta (Carion et al., 2025).
  • Conversion by: silv4souz4 (independent; not affiliated with or endorsed by Meta or Apple).
  • Model type: open-vocabulary, text-prompted instance segmentation (ViT image encoder, CLIP-style text encoder, DETR-style detector with presence token and mask head).
  • Base model: facebook/sam3.1, sam3.1_multiplex.pt (SHA-256 0567debeec80ba4ac6369540c6c248025283cb3ff2b92827509e57e2b3541cb6, revision daa6319); only the 1,166 detector.* tensors are used (the 457 tracker tensors are excluded).
  • Relation to base: quantized (8-bit k-means palettization of the encoder weights); outputs unchanged in kind.
  • License: SAM License (Meta), inherited β€” see License and Attribution.

Model Sources

Uses

Direct Use

On-device text-prompted segmentation of still images: find and mask every instance of a concept named by a short noun phrase, with per-instance scores and boxes.

Downstream Use

Selection and masking in photo-editing or annotation tools, dataset pre-labelling, automatic exclusion masks before further processing, quality gates that check whether a concept is present in an image.

Out-of-Scope Use

  • Video segmentation or tracking (the Object Multiplex tracker is not converted).
  • Point, box or exemplar prompts (only text is supported by this export).
  • Uses prohibited by the SAM License, including activities subject to ITAR or end uses prohibited by trade controls (military or warfare, nuclear, espionage, weapons), and any use that violates applicable law, such as surveillance or identification of individuals without consent.

Bias, Risks, and Limitations

  • Inherits the limitations of SAM 3 described by its authors (ambiguous or rare concepts, long phrases, small or occluded instances). See the SAM 3 paper for the authors' analyses.
  • Quantization changes some decisions near the 0.5 threshold. On the benchmark below the mean IoU is 0.19 points lower than the uncompressed model; in the worst query (one image, "car") the top score falls just below 0.5 and nothing is selected, while the uncompressed model selects the car.
  • fp16 numerics in the encoders vary across compute units and OS releases; validate on the device and OS you ship. iOS untested.
  • Debug information embedded in the asset contains build-time file paths of the converting machine; it has no effect on inference.

Recommendations

Treat scores near 0.5 as uncertain; check masks visually; validate on your own data; keep a human in the loop for consequential decisions.

How to Get Started with the Model

Download the whole repository (asset, tokenizer, config.json and checksums):

hf download silv4souz4/sam3.1-coreai-w8 --local-dir sam3.1-coreai-w8

config.json is a machine-readable summary of the functions, tensor shapes, tokenizer and selection rule below (it is also the file the Hub uses to count downloads of this repository).

File Size Notes
sam3.1_w8.aimodel 1.07 GB portable Core AI asset, 3 functions
tokenizer.json 3.6 MB SAM 3.1 tokenizer from facebook/sam3.1 (CLIP BPE), unchanged
Function Inputs Outputs
sam31_image_encode_w8_v2_98e1240e4a6e pixel_values float16 [1,3,1008,1008] backbone_features float16 [1,1024,1,5184]
sam31_text_encode_w8_v2_98e1240e4a6e input_ids int32 [1,32] text_features float16 [1,256,1,32]
sam31_detect_w8_v2_98e1240e4a6e backbone_features float32, text_features float32, text_mask int32 [1,32] pred_masks [1,200,288,288], pred_boxes [1,200,4] (xyxy, normalized), pred_logits [1,200], presence_logits [1,1], semantic_seg [1,1,288,288]
  • Image (as Meta's Sam3Processor): RGB uint8, resize (stretch) to 1008Γ—1008 bilinear with antialias, then (v/255 βˆ’ 0.5)/0.5, NCHW. Cast the encoder outputs to float32 for detect.
  • Text: tokenize with tokenizer.json, pad or truncate to 32 with the end token (id 49407). text_mask is 1 from the start token up to and including the first end token and 0 on padding β€” it cannot be derived from the ids, because padding uses the same id.
  • Selection: score = sigmoid(pred_logits) Β· sigmoid(presence_logits); keep queries with score β‰₯ 0.5; upsample their 288Γ—288 mask logits bilinearly (align_corners=False) to the image size and threshold at 0.
  • The image embedding can be reused for several phrases (only text_encode + detect run per phrase).
from coreai.runtime import AIModel, NDArray, SpecializationOptions
m = await AIModel.load("sam3.1_w8.aimodel", SpecializationOptions.default())
image_encode = m.load_function("sam31_image_encode_w8_v2_98e1240e4a6e")
text_encode = m.load_function("sam31_text_encode_w8_v2_98e1240e4a6e")
detect = m.load_function("sam31_detect_w8_v2_98e1240e4a6e")
b = (await image_encode({"pixel_values": NDArray(px)}))["backbone_features"].numpy()   # px: float16 [1,3,1008,1008]
t = (await text_encode({"input_ids": NDArray(ids)}))["text_features"].numpy()          # ids: int32 [1,32]
out = await detect({"backbone_features": NDArray(b.astype("float32")),
                     "text_features": NDArray(t.astype("float32")), "text_mask": NDArray(mask)})

Ahead-of-time compilation (.aimodelc) β€” tutorial

The asset here is a portable .aimodel. Apple's documentation, Compiling Core AI models ahead of time, explains that every Core AI model must be specialized to the device before inference; the coreai-build tool moves the most expensive part of that specialization, model compilation, to your build machine, so the model loads faster in your app. It produces one .aimodelc per device architecture; you ship (or download) only the one that matches the device. According to Apple, AOT compilation targets devices that support Apple Intelligence (iPhone/iPad with A17 Pro or later, Mac with M1 or later, Apple Vision Pro); it is not supported on tvOS and watchOS.

1. Install the Metal Toolchain (Xcode > Settings > Components > Metal Toolchain, or):

xcodebuild -downloadComponent MetalToolchain

2. Compile (all architectures of a platform, or one with --architecture):

xcrun coreai-build compile sam3.1_w8.aimodel --platform macOS --min-deployment-version 27.0 --output compiled/
xcrun coreai-build compile sam3.1_w8.aimodel --platform iOS --min-deployment-version 27.0 --output compiled/

Output files are named <asset>.<arch>.aimodelc (for example .h17g for the Apple M5 used here); each works on any OS at or above --min-deployment-version. Run coreai-build compile --help for --preferred-compute and the other options.

3. Load the matching bundle β€” the same API as for .aimodel:

let arch = AIModel.deviceArchitectureName
let url = compiledDir.appending(path: "sam3.1_w8.\(arch).aimodelc")
let model = try await AIModel(contentsOf: url, options: .default)

Apple recommends hosting the per-architecture bundles and downloading only the matching one (for example with the BackgroundAssets framework). Some on-device specialization still remains after AOT, depending on the model and compute units.

What we measured (Apple M5, macOS 27.2, Swift runtime, first load of one function with an empty specialization cache, two rounds):

Step Portable .aimodel AOT .aimodelc
Compile on the Mac (coreai-build, h17g, whole asset) β€” 7.0 s
First load, image_encode, cold cache 7.7–9.4 s 3.8–4.3 s
First load, detect, cold cache 11.9–18.4 s 2.6–3.1 s
Later loads (cache warm) 0.5–1.3 s 1.6–1.8 s

AOT changes load time, not the math: on a real image the M5 build gave all six outputs we compared byte-identical to the portable asset. It is not an inference speed-up. For this model the cold load of the portable asset is long, so shipping the .aimodelc is worth it; the cache is also rebuilt after every OS update.

Training Details

Training Data

No training or fine-tuning. Weights come from the official SAM 3.1 checkpoint (as described by Meta in the SAM 3 paper).

Training Procedure (conversion)

  1. detector.* tensors of sam3.1_multiplex.pt mapped to transformers Sam3Model with the official converter (convert_sam3_to_hf.py); 840,376,374 parameters; the 4th FPN stage (unused by the detector path), the tracker convolutions, the precomputed RoPE caches and 6 unused geometry projections are the only unmapped keys.
  2. Re-authored with Apple's SAM 3 Core AI example and corrected to match the original: exact (erf) GELU instead of the sigmoid approximation, fp32 constants (RoPE tables, FPN position encodings, attention scales, DETR constants β€” Apple's code rounds them to fp16 at build time), the text padding mask restored in the DETR encoder/decoder cross-attention, the mask decoder's attention over the text and the scoring's text pooling (Apple's detector wrapper omits it), and the native 1008Γ—1008 resolution. Before compression the corrected re-authoring matched Sam3Model on two real COCO images at 98–100 dB PSNR on the masks, with the same selected instances.
  3. Compression (coreai-opt 0.2.1 k-means palettization): image encoder 8 bits in groups of 32, text encoder 8 bits in groups of 8, both computed in fp16; the detector head is not compressed and runs in fp32.
  4. Converted with coreai-torch 0.4.2 (TorchConverter β†’ optimize()), one portable .aimodel with three uniquely named functions.

Evaluation

Testing Data, Factors & Metrics

COCO Panoptic val2017: 200 images (seed 42), 400 queries using COCO category names as text (394 with ground truth, 6 with none); ground truth = union of all non-crowd segments of the category, void/crowd pixels excluded. Metrics: IoU and Dice of the union of selected masks, mean per query. Reference = the same corrected re-authoring with the original, uncompressed weights in fp32. Apple M5, macOS 27.2, Core AI Python runtime, default compute.

Results

Uncompressed reference W8 (this)
IoU 0.774 0.772
Dice 0.838 0.836

Paired bootstrap over images (5,000 replicates): 95 % interval of the IoU change -0.67 to +0.09 points. The Swift runtime reproduced the Python runtime byte for byte on all seven tensors (three functions) of a real query. Descriptive timings (Swift, M5, one call each): image encoder ~1.2 s, text encoder ~0.09 s, detector ~0.7–1.1 s per phrase.

Summary

Within ~0.2 IoU points of the uncompressed model on 400 queries, at 1.1 GB, with occasional decisions flipping near the 0.5 threshold.

Environmental Impact

No training. Conversion and evaluation ran locally on one Apple M5 laptop for a few hours; negligible compared with the original training.

Technical Specifications

Compute Infrastructure

  • Hardware: Apple M5 (Mac17,3), 24 GB unified memory.
  • Software: Python 3.11, PyTorch 2.9.0, transformers 5.9.0, coreai-torch 0.4.2, coreai-opt 0.2.1, coreai-core 1.0.0b2 (the versions pinned by Apple's example), macOS 27.2, coreai-build 3605.5.4.

Citation

If you use these assets, please cite SAM 3 (the SAM License asks that research publications acknowledge the use of SAM Materials):

@misc{carion2025sam3segmentconcepts,
  title={SAM 3: Segment Anything with Concepts},
  author={Nicolas Carion and Laura Gustafson and Yuan-Ting Hu and Shoubhik Debnath and Ronghang Hu and Didac Suris and Chaitanya Ryali and Kalyan Vasudev Alwala and Haitham Khedr and Andrew Huang and Jie Lei and Tengyu Ma and Baishan Guo and Arpit Kalla and Markus Marks and Joseph Greer and Meng Wang and Peize Sun and Roman R{\"a}dle and Triantafyllos Afouras and Effrosyni Mavroudi and Katherine Xu and Tsung-Han Wu and Yu Zhou and Liliane Momeni and Rishi Hazra and Shuangrui Ding and Sagar Vaze and Francois Porcher and Feng Li and Siyuan Li and Aishwarya Kamath and Ho Kei Cheng and Piotr Doll{\'a}r and Nikhila Ravi and Kate Saenko and Pengchuan Zhang and Christoph Feichtenhofer},
  year={2025},
  eprint={2511.16719},
  archivePrefix={arXiv},
  primaryClass={cs.CV},
  url={https://arxiv.org/abs/2511.16719}
}

The evaluation used COCO val2017 images with panoptic annotations (annotations CC BY 4.0; images subject to the Flickr Terms of Use):

@inproceedings{lin2014coco,
  title={Microsoft COCO: Common Objects in Context},
  author={Lin, Tsung-Yi and Maire, Michael and Belongie, Serge and Hays, James and Perona, Pietro and Ramanan, Deva and Doll{\'a}r, Piotr and Zitnick, C. Lawrence},
  booktitle={European Conference on Computer Vision (ECCV)},
  year={2014}
}
@inproceedings{kirillov2019panoptic,
  title={Panoptic Segmentation},
  author={Kirillov, Alexander and He, Kaiming and Girshick, Ross and Rother, Carsten and Doll{\'a}r, Piotr},
  booktitle={IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2019}
}

License and Attribution

  • License: these files are a derivative work of the SAM Materials and are distributed under the SAM License (full text in LICENSE, version of November 19, 2025). By using or distributing them you agree to its terms, including the trade-control and prohibited-use clauses.
  • Original model: Β© Meta Platforms, Inc. and affiliates.
  • Modifications: re-authoring for Core AI with the corrections above, 8-bit palettization of the encoders, conversion to the portable Core AI format; no retraining. See NOTICE.
  • The re-authoring is based on Apple's coreai-models sample code, BSD 3-Clause; its notice is reproduced in NOTICE.
  • "Apple", "Core AI" and "Meta" are trademarks of their respective owners; their use here is descriptive only.

Model Card Authors

silv4souz4

Model Card Contact

Please open a discussion in the Community tab of this repository.

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

Model tree for silv4souz4/sam3.1-coreai-w8

Base model

facebook/sam3.1
Quantized
(10)
this model

Paper for silv4souz4/sam3.1-coreai-w8

Evaluation results

  • Mask IoU (mean per query, union of selected instances) on COCO Panoptic val2017 (200 images, seed 42, 400 category queries)
    validation set self-reported
    0.772
  • Dice (mean per query) on COCO Panoptic val2017 (200 images, seed 42, 400 category queries)
    validation set self-reported
    0.836