shreyajn commited on
Commit
7a71928
1 Parent(s): 31afddb

Upload README.md with huggingface_hub

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