Skip to content
Back to skills

Onnx And Browser

ASecurity

"Export Segment Anything's prompt encoder and mask decoder to ONNX,

  • 247 stars
  • 0 votes
  • 0 copies
  • 7 views
  • Added September 9, 2026
toolspythonapi

Works with

  • api

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned September 9, 2026

npx -y skills add VectorSpaceLab/AREX-Skill --skill onnx-and-browser --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Onnx And Browser?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Onnx And Browser
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectorspacelab-onnx-and-browser/badge)](https://www.skillsdirectory.com/skills/vectorspacelab-onnx-and-browser)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: onnx-and-browser
description: "Export Segment Anything's prompt encoder and mask decoder to ONNX,
  quantize it, prepare matching image embeddings, and wire the model into
  ONNXRuntime or browser workflows."
disable-model-invocation: true
metadata:
  disco-role: operating
license: Apache 2.0
---

# ONNX and Browser Workflows

Use this sub-skill when the user asks to export SAM to ONNX, quantize a SAM ONNX model, run the mask decoder in ONNXRuntime Web, prepare a `.npy` image embedding for a browser demo, or diagnose ONNX/browser input shape issues.

## Route First

- For prompted Python inference with `SamPredictor.predict`, use `../prompted-segmentation/` unless ONNX export or embeddings are part of the request.
- For full-image automatic mask generation with `SamAutomaticMaskGenerator`, use `../automatic-mask-generation/`.
- For browser workflows, export both a mask decoder ONNX file and image embeddings produced by the same checkpoint/model type/image preprocessing path.

## Fast Paths

- Export ONNX with `python sub-skills/onnx-and-browser/scripts/export_onnx_model.py --checkpoint sam_vit_h_4b8939.pth --model-type vit_h --output sam_onnx.onnx`.
- Quantize for browser size/runtime with `--quantize-out sam_onnx_quantized.onnx`; this requires `onnxruntime` because quantization uses ONNXRuntime tooling.
- Prepare a matching embedding by adapting `scripts/prepare_embedding_template.py`; save the `.npy` beside the browser image asset.
- In browser feeds, use input names `image_embeddings`, `point_coords`, `point_labels`, `mask_input`, `has_mask_input`, and `orig_im_size`.

## References

- `references/onnx-export.md` explains export flags, tensor contracts, dynamic axes, quantization, and embedding compatibility.
- `references/browser-demo.md` explains browser asset layout, ONNXRuntime Web feeds, scaling, and SharedArrayBuffer headers.
- `references/api-reference.md` summarizes `SamOnnxModel`, export-script behavior, input/output names, and expected shapes.
- `references/troubleshooting.md` maps common export/runtime/browser errors to concrete fixes.

## Bundled Scripts

- `scripts/export_onnx_model.py` is an adapted export helper with safe `--help` behavior and clearer optional-dependency errors.
- `scripts/prepare_embedding_template.py` is a template for exporting a `.npy` image embedding from `SamPredictor` for ONNX/browser use.

Files in this skill

  • SKILL.md2.3 KB
  • references/api-reference.md2.6 KB
  • references/browser-demo.md3 KB
  • references/onnx-export.md3.4 KB
  • references/troubleshooting.md2.9 KB
  • scripts/export_onnx_model.py7.2 KB
  • scripts/prepare_embedding_template.py2.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.