Run this model with HF Jobs

Run ai-babai/sam3-text-onnx on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/ai-babai/sam3-text-onnx. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/ai-babai/sam3-text-onnx on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

SAM 3 text-prompted segmentation, Q4 ONNX

This package lets the Transformers.js SAM 3 text-prompt integration load three ONNX graphs and its tokenizer and processor from one model ID. Give SAM 3 an image and a concept such as cat. It returns masks, bounding boxes, and scores for instances of that concept. Use a Transformers.js build with Sam3Model and Sam3Processor support.

Graph Input Output
onnx/vision_encoder_q4.onnx pixel_values, float32, 1008 × 1008 Three float32 feature levels
onnx/text_encoder_q4.onnx input_ids and attention_mask, int64, 32 tokens Float32 text features
onnx/prompt_decoder_q4.onnx The three feature levels, text features, and attention mask Mask logits, normalized XYXY boxes, detection logits, presence logits, semantic mask logits

The three graphs total 772,777,814 bytes. Each contains its weights. The image processor stretches the image to 1008 × 1008, rescales to [0, 1], and normalizes with per-channel mean and standard deviation of 0.5. The token sequence is padded or truncated to 32. The instance score is the product of the sigmoid of the detection logit and the sigmoid of the presence logit.

Transformers.js

import { AutoProcessor, RawImage, Sam3Model } from '@huggingface/transformers';

const modelId = 'ai-babai/sam3-text-onnx';
const processor = await AutoProcessor.from_pretrained(modelId);
const model = await Sam3Model.from_pretrained(modelId, { device: 'webgpu', dtype: 'q4' });

const image = await RawImage.read(
  'https://huggingface.co/datasets/huggingface/documentation-images/resolve/fa1c0d01825a6ffb0b06fb82e06d4f733b152e67/coco_sample.png',
);
const inputs = await processor(image, 'cat');
const predictions = await model(inputs);
const [instances] = processor.post_process_instance_segmentation(predictions, {
  threshold: 0.5,
  mask_threshold: 0.5,
  target_sizes: [[image.height, image.width]],
});
// instances.masks, instances.boxes (XYXY in pixels), instances.scores

Export and validation

The three graphs were exported from Meta’s SAM 3 checkpoint. Two independent exports with the pinned tools produced the same SHA-256 for each graph. The recipe includes the export script, dependencies and a check against Python FP32 masks.

On two images, Chromium WebGPU and Python FP32 both returned two cats, zero airplanes and one truck at detection and mask thresholds of 0.5. Across the three detections, the lowest mask IoU was 0.99575 and the largest box coordinate difference was 1.65 pixels. Validation results

Credits and license

Meta and the SAM 3 authors developed the model. The ONNX export uses the Hugging Face implementation of SAM 3. The three-graph design draws on Card Anvil’s exporter and the interface and Q4 parameters documented by tepirale. The previous package preserves tepirale’s original graphs. See NOTICE for attribution and LICENSE for Meta’s SAM License terms.


ONNX export and Transformers.js packaging by Maksim Popkov.

Downloads last month
71
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for ai-babai/sam3-text-onnx

Base model

facebook/sam3
Quantized
(38)
this model