Instructions to use cstr/sam2.1-hiera-tiny-ONNX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sam2
How to use cstr/sam2.1-hiera-tiny-ONNX with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained("cstr/sam2.1-hiera-tiny-ONNX") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image(<your_image>) masks, _, _ = predictor.predict(<input_prompts>)# Use SAM2 with videos import torch from sam2.sam2_video_predictor import SAM2VideoPredictor predictor = SAM2VideoPredictor.from_pretrained("cstr/sam2.1-hiera-tiny-ONNX") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): state = predictor.init_state(<your_video>) # add new prompts and instantly get the output on the same frame frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>) # propagate the prompts to get masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... - Notebooks
- Google Colab
- Kaggle
File size: 2,740 Bytes
faf41b8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | {
"schema": "crisp3ds_sam_model_v1",
"model": "sam2.1_hiera_tiny",
"license": "Apache-2.0 (SAM 2, Copyright Meta Platforms, Inc. and affiliates)",
"format": "onnx",
"opset": 17,
"image_size": 1024,
"mask_size": 256,
"mean": [
0.485,
0.456,
0.406
],
"std": [
0.229,
0.224,
0.225
],
"encoder": "encoder.onnx",
"decoder": "decoder.onnx",
"dynamic_multimask": {
"enabled": false,
"stability_delta": 0.05,
"stability_threshold": 0.98
},
"files": {
"encoder.onnx": {
"bytes": 109473919,
"sha256": "4fda6e68561e27808cedffa8689749a622bba5f11ba66f4ca4e3a8a9f6360db5"
},
"decoder.onnx": {
"bytes": 20655795,
"sha256": "0ae944e08e55814c19afa4d143ef07b1a3dbad2decd77c15ec3ab220b9f57247"
}
},
"operators": {
"encoder.onnx": {
"Add": 127,
"Cast": 146,
"Concat": 113,
"Constant": 1011,
"ConstantOfShape": 12,
"Conv": 7,
"Cos": 6,
"Div": 87,
"Erf": 12,
"Expand": 7,
"Gather": 109,
"LayerNormalization": 24,
"MatMul": 77,
"MaxPool": 6,
"Mod": 48,
"Mul": 78,
"Pad": 5,
"Range": 6,
"Reshape": 94,
"Resize": 1,
"Shape": 136,
"Sin": 6,
"Slice": 54,
"Softmax": 12,
"Split": 12,
"Sqrt": 36,
"Squeeze": 36,
"Sub": 29,
"Tile": 7,
"Transpose": 94,
"Unsqueeze": 250
},
"decoder.onnx": {
"Add": 64,
"Cast": 62,
"Concat": 51,
"Constant": 378,
"ConstantOfShape": 12,
"ConvTranspose": 2,
"Cos": 1,
"Div": 33,
"Equal": 13,
"Erf": 2,
"Expand": 10,
"Gather": 117,
"Gemm": 15,
"LayerNormalization": 9,
"MatMul": 48,
"Mul": 37,
"Neg": 1,
"OneHot": 1,
"Pow": 1,
"Range": 4,
"ReduceMean": 2,
"Relu": 12,
"Reshape": 44,
"ScatterND": 2,
"Shape": 134,
"Sigmoid": 1,
"Sin": 1,
"Slice": 15,
"Softmax": 7,
"Sqrt": 22,
"Sub": 2,
"Tile": 1,
"Transpose": 31,
"Unsqueeze": 114,
"Where": 13
}
},
"exported_from": {
"checkpoint_sha256": "7402e0d864fa82708a20fbd15bc84245c2f26dff0eb43a4b5b93452deb34be69",
"config": "configs/sam2.1/sam2.1_hiera_t.yaml",
"torch": "2.7.0",
"onnx": "1.23.2"
},
"check": {
"work": "/Users/christianstrobele/code/crisp3ds/.local-tools/sam-native-229/reference/bunny-mps/work",
"photo_size": [
1749,
1155
],
"torch": "2.7.0",
"onnxruntime": "1.30.0",
"graphs": {
"encoder.onnx": {
"views": 8,
"image_embed_max_abs_difference": 1.4901161193847656e-05,
"mask_logit_max_abs_difference": 7.152557373046875e-05,
"predicted_iou_max_abs_difference": 6.556510925292969e-07,
"raw_mask_iou_minimum_over_candidates": 0.9999957481185424,
"selected_mask_iou_median": 1.0,
"selected_mask_iou_minimum": 1.0,
"same_candidate_selected": 8
}
}
}
}
|