qaihm-bot commited on
Commit
2a513cb
·
verified ·
1 Parent(s): 5f87efd

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +233 -0
README.md ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - imagenet-1k
4
+ - imagenet-22k
5
+ library_name: pytorch
6
+ license: bsd-3-clause
7
+ pipeline_tag: image-classification
8
+ tags:
9
+ - backbone
10
+ - quantized
11
+ - android
12
+
13
+ ---
14
+
15
+ ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/densenet121_quantized/web-assets/model_demo.png)
16
+
17
+ # DenseNet-121-Quantized: Optimized for Mobile Deployment
18
+ ## Imagenet classifier and general purpose backbone
19
+
20
+ Densenet is a machine learning model that can classify images from the Imagenet dataset. It can also be used as a backbone in building more complex models for specific use cases.
21
+
22
+ This model is an implementation of DenseNet-121-Quantized found [here]({source_repo}).
23
+ This repository provides scripts to run DenseNet-121-Quantized on Qualcomm® devices.
24
+ More details on model performance across various devices, can be found
25
+ [here](https://aihub.qualcomm.com/models/densenet121_quantized).
26
+
27
+
28
+ ### Model Details
29
+
30
+ - **Model Type:** Image classification
31
+ - **Model Stats:**
32
+ - Model checkpoint: Imagenet
33
+ - Input resolution: 224x224
34
+ - Number of parameters: 7.97M
35
+ - Model size: 9.4 MB
36
+
37
+ | Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
38
+ |---|---|---|---|---|---|---|---|---|
39
+ | DenseNet-121-Quantized | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 1.745 ms | 0 - 272 MB | INT8 | NPU | [DenseNet-121-Quantized.so](https://huggingface.co/qualcomm/DenseNet-121-Quantized/blob/main/DenseNet-121-Quantized.so) |
40
+ | DenseNet-121-Quantized | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 29.847 ms | 8 - 12 MB | INT8 | NPU | [DenseNet-121-Quantized.onnx](https://huggingface.co/qualcomm/DenseNet-121-Quantized/blob/main/DenseNet-121-Quantized.onnx) |
41
+ | DenseNet-121-Quantized | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 1.218 ms | 0 - 22 MB | INT8 | NPU | [DenseNet-121-Quantized.so](https://huggingface.co/qualcomm/DenseNet-121-Quantized/blob/main/DenseNet-121-Quantized.so) |
42
+ | DenseNet-121-Quantized | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 22.391 ms | 9 - 1018 MB | INT8 | NPU | [DenseNet-121-Quantized.onnx](https://huggingface.co/qualcomm/DenseNet-121-Quantized/blob/main/DenseNet-121-Quantized.onnx) |
43
+ | DenseNet-121-Quantized | RB3 Gen 2 (Proxy) | QCS6490 Proxy | QNN | 6.521 ms | 0 - 8 MB | INT8 | NPU | Use Export Script |
44
+ | DenseNet-121-Quantized | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 1.672 ms | 0 - 1 MB | INT8 | NPU | Use Export Script |
45
+ | DenseNet-121-Quantized | SA8255 (Proxy) | SA8255P Proxy | QNN | 1.67 ms | 0 - 1 MB | INT8 | NPU | Use Export Script |
46
+ | DenseNet-121-Quantized | SA8775 (Proxy) | SA8775P Proxy | QNN | 1.684 ms | 0 - 1 MB | INT8 | NPU | Use Export Script |
47
+ | DenseNet-121-Quantized | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 2.13 ms | 0 - 27 MB | INT8 | NPU | Use Export Script |
48
+ | DenseNet-121-Quantized | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 1.16 ms | 0 - 26 MB | INT8 | NPU | Use Export Script |
49
+ | DenseNet-121-Quantized | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 1.822 ms | 0 - 0 MB | INT8 | NPU | Use Export Script |
50
+ | DenseNet-121-Quantized | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 32.525 ms | 46 - 46 MB | INT8 | NPU | [DenseNet-121-Quantized.onnx](https://huggingface.co/qualcomm/DenseNet-121-Quantized/blob/main/DenseNet-121-Quantized.onnx) |
51
+
52
+
53
+
54
+
55
+ ## Installation
56
+
57
+ This model can be installed as a Python package via pip.
58
+
59
+ ```bash
60
+ pip install qai-hub-models
61
+ ```
62
+
63
+
64
+ ## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
65
+
66
+ Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
67
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
68
+
69
+ With this API token, you can configure your client to run models on the cloud
70
+ hosted devices.
71
+ ```bash
72
+ qai-hub configure --api_token API_TOKEN
73
+ ```
74
+ Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
75
+
76
+
77
+
78
+ ## Demo off target
79
+
80
+ The package contains a simple end-to-end demo that downloads pre-trained
81
+ weights and runs this model on a sample input.
82
+
83
+ ```bash
84
+ python -m qai_hub_models.models.densenet121_quantized.demo
85
+ ```
86
+
87
+ The above demo runs a reference implementation of pre-processing, model
88
+ inference, and post processing.
89
+
90
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
91
+ environment, please add the following to your cell (instead of the above).
92
+ ```
93
+ %run -m qai_hub_models.models.densenet121_quantized.demo
94
+ ```
95
+
96
+
97
+ ### Run model on a cloud-hosted device
98
+
99
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
100
+ device. This script does the following:
101
+ * Performance check on-device on a cloud-hosted device
102
+ * Downloads compiled assets that can be deployed on-device for Android.
103
+ * Accuracy check between PyTorch and on-device outputs.
104
+
105
+ ```bash
106
+ python -m qai_hub_models.models.densenet121_quantized.export
107
+ ```
108
+ ```
109
+ Profiling Results
110
+ ------------------------------------------------------------
111
+ DenseNet-121-Quantized
112
+ Device : Samsung Galaxy S23 (13)
113
+ Runtime : QNN
114
+ Estimated inference time (ms) : 1.7
115
+ Estimated peak memory usage (MB): [0, 272]
116
+ Total # Ops : 215
117
+ Compute Unit(s) : NPU (215 ops)
118
+ ```
119
+
120
+
121
+ ## How does this work?
122
+
123
+ This [export script](https://aihub.qualcomm.com/models/densenet121_quantized/qai_hub_models/models/DenseNet-121-Quantized/export.py)
124
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
125
+ on-device. Lets go through each step below in detail:
126
+
127
+ Step 1: **Compile model for on-device deployment**
128
+
129
+ To compile a PyTorch model for on-device deployment, we first trace the model
130
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
131
+
132
+ ```python
133
+ import torch
134
+
135
+ import qai_hub as hub
136
+ from qai_hub_models.models.densenet121_quantized import
137
+
138
+ # Load the model
139
+
140
+ # Device
141
+ device = hub.Device("Samsung Galaxy S23")
142
+
143
+
144
+ ```
145
+
146
+
147
+ Step 2: **Performance profiling on cloud-hosted device**
148
+
149
+ After compiling models from step 1. Models can be profiled model on-device using the
150
+ `target_model`. Note that this scripts runs the model on a device automatically
151
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
152
+ provided job URL to view a variety of on-device performance metrics.
153
+ ```python
154
+ profile_job = hub.submit_profile_job(
155
+ model=target_model,
156
+ device=device,
157
+ )
158
+
159
+ ```
160
+
161
+ Step 3: **Verify on-device accuracy**
162
+
163
+ To verify the accuracy of the model on-device, you can run on-device inference
164
+ on sample input data on the same cloud hosted device.
165
+ ```python
166
+ input_data = torch_model.sample_inputs()
167
+ inference_job = hub.submit_inference_job(
168
+ model=target_model,
169
+ device=device,
170
+ inputs=input_data,
171
+ )
172
+ on_device_output = inference_job.download_output_data()
173
+
174
+ ```
175
+ With the output of the model, you can compute like PSNR, relative errors or
176
+ spot check the output with expected output.
177
+
178
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
179
+ AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
180
+
181
+
182
+
183
+ ## Run demo on a cloud-hosted device
184
+
185
+ You can also run the demo on-device.
186
+
187
+ ```bash
188
+ python -m qai_hub_models.models.densenet121_quantized.demo --on-device
189
+ ```
190
+
191
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
192
+ environment, please add the following to your cell (instead of the above).
193
+ ```
194
+ %run -m qai_hub_models.models.densenet121_quantized.demo -- --on-device
195
+ ```
196
+
197
+
198
+ ## Deploying compiled model to Android
199
+
200
+
201
+ The models can be deployed using multiple runtimes:
202
+ - TensorFlow Lite (`.tflite` export): [This
203
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
204
+ guide to deploy the .tflite model in an Android application.
205
+
206
+
207
+ - QNN (`.so` export ): This [sample
208
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
209
+ provides instructions on how to use the `.so` shared library in an Android application.
210
+
211
+
212
+ ## View on Qualcomm® AI Hub
213
+ Get more details on DenseNet-121-Quantized's performance across various devices [here](https://aihub.qualcomm.com/models/densenet121_quantized).
214
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
215
+
216
+
217
+ ## License
218
+ * The license for the original implementation of DenseNet-121-Quantized can be found [here](https://github.com/pytorch/vision/blob/main/LICENSE).
219
+ * 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)
220
+
221
+
222
+
223
+ ## References
224
+ * [Densely Connected Convolutional Networks](https://arxiv.org/abs/1608.06993)
225
+ * [Source Model Implementation](https://github.com/pytorch/vision/blob/main/torchvision/models/densenet.py)
226
+
227
+
228
+
229
+ ## Community
230
+ * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
231
+ * For questions or feedback please [reach out to us](mailto:[email protected]).
232
+
233
+