Downloads · 30 days
0
rajlab/sam_vit_b
sam_vit_b is a machine learning model from rajlab. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
The segment anything tool is uses the Segment Anything Model (SAM). This folder contains the ONNX files that represent the SAM and are used by the browser to compute segmentations.
Downloads · 30 days
0
Access
Public
Updated Apr 24, 2024
Repo size
376 MB
Likes
0
Public
Click a slice to open those files.
.onnx376 MB · 100%
From the Hugging Face model README
The segment anything tool is uses the Segment Anything Model (SAM). This folder contains the ONNX files that represent the SAM and are used by the browser to compute segmentations.
The SAM is provided by Facebook in the form of a pytorch model: a .pth file.
There are three types of model. They are, from the biggest to the smallest, vit_h, vit_l and vit_b.
It is advised to use vit_b as it is smaller and faster, at the cost of a lower quality segmentation.
Facebook provides a script to convert the decoder to ONNX but not the encoder. The maintainers refuse to merge PRs adding this feature. You can use the script given in one of these PRs, but the chosen solution is to use the samexporter.
checkpoint.pth model downloaded in the previous step.mkdir temp
cd temp
git clone [email protected]:vietanhdev/samexporter.git
git clone [email protected]:facebookresearch/segment-anything.git
pip install -e ./segment-anything
pip install torchvision==0.16.1 onnx==1.15.0 onnxruntime==1.15.1 timm==0.9.12
cd samexporter
python -m samexporter.export_encoder --checkpoint ../checkpoint.pth --output ../encoder.onnx --model-type vit_b
python -m samexporter.export_decoder --checkpoint ../checkpoint.pth --output ../decoder.onnx --model-type vit_b --return-single-mask
vit_b)cd $NIMUS_IMAGE_DIR
cp encoder.onnx public/onnx-models/sam/$MODEL_NAME
cp decoder.onnx public/onnx-models/sam/$MODEL_NAME