shreyajn commited on
Commit
31c2b7b
1 Parent(s): 5d91ec1

Upload README.md with huggingface_hub

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