/ Модель

Характеристики

Лицензия
Apache 2.0
Библиотека
onnxruntime
Опубликована
9 ноя 2026

SAM2.1-Tiny-ONNX-for-Oku3D

Генерация масокИзображение → mask3 профессии
0скачиваний за 30 дней0лайковвеса обновлены9 ноя 2026

Описание модели

Составлено на русском по карточке модели и метаданным Hugging Face

Экспорт SAM 2.1 Hiera Tiny в ONNX для интерактивной сегментации объектов на изображениях по точкам и рамкам.

Это экспорт модели сегментации изображений Meta SAM 2.1 Hiera Tiny в формат ONNX, подготовленный Jens-Duttke для выделения объектов в фоторедакторе Oku3D. Модель принимает изображение и интерактивные подсказки — точки или ограничивающую рамку — и выдаёт маски объекта. Энкодер изображения запускается один раз для фотографии, а декодер пересчитывает маску при каждом новом запросе; поддерживается уточнение результата по предыдущим логитам маски.

Экспорт разделён на энкодер FP16 размером около 70 МБ и декодер FP32 размером около 18 МБ. Модель запускается через ONNX Runtime на CPU или DirectML. Для входа изображение RGB растягивается до 1024 × 1024 без сохранения пропорций. В README приведено сравнение с предсказателем SAM 2: качество масок почти совпадает с исходной моделью, а для FP16 энкодера IoU при одном клике составил 0,9998. Репозиторий распространяется по лицензии Apache-2.0.

Сценарии применения

  • выделение объекта на фотографии по клику
  • сегментация объекта по ограничивающей рамке
  • уточнение маски объекта последовательными подсказками
  • интеграция интерактивного выделения объектов в фоторедактор
  • запуск сегментации через ONNX Runtime на CPU или DirectML

Ограничения

Входное изображение растягивается до 1024 × 1024 без сохранения соотношения сторон. Модель предназначена для сегментации изображений с точечными или рамочными подсказками, а не для обработки видео.

Публичные бенчмарки

Результаты из открытых лидербордов в сравнении с лидерами каталога

Публичных оценок пока нет

В подключённых источниках результатов этой модели не нашлось. Отсутствие оценки не значит, что модель хуже: её могли просто не проверять.

Источники: Hugging Face Leaderboards, Hugging Face Eval Results, Open LLM v2, MTEB, timm, Open ASR, EvalPlus, LLM Stats

Для каких профессий подходит3

Разделы каталога профессий, в задачах которых используется эта модель

Все профессии

Карточка модели

README от автора на Hugging Face, как он его опубликовал

Открыть на Hugging Face

SAM 2.1 hiera-tiny - ONNX (encoder FP16, decoder FP32)

ONNX export of Meta's SAM 2.1 hiera-tiny image segmentation model, built for the object selection in Oku3D's photo editor and usable by any ONNX Runtime consumer. The export runs on DirectML as well as on the CPU.

filewhat it doessize
sam2.1-tiny-encoder_fp16.onnximage encoder, run once per picture70 MB
sam2.1-tiny-decoder_fp32.onnxprompt encoder and mask decoder, run per click or box18 MB

Built from sam2.1_hiera_tiny.pt and facebookresearch/sam2 at commit 2b90b9f.

Interface

encoder
  input   image             float32  [1, 3, 1024, 1024]
  output  image_embed       float32  [1, 256, 64, 64]
  output  high_res_feats_0  float16  [1, 32, 256, 256]
  output  high_res_feats_1  float16  [1, 64, 128, 128]

decoder
  input   image_embed       float32  [1, 256, 64, 64]
  input   high_res_feats_0  float32  [1, 32, 256, 256]
  input   high_res_feats_1  float32  [1, 64, 128, 128]
  input   point_coords      float32  [1, points, 2]
  input   point_labels      float32  [1, points]
  input   mask_input        float32  [1, 1, 256, 256]
  input   has_mask_input    float32  [1]
  output  masks             float32  [1, 4, 256, 256]
  output  iou               float32  [1, 4]

The image is RGB in [0, 1], stretched to 1024 x 1024 as SAM 2's own transform resizes it, aspect ratio not kept. The ImageNet standardization runs inside the graph.

The encoder's image embedding leaves as float32 and its two high-resolution features as float16; the decoder takes all three as float32.

point_coords are pixels of the 1024 x 1024 frame (x, y). point_labels: 1 a point on the object, 0 a point on the background, 2 and 3 a box's top-left and bottom-right corner. The padding point SAM 2 appends to a prompt is appended inside the graph. mask_input takes the logits of an earlier answer when has_mask_input is 1, and is ignored when it is 0.

masks holds the low-resolution logits of every mask token: index 0 is the single-mask answer, 1 to 3 the three alternatives. Pick as SAM 2's image predictor does:

  • for a single click, the alternative with the highest iou;
  • otherwise mask 0, unless it is unstable - its area above a logit of 0.05 is less than 98 % of its area above -0.05 - and then again the best alternative.

Cut the logits at 0 after resizing them to the picture.

Changes against the PyTorch model

  • Hiera's position embedding, which the model resizes bicubically to the patch grid on every run, is computed once for the 1024 input and stored. DirectML has no bicubic resize.
  • The encoder is exported from the float16 model, not converted afterwards.
  • Every CastLike is the plain Cast it amounts to, and allowzero is cleared on every Reshape whose target shape holds no zero. DirectML refuses a session holding either as exported.
  • The encoder's attention scales, float16 square roots of its fixed sizes, are stored as values. ONNX Runtime has no float16 square root on the CPU to fold them with, and warned once per node on every load.

Accuracy and speed

Against Meta's SAM2ImagePredictor on a photograph, fed the predictor's own resized input, on ONNX Runtime's CPU provider:

promptFP32 encoderFP16 encoder (shipped)
one clickidentical logits, mask IoU 1.0000mask IoU 0.9998
boxidentical logits, mask IoU 1.0000mask IoU 1.0000

With ONNX Runtime 1.24.4 and DirectML on an NVIDIA GeForce RTX 5070 Ti: encoder about 24 ms, decoder about 3.3 ms per prompt, after the first run.

Building

build/ holds the pipeline: Dockerfile, 01_export_onnx.py and 02_optimize_verify.py. With the sam2 source and the checkpoint beside it:

docker build -t oku3d-sam2-export build
docker run --rm -v "$PWD:/work" oku3d-sam2-export python build/01_export_onnx.py \
    --source /work/src/sam2 --ckpt /work/checkpoints/sam2.1_hiera_tiny.pt --out /work/out --opset 18
docker run --rm -v "$PWD:/work" oku3d-sam2-export python build/02_optimize_verify.py \
    --source /work/src/sam2 --ckpt /work/checkpoints/sam2.1_hiera_tiny.pt --out /work/out --image <photo>

License

Apache-2.0, as Meta publishes the SAM 2 code and checkpoints; see LICENSE.

Citation

@article{ravi2024sam2,
  title={SAM 2: Segment Anything in Images and Videos},
  author={Ravi, Nikhila and Gabeur, Valentin and Hu, Yuan-Ting and Hu, Ronghang and Ryali, Chaitanya and Ma, Tengyu and Khedr, Haitham and R{\"a}dle, Roman and Rolland, Chloe and Gustafson, Laura and Mintun, Eric and Pan, Junting and Alwala, Kalyan Vasudev and Carion, Nicolas and Wu, Chao-Yuan and Girshick, Ross and Doll{\'a}r, Piotr and Feichtenhofer, Christoph},
  journal={arXiv preprint arXiv:2408.00714},
  url={https://arxiv.org/abs/2408.00714},
  year={2024}
}

Как запустить

На своей GPU в ailist. Цена — по текущим предложениям провайдеров

GPU в ailist

Универсальный рантайм · onnxruntime

Нельзя запустить

Модель выложена только в формате ONNX, рантайм загружает PyTorch-веса.

Ревизия весов
1f6d09f

0 моделей