shreyajn commited on
Commit
440604d
1 Parent(s): b060569

Upload README.md with huggingface_hub

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