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.496 ms | 0 - 29 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 7.297 ms | 4 - 26 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMDecoder | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 10.997 ms | 1 - 59 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMDecoder | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 5.194 ms | 0 - 39 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 5.138 ms | 4 - 45 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMDecoder | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 7.908 ms | 4 - 58 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMDecoder | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 5.022 ms | 0 - 35 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 4.808 ms | 4 - 43 MB | FP16 | NPU | Use Export Script |
SAMDecoder | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 8.33 ms | 3 - 48 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMDecoder | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 7.482 ms | 0 - 34 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 6.833 ms | 4 - 7 MB | FP16 | NPU | Use Export Script |
SAMDecoder | SA7255P ADP | SA7255P | TFLITE | 53.072 ms | 0 - 31 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | SA7255P ADP | SA7255P | QNN | 49.854 ms | 2 - 9 MB | FP16 | NPU | Use Export Script |
SAMDecoder | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 7.488 ms | 0 - 33 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | SA8255 (Proxy) | SA8255P Proxy | QNN | 6.856 ms | 4 - 6 MB | FP16 | NPU | Use Export Script |
SAMDecoder | SA8295P ADP | SA8295P | TFLITE | 10.448 ms | 0 - 35 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | SA8295P ADP | SA8295P | QNN | 9.023 ms | 0 - 14 MB | FP16 | NPU | Use Export Script |
SAMDecoder | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 7.468 ms | 0 - 31 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | SA8650 (Proxy) | SA8650P Proxy | QNN | 6.898 ms | 4 - 7 MB | FP16 | NPU | Use Export Script |
SAMDecoder | SA8775P ADP | SA8775P | TFLITE | 10.481 ms | 0 - 32 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | SA8775P ADP | SA8775P | QNN | 9.672 ms | 1 - 11 MB | FP16 | NPU | Use Export Script |
SAMDecoder | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 8.944 ms | 0 - 39 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMDecoder | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 8.3 ms | 4 - 47 MB | FP16 | NPU | Use Export Script |
SAMDecoder | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 7.387 ms | 4 - 4 MB | FP16 | NPU | Use Export Script |
SAMDecoder | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 14.654 ms | 13 - 13 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart1 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 209.019 ms | 12 - 69 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 205.936 ms | 12 - 93 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart1 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 170.285 ms | 25 - 176 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart1 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 148.733 ms | 10 - 653 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 146.052 ms | 12 - 652 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart1 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 120.931 ms | 24 - 696 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart1 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 146.901 ms | 12 - 670 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 142.17 ms | 3 - 654 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 108.126 ms | 24 - 673 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart1 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 209.39 ms | 12 - 78 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 175.952 ms | 12 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | SA7255P ADP | SA7255P | TFLITE | 1176.456 ms | 12 - 655 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | SA7255P ADP | SA7255P | QNN | 1101.014 ms | 4 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 208.032 ms | 12 - 74 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | SA8255 (Proxy) | SA8255P Proxy | QNN | 178.079 ms | 12 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | SA8295P ADP | SA8295P | TFLITE | 243.729 ms | 12 - 640 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | SA8295P ADP | SA8295P | QNN | 207.581 ms | 0 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 206.899 ms | 12 - 79 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | SA8650 (Proxy) | SA8650P Proxy | QNN | 178.981 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | SA8775P ADP | SA8775P | TFLITE | 252.41 ms | 12 - 655 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | SA8775P ADP | SA8775P | QNN | 211.388 ms | 1 - 11 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 232.157 ms | 12 - 995 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart1 | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 222.335 ms | 4 - 965 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 171.549 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart1 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 181.095 ms | 38 - 38 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart2 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 654.976 ms | 12 - 110 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 832.207 ms | 12 - 110 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart2 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 694.809 ms | 0 - 201 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart2 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 661.317 ms | 12 - 1110 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart2 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 472.889 ms | 12 - 1148 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 528.224 ms | 12 - 1115 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 462.973 ms | 25 - 1409 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart2 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 654.376 ms | 12 - 104 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 728.462 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 684.138 ms | 12 - 104 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | SA8255 (Proxy) | SA8255P Proxy | QNN | 744.998 ms | 12 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | SA8295P ADP | SA8295P | TFLITE | 704.249 ms | 12 - 1176 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | SA8295P ADP | SA8295P | QNN | 782.37 ms | 0 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 624.867 ms | 12 - 110 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | SA8650 (Proxy) | SA8650P Proxy | QNN | 743.875 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | SA8775P ADP | SA8775P | TFLITE | 722.805 ms | 0 - 1144 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart2 | SA8775P ADP | SA8775P | QNN | 739.926 ms | 1 - 11 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 635.324 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart2 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 741.229 ms | 52 - 52 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart3 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 659.742 ms | 12 - 114 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 849.715 ms | 1 - 107 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart3 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 687.45 ms | 12 - 211 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart3 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 682.052 ms | 12 - 1108 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart3 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 609.933 ms | 24 - 1425 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart3 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 423.957 ms | 12 - 1149 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 577.926 ms | 12 - 1114 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 463.85 ms | 24 - 1409 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart3 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 658.397 ms | 12 - 105 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 719.036 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | SA7255P ADP | SA7255P | QNN | 1877.658 ms | 4 - 13 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 658.984 ms | 12 - 106 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | SA8255 (Proxy) | SA8255P Proxy | QNN | 746.128 ms | 12 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | SA8295P ADP | SA8295P | TFLITE | 707.389 ms | 11 - 1169 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | SA8295P ADP | SA8295P | QNN | 780.808 ms | 0 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 650.209 ms | 12 - 104 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | SA8650 (Proxy) | SA8650P Proxy | QNN | 741.658 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | SA8775P ADP | SA8775P | TFLITE | 699.588 ms | 0 - 1145 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart3 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 682.704 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart3 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 741.666 ms | 53 - 53 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart4 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 660.425 ms | 12 - 103 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 850.796 ms | 12 - 111 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart4 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 735.756 ms | 24 - 217 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart4 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 676.625 ms | 3 - 1105 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart4 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 606.957 ms | 23 - 1418 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart4 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 469.821 ms | 11 - 1144 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 574.694 ms | 10 - 1118 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 462.452 ms | 36 - 1417 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart4 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 661.229 ms | 12 - 103 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 727.569 ms | 12 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | SA7255P ADP | SA7255P | QNN | 1869.043 ms | 8 - 17 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 662.568 ms | 12 - 103 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | SA8255 (Proxy) | SA8255P Proxy | QNN | 733.293 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | SA8295P ADP | SA8295P | TFLITE | 706.266 ms | 12 - 1172 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | SA8295P ADP | SA8295P | QNN | 784.772 ms | 0 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 656.939 ms | 12 - 108 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | SA8650 (Proxy) | SA8650P Proxy | QNN | 741.153 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | SA8775P ADP | SA8775P | TFLITE | 717.416 ms | 0 - 1143 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart4 | SA8775P ADP | SA8775P | QNN | 739.764 ms | 6 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 629.135 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart4 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 742.285 ms | 52 - 52 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart5 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 664.891 ms | 12 - 102 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 818.349 ms | 12 - 120 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart5 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 752.745 ms | 24 - 211 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart5 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 666.563 ms | 6 - 1101 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart5 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 578.332 ms | 18 - 1423 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart5 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 471.325 ms | 12 - 1147 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 577.197 ms | 12 - 1114 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 461.817 ms | 36 - 1424 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart5 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 655.75 ms | 12 - 118 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 749.162 ms | 12 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | SA7255P ADP | SA7255P | QNN | 1874.378 ms | 4 - 13 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 665.3 ms | 12 - 113 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | SA8255 (Proxy) | SA8255P Proxy | QNN | 736.349 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | SA8295P ADP | SA8295P | TFLITE | 1.844674407370935e+16 ms | 12 - 1172 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | SA8295P ADP | SA8295P | QNN | 783.84 ms | 1 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 654.117 ms | 12 - 115 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | SA8650 (Proxy) | SA8650P Proxy | QNN | 743.603 ms | 12 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | SA8775P ADP | SA8775P | TFLITE | 718.325 ms | 0 - 1144 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart5 | SA8775P ADP | SA8775P | QNN | 740.649 ms | 12 - 22 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 633.494 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart5 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 742.408 ms | 52 - 52 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart6 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 655.189 ms | 12 - 108 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 807.274 ms | 12 - 120 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart6 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 755.205 ms | 12 - 204 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart6 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 668.409 ms | 1212 - 2314 MB | FP16 | NPU | Segment-Anything-Model.so |
SAMEncoderPart6 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 584.922 ms | 24 - 1421 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart6 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 475.467 ms | 11 - 1140 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 528.924 ms | 10 - 1114 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 439.119 ms | 36 - 1413 MB | FP16 | NPU | Segment-Anything-Model.onnx |
SAMEncoderPart6 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 665.633 ms | 12 - 108 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 727.32 ms | 12 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 667.805 ms | 12 - 107 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | SA8255 (Proxy) | SA8255P Proxy | QNN | 742.425 ms | 12 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | SA8295P ADP | SA8295P | TFLITE | 706.978 ms | 12 - 1175 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | SA8295P ADP | SA8295P | QNN | 784.131 ms | 0 - 14 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 675.893 ms | 12 - 115 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | SA8650 (Proxy) | SA8650P Proxy | QNN | 739.078 ms | 12 - 15 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | SA8775P ADP | SA8775P | TFLITE | 703.126 ms | 0 - 1144 MB | FP16 | NPU | Segment-Anything-Model.tflite |
SAMEncoderPart6 | SA8775P ADP | SA8775P | QNN | 740.372 ms | 1 - 11 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 634.143 ms | 12 - 12 MB | FP16 | NPU | Use Export Script |
SAMEncoderPart6 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 726.741 ms | 51 - 51 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.5
Estimated peak memory usage (MB): [0, 29]
Total # Ops : 845
Compute Unit(s) : NPU (845 ops)
------------------------------------------------------------
SAMEncoderPart1
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 209.0
Estimated peak memory usage (MB): [12, 69]
Total # Ops : 585
Compute Unit(s) : NPU (585 ops)
------------------------------------------------------------
SAMEncoderPart2
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 655.0
Estimated peak memory usage (MB): [12, 110]
Total # Ops : 573
Compute Unit(s) : NPU (573 ops)
------------------------------------------------------------
SAMEncoderPart3
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 659.7
Estimated peak memory usage (MB): [12, 114]
Total # Ops : 573
Compute Unit(s) : NPU (573 ops)
------------------------------------------------------------
SAMEncoderPart4
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 660.4
Estimated peak memory usage (MB): [12, 103]
Total # Ops : 573
Compute Unit(s) : NPU (573 ops)
------------------------------------------------------------
SAMEncoderPart5
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 664.9
Estimated peak memory usage (MB): [12, 102]
Total # Ops : 573
Compute Unit(s) : NPU (573 ops)
------------------------------------------------------------
SAMEncoderPart6
Device : Samsung Galaxy S23 (13)
Runtime : TFLITE
Estimated inference time (ms) : 655.2
Estimated peak memory usage (MB): [12, 108]
Total # Ops : 573
Compute Unit(s) : NPU (573 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.