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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: pytorch
|
| 3 |
+
license: mit
|
| 4 |
+
tags:
|
| 5 |
+
- real_time
|
| 6 |
+
- android
|
| 7 |
+
pipeline_tag: audio-classification
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+

|
| 12 |
+
|
| 13 |
+
# YamNet: Optimized for Mobile Deployment
|
| 14 |
+
## Audio Event classification Model
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
An audio event classifier trained on the AudioSet dataset to predict audio events from the AudioSet ontology employing the Mobilenet_v1 depthwise-separable convolution architecture.
|
| 18 |
+
|
| 19 |
+
This model is an implementation of YamNet found [here](https://github.com/w-hc/torch_audioset).
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
This repository provides scripts to run YamNet on Qualcomm® devices.
|
| 23 |
+
More details on model performance across various devices, can be found
|
| 24 |
+
[here](https://aihub.qualcomm.com/models/yamnet).
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
### Model Details
|
| 28 |
+
|
| 29 |
+
- **Model Type:** Audio classification
|
| 30 |
+
- **Model Stats:**
|
| 31 |
+
- Model checkpoint: yamnet.pth
|
| 32 |
+
- Input resolution: 1x1x96x64
|
| 33 |
+
- Number of parameters: 3.73M
|
| 34 |
+
- Model size: 14.2 MB
|
| 35 |
+
|
| 36 |
+
| Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
|
| 37 |
+
|---|---|---|---|---|---|---|---|---|
|
| 38 |
+
| YamNet | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 0.223 ms | 0 - 64 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 39 |
+
| YamNet | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 0.216 ms | 0 - 2 MB | FP16 | NPU | [YamNet.so](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.so) |
|
| 40 |
+
| YamNet | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 0.311 ms | 0 - 39 MB | FP16 | NPU | [YamNet.onnx](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.onnx) |
|
| 41 |
+
| YamNet | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 0.181 ms | 0 - 30 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 42 |
+
| YamNet | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 0.177 ms | 0 - 18 MB | FP16 | NPU | [YamNet.so](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.so) |
|
| 43 |
+
| YamNet | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 0.24 ms | 0 - 23 MB | FP16 | NPU | [YamNet.onnx](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.onnx) |
|
| 44 |
+
| YamNet | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 0.158 ms | 0 - 23 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 45 |
+
| YamNet | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 0.159 ms | 0 - 18 MB | FP16 | NPU | Use Export Script |
|
| 46 |
+
| YamNet | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 0.256 ms | 0 - 14 MB | FP16 | NPU | [YamNet.onnx](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.onnx) |
|
| 47 |
+
| YamNet | SA7255P ADP | SA7255P | TFLITE | 2.966 ms | 0 - 19 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 48 |
+
| YamNet | SA7255P ADP | SA7255P | QNN | 2.918 ms | 0 - 9 MB | FP16 | NPU | Use Export Script |
|
| 49 |
+
| YamNet | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 0.224 ms | 0 - 64 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 50 |
+
| YamNet | SA8255 (Proxy) | SA8255P Proxy | QNN | 0.212 ms | 0 - 3 MB | FP16 | NPU | Use Export Script |
|
| 51 |
+
| YamNet | SA8295P ADP | SA8295P | TFLITE | 0.569 ms | 0 - 22 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 52 |
+
| YamNet | SA8295P ADP | SA8295P | QNN | 0.558 ms | 0 - 17 MB | FP16 | NPU | Use Export Script |
|
| 53 |
+
| YamNet | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 0.224 ms | 0 - 64 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 54 |
+
| YamNet | SA8650 (Proxy) | SA8650P Proxy | QNN | 0.223 ms | 0 - 2 MB | FP16 | NPU | Use Export Script |
|
| 55 |
+
| YamNet | SA8775P ADP | SA8775P | TFLITE | 0.428 ms | 0 - 19 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 56 |
+
| YamNet | SA8775P ADP | SA8775P | QNN | 0.401 ms | 0 - 10 MB | FP16 | NPU | Use Export Script |
|
| 57 |
+
| YamNet | QCS8275 (Proxy) | QCS8275 Proxy | TFLITE | 2.966 ms | 0 - 19 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 58 |
+
| YamNet | QCS8275 (Proxy) | QCS8275 Proxy | QNN | 2.918 ms | 0 - 9 MB | FP16 | NPU | Use Export Script |
|
| 59 |
+
| YamNet | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 0.227 ms | 0 - 64 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 60 |
+
| YamNet | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 0.216 ms | 0 - 3 MB | FP16 | NPU | Use Export Script |
|
| 61 |
+
| YamNet | QCS9075 (Proxy) | QCS9075 Proxy | TFLITE | 0.428 ms | 0 - 19 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 62 |
+
| YamNet | QCS9075 (Proxy) | QCS9075 Proxy | QNN | 0.401 ms | 0 - 10 MB | FP16 | NPU | Use Export Script |
|
| 63 |
+
| YamNet | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 0.396 ms | 0 - 29 MB | FP16 | NPU | [YamNet.tflite](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.tflite) |
|
| 64 |
+
| YamNet | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 0.396 ms | 0 - 27 MB | FP16 | NPU | Use Export Script |
|
| 65 |
+
| YamNet | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 0.267 ms | 1 - 1 MB | FP16 | NPU | Use Export Script |
|
| 66 |
+
| YamNet | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 0.258 ms | 8 - 8 MB | FP16 | NPU | [YamNet.onnx](https://huggingface.co/qualcomm/YamNet/blob/main/YamNet.onnx) |
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
## Installation
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
Install the package via pip:
|
| 75 |
+
```bash
|
| 76 |
+
pip install "qai-hub-models[yamnet]"
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
|
| 81 |
+
|
| 82 |
+
Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
|
| 83 |
+
Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
|
| 84 |
+
|
| 85 |
+
With this API token, you can configure your client to run models on the cloud
|
| 86 |
+
hosted devices.
|
| 87 |
+
```bash
|
| 88 |
+
qai-hub configure --api_token API_TOKEN
|
| 89 |
+
```
|
| 90 |
+
Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
## Demo off target
|
| 95 |
+
|
| 96 |
+
The package contains a simple end-to-end demo that downloads pre-trained
|
| 97 |
+
weights and runs this model on a sample input.
|
| 98 |
+
|
| 99 |
+
```bash
|
| 100 |
+
python -m qai_hub_models.models.yamnet.demo
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
The above demo runs a reference implementation of pre-processing, model
|
| 104 |
+
inference, and post processing.
|
| 105 |
+
|
| 106 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
| 107 |
+
environment, please add the following to your cell (instead of the above).
|
| 108 |
+
```
|
| 109 |
+
%run -m qai_hub_models.models.yamnet.demo
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
### Run model on a cloud-hosted device
|
| 114 |
+
|
| 115 |
+
In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
|
| 116 |
+
device. This script does the following:
|
| 117 |
+
* Performance check on-device on a cloud-hosted device
|
| 118 |
+
* Downloads compiled assets that can be deployed on-device for Android.
|
| 119 |
+
* Accuracy check between PyTorch and on-device outputs.
|
| 120 |
+
|
| 121 |
+
```bash
|
| 122 |
+
python -m qai_hub_models.models.yamnet.export
|
| 123 |
+
```
|
| 124 |
+
```
|
| 125 |
+
Profiling Results
|
| 126 |
+
------------------------------------------------------------
|
| 127 |
+
YamNet
|
| 128 |
+
Device : Samsung Galaxy S23 (13)
|
| 129 |
+
Runtime : TFLITE
|
| 130 |
+
Estimated inference time (ms) : 0.2
|
| 131 |
+
Estimated peak memory usage (MB): [0, 64]
|
| 132 |
+
Total # Ops : 31
|
| 133 |
+
Compute Unit(s) : NPU (31 ops)
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
## How does this work?
|
| 138 |
+
|
| 139 |
+
This [export script](https://aihub.qualcomm.com/models/yamnet/qai_hub_models/models/YamNet/export.py)
|
| 140 |
+
leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
|
| 141 |
+
on-device. Lets go through each step below in detail:
|
| 142 |
+
|
| 143 |
+
Step 1: **Compile model for on-device deployment**
|
| 144 |
+
|
| 145 |
+
To compile a PyTorch model for on-device deployment, we first trace the model
|
| 146 |
+
in memory using the `jit.trace` and then call the `submit_compile_job` API.
|
| 147 |
+
|
| 148 |
+
```python
|
| 149 |
+
import torch
|
| 150 |
+
|
| 151 |
+
import qai_hub as hub
|
| 152 |
+
from qai_hub_models.models.yamnet import Model
|
| 153 |
+
|
| 154 |
+
# Load the model
|
| 155 |
+
torch_model = Model.from_pretrained()
|
| 156 |
+
|
| 157 |
+
# Device
|
| 158 |
+
device = hub.Device("Samsung Galaxy S24")
|
| 159 |
+
|
| 160 |
+
# Trace model
|
| 161 |
+
input_shape = torch_model.get_input_spec()
|
| 162 |
+
sample_inputs = torch_model.sample_inputs()
|
| 163 |
+
|
| 164 |
+
pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
|
| 165 |
+
|
| 166 |
+
# Compile model on a specific device
|
| 167 |
+
compile_job = hub.submit_compile_job(
|
| 168 |
+
model=pt_model,
|
| 169 |
+
device=device,
|
| 170 |
+
input_specs=torch_model.get_input_spec(),
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
# Get target model to run on-device
|
| 174 |
+
target_model = compile_job.get_target_model()
|
| 175 |
+
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
Step 2: **Performance profiling on cloud-hosted device**
|
| 180 |
+
|
| 181 |
+
After compiling models from step 1. Models can be profiled model on-device using the
|
| 182 |
+
`target_model`. Note that this scripts runs the model on a device automatically
|
| 183 |
+
provisioned in the cloud. Once the job is submitted, you can navigate to a
|
| 184 |
+
provided job URL to view a variety of on-device performance metrics.
|
| 185 |
+
```python
|
| 186 |
+
profile_job = hub.submit_profile_job(
|
| 187 |
+
model=target_model,
|
| 188 |
+
device=device,
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
Step 3: **Verify on-device accuracy**
|
| 194 |
+
|
| 195 |
+
To verify the accuracy of the model on-device, you can run on-device inference
|
| 196 |
+
on sample input data on the same cloud hosted device.
|
| 197 |
+
```python
|
| 198 |
+
input_data = torch_model.sample_inputs()
|
| 199 |
+
inference_job = hub.submit_inference_job(
|
| 200 |
+
model=target_model,
|
| 201 |
+
device=device,
|
| 202 |
+
inputs=input_data,
|
| 203 |
+
)
|
| 204 |
+
on_device_output = inference_job.download_output_data()
|
| 205 |
+
|
| 206 |
+
```
|
| 207 |
+
With the output of the model, you can compute like PSNR, relative errors or
|
| 208 |
+
spot check the output with expected output.
|
| 209 |
+
|
| 210 |
+
**Note**: This on-device profiling and inference requires access to Qualcomm®
|
| 211 |
+
AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
## Run demo on a cloud-hosted device
|
| 216 |
+
|
| 217 |
+
You can also run the demo on-device.
|
| 218 |
+
|
| 219 |
+
```bash
|
| 220 |
+
python -m qai_hub_models.models.yamnet.demo --on-device
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
| 224 |
+
environment, please add the following to your cell (instead of the above).
|
| 225 |
+
```
|
| 226 |
+
%run -m qai_hub_models.models.yamnet.demo -- --on-device
|
| 227 |
+
```
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
## Deploying compiled model to Android
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
The models can be deployed using multiple runtimes:
|
| 234 |
+
- TensorFlow Lite (`.tflite` export): [This
|
| 235 |
+
tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
|
| 236 |
+
guide to deploy the .tflite model in an Android application.
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
- QNN (`.so` export ): This [sample
|
| 240 |
+
app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
|
| 241 |
+
provides instructions on how to use the `.so` shared library in an Android application.
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
## View on Qualcomm® AI Hub
|
| 245 |
+
Get more details on YamNet's performance across various devices [here](https://aihub.qualcomm.com/models/yamnet).
|
| 246 |
+
Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
## License
|
| 250 |
+
* The license for the original implementation of YamNet can be found
|
| 251 |
+
[here](https://github.com/w-hc/torch_audioset/blob/master/LICENSE).
|
| 252 |
+
* 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)
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
## References
|
| 257 |
+
* [MobileNets Efficient Convolutional Neural Networks for Mobile Vision Applications](https://arxiv.org/abs/1704.04861)
|
| 258 |
+
* [Source Model Implementation](https://github.com/w-hc/torch_audioset)
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
## Community
|
| 263 |
+
* Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
|
| 264 |
+
* For questions or feedback please [reach out to us](mailto:[email protected]).
|
| 265 |
+
|
| 266 |
+
|