Segment-Anything-Model: Optimized for Mobile Deployment
High-quality segmentation mask generation around any object in an image with simple input prompt
Transformer based encoder-decoder where prompts specify what to segment in an image thereby allowing segmentation without the need for additional training. The image encoder generates embeddings and the lightweight decoder operates on the embeddings for point and mask based image segmentation.
This model is an implementation of Segment-Anything-Model found here.
This repository provides scripts to run Segment-Anything-Model on Qualcomm® devices. More details on model performance across various devices, can be found here.
Model Details
- Model Type: Semantic segmentation
- Model Stats:
- Model checkpoint: vit_l
- Input resolution: 720p (720x1280)
- Number of parameters (SAMDecoder): 5.11M
- Model size (SAMDecoder): 19.6 MB
Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model |
---|---|---|---|---|---|---|---|---|
SAMDecoder | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 7.557 ms | 0 - 31 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 7.052 ms | 4 - 19 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMDecoder | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 11.415 ms | 0 - 266 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMDecoder | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 5.23 ms | 0 - 39 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 4.973 ms | 4 - 46 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMDecoder | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 7.741 ms | 5 - 126 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMDecoder | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 5.18 ms | 0 - 35 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 3.787 ms | 4 - 42 MB | FP16 | NPU | Use Export Script |
SAMDecoder | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 8.231 ms | 0 - 86 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMDecoder | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 7.484 ms | 0 - 33 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 6.814 ms | 4 - 5 MB | FP16 | NPU | Use Export Script |
SAMDecoder | SA7255P ADP | SA7255P | TFLITE | 52.929 ms | 0 - 32 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | SA7255P ADP | SA7255P | QNN | 50.031 ms | 2 - 11 MB | FP16 | NPU | Use Export Script |
SAMDecoder | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 7.484 ms | 0 - 32 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | SA8255 (Proxy) | SA8255P Proxy | QNN | 6.852 ms | 4 - 5 MB | FP16 | NPU | Use Export Script |
SAMDecoder | SA8295P ADP | SA8295P | TFLITE | 9.976 ms | 0 - 35 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | SA8295P ADP | SA8295P | QNN | 9.05 ms | 0 - 6 MB | FP16 | NPU | Use Export Script |
SAMDecoder | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 7.477 ms | 0 - 29 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | SA8650 (Proxy) | SA8650P Proxy | QNN | 6.893 ms | 4 - 6 MB | FP16 | NPU | Use Export Script |
SAMDecoder | SA8775P ADP | SA8775P | TFLITE | 10.51 ms | 0 - 34 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | SA8775P ADP | SA8775P | QNN | 9.667 ms | 0 - 6 MB | FP16 | NPU | Use Export Script |
SAMDecoder | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 8.533 ms | 0 - 37 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 8.315 ms | 4 - 44 MB | FP16 | NPU | Use Export Script |
SAMDecoder | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 7.458 ms | 4 - 4 MB | FP16 | NPU | Use Export Script |
SAMDecoder | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 14.75 ms | 12 - 12 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart1 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 208.201 ms | 12 - 74 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 203.885 ms | 12 - 67 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart1 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 168.865 ms | 12 - 57 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart1 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 149.759 ms | 11 - 660 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 144.476 ms | 364 - 1006 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart1 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 121.68 ms | 0 - 1234 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart1 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 128.622 ms | 11 - 667 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 141.432 ms | 3 - 655 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 96.596 ms | 39 - 1086 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart1 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 205.315 ms | 12 - 81 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 177.157 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | SA7255P ADP | SA7255P | TFLITE | 1173.558 ms | 2 - 646 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | SA7255P ADP | SA7255P | QNN | 1100.71 ms | 4 - 13 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 208.837 ms | 12 - 70 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | SA8255 (Proxy) | SA8255P Proxy | QNN | 178.44 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | SA8295P ADP | SA8295P | TFLITE | 242.752 ms | 12 - 640 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | SA8295P ADP | SA8295P | QNN | 206.972 ms | 0 - 6 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 208.397 ms | 12 - 65 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | SA8650 (Proxy) | SA8650P Proxy | QNN | 177.673 ms | 13 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | SA8775P ADP | SA8775P | TFLITE | 251.286 ms | 12 - 656 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | SA8775P ADP | SA8775P | QNN | 211.825 ms | 3 - 9 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 226.498 ms | 12 - 995 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 219.929 ms | 9 - 964 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 171.827 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 179.691 ms | 39 - 39 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart2 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 670.133 ms | 12 - 104 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 838.379 ms | 12 - 109 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart2 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 722.337 ms | 0 - 54 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart2 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 556.374 ms | 11 - 1092 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 668.897 ms | 12 - 1113 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart2 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 487.43 ms | 12 - 1100 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 574.723 ms | 10 - 1113 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 474.562 ms | 41 - 4748 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart2 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 671.625 ms | 0 - 102 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 737.788 ms | 13 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | SA7255P ADP | SA7255P | QNN | 1869.513 ms | 0 - 10 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 690.907 ms | 12 - 116 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | SA8255 (Proxy) | SA8255P Proxy | QNN | 731.994 ms | 15 - 16 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | SA8295P ADP | SA8295P | TFLITE | 726.454 ms | 12 - 1141 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | SA8295P ADP | SA8295P | QNN | 782.399 ms | 0 - 6 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 671.719 ms | 12 - 104 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | SA8650 (Proxy) | SA8650P Proxy | QNN | 733.997 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | SA8775P ADP | SA8775P | TFLITE | 717.157 ms | 0 - 1105 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 633.76 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 743.453 ms | 51 - 51 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart3 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 686.379 ms | 12 - 103 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 852.964 ms | 12 - 115 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart3 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 740.438 ms | 9 - 62 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart3 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 440.773 ms | 12 - 1099 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 579.622 ms | 11 - 1115 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 472.649 ms | 39 - 4748 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart3 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 668.273 ms | 12 - 114 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 731.938 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | SA7255P ADP | SA7255P | QNN | 1874.534 ms | 12 - 22 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 684.379 ms | 12 - 108 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | SA8255 (Proxy) | SA8255P Proxy | QNN | 731.638 ms | 13 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | SA8295P ADP | SA8295P | TFLITE | 725.387 ms | 12 - 1148 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | SA8295P ADP | SA8295P | QNN | 781.146 ms | 0 - 6 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 683.645 ms | 12 - 112 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | SA8650 (Proxy) | SA8650P Proxy | QNN | 735.421 ms | 13 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | SA8775P ADP | SA8775P | TFLITE | 724.877 ms | 0 - 1107 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | SA8775P ADP | SA8775P | QNN | 742.231 ms | 1 - 11 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 632.458 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 741.655 ms | 51 - 51 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart4 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 833.428 ms | 12 - 100 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart4 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 682.163 ms | 0 - 53 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart4 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 437.593 ms | 11 - 1098 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 531.361 ms | 10 - 1119 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 563.94 ms | 26 - 5204 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart4 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 675.986 ms | 12 - 102 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 731.308 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 677.387 ms | 12 - 103 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | SA8255 (Proxy) | SA8255P Proxy | QNN | 740.258 ms | 13 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | SA8295P ADP | SA8295P | TFLITE | 725.343 ms | 12 - 1150 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | SA8295P ADP | SA8295P | QNN | 782.501 ms | 0 - 6 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 674.544 ms | 12 - 102 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | SA8650 (Proxy) | SA8650P Proxy | QNN | 745.54 ms | 13 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | SA8775P ADP | SA8775P | QNN | 738.7 ms | 12 - 22 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 628.108 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 739.45 ms | 53 - 53 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart5 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 671.428 ms | 12 - 107 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 844.265 ms | 12 - 102 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart5 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 684.639 ms | 0 - 53 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart5 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 548.457 ms | 12 - 1096 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 484.471 ms | 11 - 1099 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 575.509 ms | 7 - 1111 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 470.838 ms | 39 - 4742 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart5 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 665.458 ms | 12 - 104 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 720.635 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | SA7255P ADP | SA7255P | QNN | 1874.681 ms | 11 - 22 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 691.758 ms | 12 - 113 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | SA8255 (Proxy) | SA8255P Proxy | QNN | 745.957 ms | 13 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | SA8295P ADP | SA8295P | TFLITE | 725.701 ms | 12 - 1149 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | SA8295P ADP | SA8295P | QNN | 782.525 ms | 0 - 6 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 679.545 ms | 12 - 105 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | SA8650 (Proxy) | SA8650P Proxy | QNN | 730.129 ms | 13 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | SA8775P ADP | SA8775P | QNN | 741.02 ms | 1 - 11 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 640.949 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 735.548 ms | 51 - 51 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart6 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 677.701 ms | 12 - 102 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 841.659 ms | 12 - 109 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart6 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 684.635 ms | 0 - 935 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart6 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 536.637 ms | 10 - 1099 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 485.849 ms | 11 - 1093 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 579.641 ms | 10 - 1114 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 472.01 ms | 39 - 4745 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart6 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 656.062 ms | 12 - 113 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 730.888 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | SA7255P ADP | SA7255P | QNN | 1868.576 ms | 5 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 688.443 ms | 12 - 102 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | SA8255 (Proxy) | SA8255P Proxy | QNN | 736.226 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | SA8295P ADP | SA8295P | TFLITE | 725.807 ms | 5 - 1142 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | SA8295P ADP | SA8295P | QNN | 782.131 ms | 0 - 6 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 672.876 ms | 12 - 104 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | SA8650 (Proxy) | SA8650P Proxy | QNN | 740.495 ms | 16 - 18 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | SA8775P ADP | SA8775P | TFLITE | 726.536 ms | 0 - 1104 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | SA8775P ADP | SA8775P | QNN | 742.038 ms | 2 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 629.137 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 743.947 ms | 52 - 52 MB | FP16 | NPU | Segment-Anything-Model.onnx |
Installation
This model can be installed as a Python package via pip.
pip install "qai-hub-models[sam]"
Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
Sign-in to Qualcomm® AI Hub with your
Qualcomm® ID. Once signed in navigate to Account -> Settings -> API Token
.
With this API token, you can configure your client to run models on the cloud hosted devices.
qai-hub configure --api_token API_TOKEN
Navigate to docs for more information.
Demo off target
The package contains a simple end-to-end demo that downloads pre-trained weights and runs this model on a sample input.
python -m qai_hub_models.models.sam.demo
The above demo runs a reference implementation of pre-processing, model inference, and post processing.
NOTE: If you want running in a Jupyter Notebook or Google Colab like environment, please add the following to your cell (instead of the above).
%run -m qai_hub_models.models.sam.demo
Run model on a cloud-hosted device
In addition to the demo, you can also run the model on a cloud-hosted Qualcomm® device. This script does the following:
- Performance check on-device on a cloud-hosted device
- Downloads compiled assets that can be deployed on-device for Android.
- Accuracy check between PyTorch and on-device outputs.
python -m qai_hub_models.models.sam.export
Profiling Results
------------------------------------------------------------
SAMDecoder
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 7.6
Estimated peak memory usage (MB): [0, 31]
Total # Ops : 845
Compute Unit(s) : NPU (845 ops)
------------------------------------------------------------
SAMEncoderPart1
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 208.2
Estimated peak memory usage (MB): [12, 74]
Total # Ops : 585
Compute Unit(s) : NPU (585 ops)
------------------------------------------------------------
SAMEncoderPart2
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 670.1
Estimated peak memory usage (MB): [12, 104]
Total # Ops : 580
Compute Unit(s) : NPU (580 ops)
------------------------------------------------------------
SAMEncoderPart3
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 686.4
Estimated peak memory usage (MB): [12, 103]
Total # Ops : 580
Compute Unit(s) : NPU (580 ops)
------------------------------------------------------------
SAMEncoderPart4
Device : Samsung Galaxy S23 (13)
Runtime : QNN
Estimated inference time (ms) : 833.4
Estimated peak memory usage (MB): [12, 100]
Total # Ops : 613
Compute Unit(s) : NPU (613 ops)
------------------------------------------------------------
SAMEncoderPart5
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 671.4
Estimated peak memory usage (MB): [12, 107]
Total # Ops : 580
Compute Unit(s) : NPU (580 ops)
------------------------------------------------------------
SAMEncoderPart6
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 677.7
Estimated peak memory usage (MB): [12, 102]
Total # Ops : 580
Compute Unit(s) : NPU (580 ops)
How does this work?
This export script leverages Qualcomm® AI Hub to optimize, validate, and deploy this model on-device. Lets go through each step below in detail:
Step 1: Compile model for on-device deployment
To compile a PyTorch model for on-device deployment, we first trace the model
in memory using the jit.trace
and then call the submit_compile_job
API.
import torch
import qai_hub as hub
from qai_hub_models.models.sam import Model
# Load the model
model = Model.from_pretrained()
decoder_model = model.decoder
encoder_splits[0]_model = model.encoder_splits[0]
encoder_splits[1]_model = model.encoder_splits[1]
encoder_splits[2]_model = model.encoder_splits[2]
encoder_splits[3]_model = model.encoder_splits[3]
encoder_splits[4]_model = model.encoder_splits[4]
encoder_splits[5]_model = model.encoder_splits[5]
# Device
device = hub.Device("Samsung Galaxy S23")
# Trace model
decoder_input_shape = decoder_model.get_input_spec()
decoder_sample_inputs = decoder_model.sample_inputs()
traced_decoder_model = torch.jit.trace(decoder_model, [torch.tensor(data[0]) for _, data in decoder_sample_inputs.items()])
# Compile model on a specific device
decoder_compile_job = hub.submit_compile_job(
model=traced_decoder_model ,
device=device,
input_specs=decoder_model.get_input_spec(),
)
# Get target model to run on-device
decoder_target_model = decoder_compile_job.get_target_model()
# Trace model
encoder_splits[0]_input_shape = encoder_splits[0]_model.get_input_spec()
encoder_splits[0]_sample_inputs = encoder_splits[0]_model.sample_inputs()
traced_encoder_splits[0]_model = torch.jit.trace(encoder_splits[0]_model, [torch.tensor(data[0]) for _, data in encoder_splits[0]_sample_inputs.items()])
# Compile model on a specific device
encoder_splits[0]_compile_job = hub.submit_compile_job(
model=traced_encoder_splits[0]_model ,
device=device,
input_specs=encoder_splits[0]_model.get_input_spec(),
)
# Get target model to run on-device
encoder_splits[0]_target_model = encoder_splits[0]_compile_job.get_target_model()
# Trace model
encoder_splits[1]_input_shape = encoder_splits[1]_model.get_input_spec()
encoder_splits[1]_sample_inputs = encoder_splits[1]_model.sample_inputs()
traced_encoder_splits[1]_model = torch.jit.trace(encoder_splits[1]_model, [torch.tensor(data[0]) for _, data in encoder_splits[1]_sample_inputs.items()])
# Compile model on a specific device
encoder_splits[1]_compile_job = hub.submit_compile_job(
model=traced_encoder_splits[1]_model ,
device=device,
input_specs=encoder_splits[1]_model.get_input_spec(),
)
# Get target model to run on-device
encoder_splits[1]_target_model = encoder_splits[1]_compile_job.get_target_model()
# Trace model
encoder_splits[2]_input_shape = encoder_splits[2]_model.get_input_spec()
encoder_splits[2]_sample_inputs = encoder_splits[2]_model.sample_inputs()
traced_encoder_splits[2]_model = torch.jit.trace(encoder_splits[2]_model, [torch.tensor(data[0]) for _, data in encoder_splits[2]_sample_inputs.items()])
# Compile model on a specific device
encoder_splits[2]_compile_job = hub.submit_compile_job(
model=traced_encoder_splits[2]_model ,
device=device,
input_specs=encoder_splits[2]_model.get_input_spec(),
)
# Get target model to run on-device
encoder_splits[2]_target_model = encoder_splits[2]_compile_job.get_target_model()
# Trace model
encoder_splits[3]_input_shape = encoder_splits[3]_model.get_input_spec()
encoder_splits[3]_sample_inputs = encoder_splits[3]_model.sample_inputs()
traced_encoder_splits[3]_model = torch.jit.trace(encoder_splits[3]_model, [torch.tensor(data[0]) for _, data in encoder_splits[3]_sample_inputs.items()])
# Compile model on a specific device
encoder_splits[3]_compile_job = hub.submit_compile_job(
model=traced_encoder_splits[3]_model ,
device=device,
input_specs=encoder_splits[3]_model.get_input_spec(),
)
# Get target model to run on-device
encoder_splits[3]_target_model = encoder_splits[3]_compile_job.get_target_model()
# Trace model
encoder_splits[4]_input_shape = encoder_splits[4]_model.get_input_spec()
encoder_splits[4]_sample_inputs = encoder_splits[4]_model.sample_inputs()
traced_encoder_splits[4]_model = torch.jit.trace(encoder_splits[4]_model, [torch.tensor(data[0]) for _, data in encoder_splits[4]_sample_inputs.items()])
# Compile model on a specific device
encoder_splits[4]_compile_job = hub.submit_compile_job(
model=traced_encoder_splits[4]_model ,
device=device,
input_specs=encoder_splits[4]_model.get_input_spec(),
)
# Get target model to run on-device
encoder_splits[4]_target_model = encoder_splits[4]_compile_job.get_target_model()
# Trace model
encoder_splits[5]_input_shape = encoder_splits[5]_model.get_input_spec()
encoder_splits[5]_sample_inputs = encoder_splits[5]_model.sample_inputs()
traced_encoder_splits[5]_model = torch.jit.trace(encoder_splits[5]_model, [torch.tensor(data[0]) for _, data in encoder_splits[5]_sample_inputs.items()])
# Compile model on a specific device
encoder_splits[5]_compile_job = hub.submit_compile_job(
model=traced_encoder_splits[5]_model ,
device=device,
input_specs=encoder_splits[5]_model.get_input_spec(),
)
# Get target model to run on-device
encoder_splits[5]_target_model = encoder_splits[5]_compile_job.get_target_model()
Step 2: Performance profiling on cloud-hosted device
After compiling models from step 1. Models can be profiled model on-device using the
target_model
. Note that this scripts runs the model on a device automatically
provisioned in the cloud. Once the job is submitted, you can navigate to a
provided job URL to view a variety of on-device performance metrics.
decoder_profile_job = hub.submit_profile_job(
model=decoder_target_model,
device=device,
)
encoder_splits[0]_profile_job = hub.submit_profile_job(
model=encoder_splits[0]_target_model,
device=device,
)
encoder_splits[1]_profile_job = hub.submit_profile_job(
model=encoder_splits[1]_target_model,
device=device,
)
encoder_splits[2]_profile_job = hub.submit_profile_job(
model=encoder_splits[2]_target_model,
device=device,
)
encoder_splits[3]_profile_job = hub.submit_profile_job(
model=encoder_splits[3]_target_model,
device=device,
)
encoder_splits[4]_profile_job = hub.submit_profile_job(
model=encoder_splits[4]_target_model,
device=device,
)
encoder_splits[5]_profile_job = hub.submit_profile_job(
model=encoder_splits[5]_target_model,
device=device,
)
Step 3: Verify on-device accuracy
To verify the accuracy of the model on-device, you can run on-device inference on sample input data on the same cloud hosted device.
decoder_input_data = decoder_model.sample_inputs()
decoder_inference_job = hub.submit_inference_job(
model=decoder_target_model,
device=device,
inputs=decoder_input_data,
)
decoder_inference_job.download_output_data()
encoder_splits[0]_input_data = encoder_splits[0]_model.sample_inputs()
encoder_splits[0]_inference_job = hub.submit_inference_job(
model=encoder_splits[0]_target_model,
device=device,
inputs=encoder_splits[0]_input_data,
)
encoder_splits[0]_inference_job.download_output_data()
encoder_splits[1]_input_data = encoder_splits[1]_model.sample_inputs()
encoder_splits[1]_inference_job = hub.submit_inference_job(
model=encoder_splits[1]_target_model,
device=device,
inputs=encoder_splits[1]_input_data,
)
encoder_splits[1]_inference_job.download_output_data()
encoder_splits[2]_input_data = encoder_splits[2]_model.sample_inputs()
encoder_splits[2]_inference_job = hub.submit_inference_job(
model=encoder_splits[2]_target_model,
device=device,
inputs=encoder_splits[2]_input_data,
)
encoder_splits[2]_inference_job.download_output_data()
encoder_splits[3]_input_data = encoder_splits[3]_model.sample_inputs()
encoder_splits[3]_inference_job = hub.submit_inference_job(
model=encoder_splits[3]_target_model,
device=device,
inputs=encoder_splits[3]_input_data,
)
encoder_splits[3]_inference_job.download_output_data()
encoder_splits[4]_input_data = encoder_splits[4]_model.sample_inputs()
encoder_splits[4]_inference_job = hub.submit_inference_job(
model=encoder_splits[4]_target_model,
device=device,
inputs=encoder_splits[4]_input_data,
)
encoder_splits[4]_inference_job.download_output_data()
encoder_splits[5]_input_data = encoder_splits[5]_model.sample_inputs()
encoder_splits[5]_inference_job = hub.submit_inference_job(
model=encoder_splits[5]_target_model,
device=device,
inputs=encoder_splits[5]_input_data,
)
encoder_splits[5]_inference_job.download_output_data()
With the output of the model, you can compute like PSNR, relative errors or spot check the output with expected output.
Note: This on-device profiling and inference requires access to Qualcomm® AI Hub. Sign up for access.
Run demo on a cloud-hosted device
You can also run the demo on-device.
python -m qai_hub_models.models.sam.demo --on-device
NOTE: If you want running in a Jupyter Notebook or Google Colab like environment, please add the following to your cell (instead of the above).
%run -m qai_hub_models.models.sam.demo -- --on-device
Deploying compiled model to Android
The models can be deployed using multiple runtimes:
TensorFlow Lite (
.tflite
export): This tutorial provides a guide to deploy the .tflite model in an Android application.QNN (
.so
export ): This sample app provides instructions on how to use the.so
shared library in an Android application.
View on Qualcomm® AI Hub
Get more details on Segment-Anything-Model's performance across various devices here. Explore all available models on Qualcomm® AI Hub
License
- The license for the original implementation of Segment-Anything-Model can be found here.
- The license for the compiled assets for on-device deployment can be found here
References
Community
- Join our AI Hub Slack community to collaborate, post questions and learn more about on-device AI.
- For questions or feedback please reach out to us.