v0.31.0
Browse filesSee https://github.com/quic/ai-hub-models/releases/v0.31.0 for changelog.
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
Segment-Anything-Model-2_SAM2Decoder.dlc filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
Segment-Anything-Model-2_SAM2Encoder.dlc filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: pytorch
|
| 3 |
+
license: other
|
| 4 |
+
tags:
|
| 5 |
+
- foundation
|
| 6 |
+
- android
|
| 7 |
+
pipeline_tag: image-segmentation
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+

|
| 12 |
+
|
| 13 |
+
# Segment-Anything-Model-2: Optimized for Mobile Deployment
|
| 14 |
+
## High-quality segmentation in images and videos with real-time performance and minimal user interaction
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
SAM 2, the successor to Meta's Segment Anything Model (SAM), is a cutting-edge tool designed for comprehensive object segmentation in both images and videos. It excels in handling complex visual data through a unified, promptable model architecture that supports real-time processing and zero-shot generalization.
|
| 18 |
+
|
| 19 |
+
This model is an implementation of Segment-Anything-Model-2 found [here](https://github.com/facebookresearch/sam2).
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
This repository provides scripts to run Segment-Anything-Model-2 on Qualcomm® devices.
|
| 23 |
+
More details on model performance across various devices, can be found
|
| 24 |
+
[here](https://aihub.qualcomm.com/models/sam2).
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
### Model Details
|
| 28 |
+
|
| 29 |
+
- **Model Type:** Model_use_case.semantic_segmentation
|
| 30 |
+
- **Model Stats:**
|
| 31 |
+
- Model checkpoint: sam2.1_hiera_t
|
| 32 |
+
- Input resolution: 720p (720x1280)
|
| 33 |
+
- Number of parameters (SAM2Encoder): 33.5M
|
| 34 |
+
- Model size (SAM2Encoder): 128 MB
|
| 35 |
+
- Number of parameters (SAM2Decoder): 6.22M
|
| 36 |
+
- Model size (SAM2Decoder): 23.7 MB
|
| 37 |
+
|
| 38 |
+
| Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model
|
| 39 |
+
|---|---|---|---|---|---|---|---|---|
|
| 40 |
+
| SAM2Encoder | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 609.767 ms | 92 - 296 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 41 |
+
| SAM2Encoder | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 367.288 ms | 85 - 296 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 42 |
+
| SAM2Encoder | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN_DLC | 384.843 ms | 12 - 2403 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 43 |
+
| SAM2Encoder | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 252.662 ms | 92 - 117 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 44 |
+
| SAM2Encoder | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_DLC | 212.081 ms | 15 - 86 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 45 |
+
| SAM2Encoder | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 290.379 ms | 92 - 295 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 46 |
+
| SAM2Encoder | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 609.767 ms | 92 - 296 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 47 |
+
| SAM2Encoder | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | TFLITE | 259.454 ms | 92 - 117 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 48 |
+
| SAM2Encoder | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN_DLC | 214.113 ms | 12 - 93 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 49 |
+
| SAM2Encoder | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 380.286 ms | 92 - 307 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 50 |
+
| SAM2Encoder | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | TFLITE | 263.816 ms | 92 - 117 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 51 |
+
| SAM2Encoder | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN_DLC | 214.315 ms | 12 - 89 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 52 |
+
| SAM2Encoder | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 290.379 ms | 92 - 295 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 53 |
+
| SAM2Encoder | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | TFLITE | 265.703 ms | 92 - 115 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 54 |
+
| SAM2Encoder | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | QNN_DLC | 215.128 ms | 12 - 87 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 55 |
+
| SAM2Encoder | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 191.967 ms | 92 - 308 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 56 |
+
| SAM2Encoder | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | TFLITE | 178.194 ms | 90 - 298 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 57 |
+
| SAM2Encoder | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | QNN_DLC | 139.549 ms | 12 - 1333 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 58 |
+
| SAM2Encoder | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_DLC | 260.348 ms | 800 - 800 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 59 |
+
| SAM2Decoder | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 17.97 ms | 0 - 54 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 60 |
+
| SAM2Decoder | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 10.167 ms | 0 - 57 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 61 |
+
| SAM2Decoder | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN_DLC | 11.324 ms | 15 - 76 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 62 |
+
| SAM2Decoder | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 8.133 ms | 0 - 30 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 63 |
+
| SAM2Decoder | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_DLC | 6.962 ms | 16 - 35 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 64 |
+
| SAM2Decoder | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 9.556 ms | 0 - 55 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 65 |
+
| SAM2Decoder | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 17.97 ms | 0 - 54 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 66 |
+
| SAM2Decoder | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | TFLITE | 8.173 ms | 0 - 33 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 67 |
+
| SAM2Decoder | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN_DLC | 6.96 ms | 16 - 39 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 68 |
+
| SAM2Decoder | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 11.752 ms | 0 - 52 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 69 |
+
| SAM2Decoder | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | TFLITE | 8.166 ms | 0 - 32 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 70 |
+
| SAM2Decoder | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN_DLC | 6.987 ms | 16 - 37 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 71 |
+
| SAM2Decoder | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 9.556 ms | 0 - 55 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 72 |
+
| SAM2Decoder | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | TFLITE | 8.209 ms | 0 - 33 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 73 |
+
| SAM2Decoder | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | QNN_DLC | 6.982 ms | 15 - 38 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 74 |
+
| SAM2Decoder | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 5.59 ms | 0 - 65 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 75 |
+
| SAM2Decoder | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | TFLITE | 5.651 ms | 0 - 56 MB | NPU | [Segment-Anything-Model-2.tflite](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.tflite) |
|
| 76 |
+
| SAM2Decoder | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | QNN_DLC | 4.238 ms | 8 - 62 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 77 |
+
| SAM2Decoder | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_DLC | 7.652 ms | 16 - 16 MB | NPU | [Segment-Anything-Model-2.dlc](https://huggingface.co/qualcomm/Segment-Anything-Model-2/blob/main/Segment-Anything-Model-2.dlc) |
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
## Installation
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
Install the package via pip:
|
| 86 |
+
```bash
|
| 87 |
+
pip install "qai-hub-models[sam2]"
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
|
| 92 |
+
|
| 93 |
+
Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
|
| 94 |
+
Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
|
| 95 |
+
|
| 96 |
+
With this API token, you can configure your client to run models on the cloud
|
| 97 |
+
hosted devices.
|
| 98 |
+
```bash
|
| 99 |
+
qai-hub configure --api_token API_TOKEN
|
| 100 |
+
```
|
| 101 |
+
Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
## Demo off target
|
| 106 |
+
|
| 107 |
+
The package contains a simple end-to-end demo that downloads pre-trained
|
| 108 |
+
weights and runs this model on a sample input.
|
| 109 |
+
|
| 110 |
+
```bash
|
| 111 |
+
python -m qai_hub_models.models.sam2.demo
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
The above demo runs a reference implementation of pre-processing, model
|
| 115 |
+
inference, and post processing.
|
| 116 |
+
|
| 117 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
| 118 |
+
environment, please add the following to your cell (instead of the above).
|
| 119 |
+
```
|
| 120 |
+
%run -m qai_hub_models.models.sam2.demo
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
### Run model on a cloud-hosted device
|
| 125 |
+
|
| 126 |
+
In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
|
| 127 |
+
device. This script does the following:
|
| 128 |
+
* Performance check on-device on a cloud-hosted device
|
| 129 |
+
* Downloads compiled assets that can be deployed on-device for Android.
|
| 130 |
+
* Accuracy check between PyTorch and on-device outputs.
|
| 131 |
+
|
| 132 |
+
```bash
|
| 133 |
+
python -m qai_hub_models.models.sam2.export
|
| 134 |
+
```
|
| 135 |
+
```
|
| 136 |
+
Profiling Results
|
| 137 |
+
------------------------------------------------------------
|
| 138 |
+
SAM2Encoder
|
| 139 |
+
Device : cs_8275 (ANDROID 14)
|
| 140 |
+
Runtime : TFLITE
|
| 141 |
+
Estimated inference time (ms) : 609.8
|
| 142 |
+
Estimated peak memory usage (MB): [92, 296]
|
| 143 |
+
Total # Ops : 647
|
| 144 |
+
Compute Unit(s) : npu (593 ops) gpu (0 ops) cpu (54 ops)
|
| 145 |
+
|
| 146 |
+
------------------------------------------------------------
|
| 147 |
+
SAM2Decoder
|
| 148 |
+
Device : cs_8275 (ANDROID 14)
|
| 149 |
+
Runtime : TFLITE
|
| 150 |
+
Estimated inference time (ms) : 18.0
|
| 151 |
+
Estimated peak memory usage (MB): [0, 54]
|
| 152 |
+
Total # Ops : 889
|
| 153 |
+
Compute Unit(s) : npu (889 ops) gpu (0 ops) cpu (0 ops)
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
## How does this work?
|
| 158 |
+
|
| 159 |
+
This [export script](https://aihub.qualcomm.com/models/sam2/qai_hub_models/models/Segment-Anything-Model-2/export.py)
|
| 160 |
+
leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
|
| 161 |
+
on-device. Lets go through each step below in detail:
|
| 162 |
+
|
| 163 |
+
Step 1: **Compile model for on-device deployment**
|
| 164 |
+
|
| 165 |
+
To compile a PyTorch model for on-device deployment, we first trace the model
|
| 166 |
+
in memory using the `jit.trace` and then call the `submit_compile_job` API.
|
| 167 |
+
|
| 168 |
+
```python
|
| 169 |
+
import torch
|
| 170 |
+
|
| 171 |
+
import qai_hub as hub
|
| 172 |
+
from qai_hub_models.models.sam2 import Model
|
| 173 |
+
|
| 174 |
+
# Load the model
|
| 175 |
+
torch_model = Model.from_pretrained()
|
| 176 |
+
|
| 177 |
+
# Device
|
| 178 |
+
device = hub.Device("Samsung Galaxy S24")
|
| 179 |
+
|
| 180 |
+
# Trace model
|
| 181 |
+
input_shape = torch_model.get_input_spec()
|
| 182 |
+
sample_inputs = torch_model.sample_inputs()
|
| 183 |
+
|
| 184 |
+
pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
|
| 185 |
+
|
| 186 |
+
# Compile model on a specific device
|
| 187 |
+
compile_job = hub.submit_compile_job(
|
| 188 |
+
model=pt_model,
|
| 189 |
+
device=device,
|
| 190 |
+
input_specs=torch_model.get_input_spec(),
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
# Get target model to run on-device
|
| 194 |
+
target_model = compile_job.get_target_model()
|
| 195 |
+
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
Step 2: **Performance profiling on cloud-hosted device**
|
| 200 |
+
|
| 201 |
+
After compiling models from step 1. Models can be profiled model on-device using the
|
| 202 |
+
`target_model`. Note that this scripts runs the model on a device automatically
|
| 203 |
+
provisioned in the cloud. Once the job is submitted, you can navigate to a
|
| 204 |
+
provided job URL to view a variety of on-device performance metrics.
|
| 205 |
+
```python
|
| 206 |
+
profile_job = hub.submit_profile_job(
|
| 207 |
+
model=target_model,
|
| 208 |
+
device=device,
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
Step 3: **Verify on-device accuracy**
|
| 214 |
+
|
| 215 |
+
To verify the accuracy of the model on-device, you can run on-device inference
|
| 216 |
+
on sample input data on the same cloud hosted device.
|
| 217 |
+
```python
|
| 218 |
+
input_data = torch_model.sample_inputs()
|
| 219 |
+
inference_job = hub.submit_inference_job(
|
| 220 |
+
model=target_model,
|
| 221 |
+
device=device,
|
| 222 |
+
inputs=input_data,
|
| 223 |
+
)
|
| 224 |
+
on_device_output = inference_job.download_output_data()
|
| 225 |
+
|
| 226 |
+
```
|
| 227 |
+
With the output of the model, you can compute like PSNR, relative errors or
|
| 228 |
+
spot check the output with expected output.
|
| 229 |
+
|
| 230 |
+
**Note**: This on-device profiling and inference requires access to Qualcomm®
|
| 231 |
+
AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
## Run demo on a cloud-hosted device
|
| 236 |
+
|
| 237 |
+
You can also run the demo on-device.
|
| 238 |
+
|
| 239 |
+
```bash
|
| 240 |
+
python -m qai_hub_models.models.sam2.demo --eval-mode on-device
|
| 241 |
+
```
|
| 242 |
+
|
| 243 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
| 244 |
+
environment, please add the following to your cell (instead of the above).
|
| 245 |
+
```
|
| 246 |
+
%run -m qai_hub_models.models.sam2.demo -- --eval-mode on-device
|
| 247 |
+
```
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
## Deploying compiled model to Android
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
The models can be deployed using multiple runtimes:
|
| 254 |
+
- TensorFlow Lite (`.tflite` export): [This
|
| 255 |
+
tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
|
| 256 |
+
guide to deploy the .tflite model in an Android application.
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
- QNN (`.so` export ): This [sample
|
| 260 |
+
app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
|
| 261 |
+
provides instructions on how to use the `.so` shared library in an Android application.
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
## View on Qualcomm® AI Hub
|
| 265 |
+
Get more details on Segment-Anything-Model-2's performance across various devices [here](https://aihub.qualcomm.com/models/sam2).
|
| 266 |
+
Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
## License
|
| 270 |
+
* The license for the original implementation of Segment-Anything-Model-2 can be found
|
| 271 |
+
[here](https://github.com/facebookresearch/sam2/blob/main/LICENSE).
|
| 272 |
+
* The license for the compiled assets for on-device deployment can be found [here](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/Qualcomm+AI+Hub+Proprietary+License.pdf)
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
## References
|
| 277 |
+
* [SAM 2 Segment Anything in Images and Videos](https://arxiv.org/abs/2408.00714)
|
| 278 |
+
* [Source Model Implementation](https://github.com/facebookresearch/sam2)
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
## Community
|
| 283 |
+
* Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
|
| 284 |
+
* For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
|
| 285 |
+
|
| 286 |
+
|
Segment-Anything-Model-2_SAM2Decoder.dlc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6627a24f888aa8215154652eec310890dba83361be619ccfc973a04d6680be8f
|
| 3 |
+
size 25337779
|
Segment-Anything-Model-2_SAM2Decoder.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:36b8af9046e6cfd5f3a004e3810f57caf8b14899d67b77ca12d81762f07c1729
|
| 3 |
+
size 24878352
|
Segment-Anything-Model-2_SAM2Encoder.dlc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:781f5e13b85c2372a386f0daef8aadf0544c8cde19acf87f98456382c5b21756
|
| 3 |
+
size 134437963
|
Segment-Anything-Model-2_SAM2Encoder.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:328be9ab2563d70bc417240b5e5c5d86b716047fbccc9662184529a3eb0487bd
|
| 3 |
+
size 134225260
|