shreyajn commited on
Commit
77e42fb
1 Parent(s): 11522de

Upload README.md with huggingface_hub

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