Image-to-Text
PyTorch
android
qaihm-bot commited on
Commit
d5c4233
·
verified ·
1 Parent(s): 85c074c

See https://github.com/quic/ai-hub-models/releases/v0.46.1 for changelog.

README.md CHANGED
@@ -9,259 +9,120 @@ pipeline_tag: image-to-text
9
 
10
  ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/trocr/web-assets/model_demo.png)
11
 
12
- # TrOCR: Optimized for Mobile Deployment
13
- ## Transformer based model for state-of-the-art optical character recognition (OCR) on both printed and handwritten text
14
-
15
 
16
  End-to-end text recognition approach with pre-trained image transformer and text transformer models for both image understanding and wordpiece-level text generation.
17
 
18
- This model is an implementation of TrOCR found [here](https://huggingface.co/microsoft/trocr-small-stage1).
19
-
20
-
21
- This repository provides scripts to run TrOCR on Qualcomm® devices.
22
- More details on model performance across various devices, can be found
23
- [here](https://aihub.qualcomm.com/models/trocr).
24
-
25
-
26
-
27
- ### Model Details
28
-
29
- - **Model Type:** Model_use_case.image_to_text
30
- - **Model Stats:**
31
- - Model checkpoint: trocr-small-stage1
32
- - Input resolution: 320x320
33
- - Number of parameters (TrOCRDecoder): 38.3M
34
- - Model size (TrOCRDecoder) (float): 146 MB
35
- - Number of parameters (TrOCREncoder): 23.0M
36
- - Model size (TrOCREncoder) (float): 87.8 MB
37
-
38
- | Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model
39
- |---|---|---|---|---|---|---|---|---|
40
- | TrOCRDecoder | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 4.155 ms | 0 - 222 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
41
- | TrOCRDecoder | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_DLC | 4.189 ms | 0 - 213 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
42
- | TrOCRDecoder | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 2.814 ms | 0 - 296 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
43
- | TrOCRDecoder | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN_DLC | 2.832 ms | 1 - 292 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
44
- | TrOCRDecoder | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 2.02 ms | 0 - 3 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
45
- | TrOCRDecoder | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_DLC | 1.927 ms | 2 - 4 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
46
- | TrOCRDecoder | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | ONNX | 2.499 ms | 1 - 4 MB | NPU | [TrOCR.onnx.zip](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.onnx.zip) |
47
- | TrOCRDecoder | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 2.881 ms | 0 - 219 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
48
- | TrOCRDecoder | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_DLC | 2.796 ms | 7 - 217 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
49
- | TrOCRDecoder | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 4.155 ms | 0 - 222 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
50
- | TrOCRDecoder | float | SA7255P ADP | Qualcomm® SA7255P | QNN_DLC | 4.189 ms | 0 - 213 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
51
- | TrOCRDecoder | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 2.817 ms | 0 - 207 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
52
- | TrOCRDecoder | float | SA8295P ADP | Qualcomm® SA8295P | QNN_DLC | 2.817 ms | 6 - 207 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
53
- | TrOCRDecoder | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 2.881 ms | 0 - 219 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
54
- | TrOCRDecoder | float | SA8775P ADP | Qualcomm® SA8775P | QNN_DLC | 2.796 ms | 7 - 217 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
55
- | TrOCRDecoder | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 1.407 ms | 0 - 319 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
56
- | TrOCRDecoder | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_DLC | 1.415 ms | 0 - 311 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
57
- | TrOCRDecoder | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 1.765 ms | 0 - 290 MB | NPU | [TrOCR.onnx.zip](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.onnx.zip) |
58
- | TrOCRDecoder | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | TFLITE | 1.157 ms | 0 - 303 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
59
- | TrOCRDecoder | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_DLC | 1.156 ms | 0 - 294 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
60
- | TrOCRDecoder | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | ONNX | 1.512 ms | 0 - 268 MB | NPU | [TrOCR.onnx.zip](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.onnx.zip) |
61
- | TrOCRDecoder | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | TFLITE | 1.099 ms | 0 - 282 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
62
- | TrOCRDecoder | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | QNN_DLC | 1.11 ms | 2 - 279 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
63
- | TrOCRDecoder | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | ONNX | 1.378 ms | 2 - 259 MB | NPU | [TrOCR.onnx.zip](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.onnx.zip) |
64
- | TrOCRDecoder | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_DLC | 2.174 ms | 7 - 7 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
65
- | TrOCRDecoder | float | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 2.265 ms | 68 - 68 MB | NPU | [TrOCR.onnx.zip](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.onnx.zip) |
66
- | TrOCREncoder | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 38.054 ms | 7 - 252 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
67
- | TrOCREncoder | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_DLC | 45.721 ms | 2 - 260 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
68
- | TrOCREncoder | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 21.572 ms | 7 - 349 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
69
- | TrOCREncoder | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN_DLC | 28.194 ms | 2 - 356 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
70
- | TrOCREncoder | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 12.106 ms | 7 - 9 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
71
- | TrOCREncoder | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_DLC | 16.659 ms | 2 - 4 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
72
- | TrOCREncoder | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | ONNX | 17.607 ms | 0 - 58 MB | NPU | [TrOCR.onnx.zip](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.onnx.zip) |
73
- | TrOCREncoder | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 14.633 ms | 7 - 252 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
74
- | TrOCREncoder | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_DLC | 19.802 ms | 2 - 263 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
75
- | TrOCREncoder | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 38.054 ms | 7 - 252 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
76
- | TrOCREncoder | float | SA7255P ADP | Qualcomm® SA7255P | QNN_DLC | 45.721 ms | 2 - 260 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
77
- | TrOCREncoder | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 20.681 ms | 5 - 256 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
78
- | TrOCREncoder | float | SA8295P ADP | Qualcomm® SA8295P | QNN_DLC | 25.815 ms | 2 - 262 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
79
- | TrOCREncoder | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 14.633 ms | 7 - 252 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
80
- | TrOCREncoder | float | SA8775P ADP | Qualcomm® SA8775P | QNN_DLC | 19.802 ms | 2 - 263 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
81
- | TrOCREncoder | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 8.523 ms | 6 - 343 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
82
- | TrOCREncoder | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_DLC | 11.519 ms | 2 - 356 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
83
- | TrOCREncoder | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 11.547 ms | 16 - 390 MB | NPU | [TrOCR.onnx.zip](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.onnx.zip) |
84
- | TrOCREncoder | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | TFLITE | 5.789 ms | 6 - 253 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
85
- | TrOCREncoder | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_DLC | 9.302 ms | 2 - 287 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
86
- | TrOCREncoder | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | ONNX | 10.061 ms | 16 - 279 MB | NPU | [TrOCR.onnx.zip](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.onnx.zip) |
87
- | TrOCREncoder | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | TFLITE | 4.642 ms | 0 - 250 MB | NPU | [TrOCR.tflite](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.tflite) |
88
- | TrOCREncoder | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | QNN_DLC | 6.944 ms | 2 - 265 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
89
- | TrOCREncoder | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen 5 Mobile | ONNX | 7.25 ms | 16 - 259 MB | NPU | [TrOCR.onnx.zip](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.onnx.zip) |
90
- | TrOCREncoder | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_DLC | 17.633 ms | 2 - 2 MB | NPU | [TrOCR.dlc](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.dlc) |
91
- | TrOCREncoder | float | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 17.988 ms | 48 - 48 MB | NPU | [TrOCR.onnx.zip](https://huggingface.co/qualcomm/TrOCR/blob/main/TrOCR.onnx.zip) |
92
-
93
-
94
-
95
-
96
- ## Installation
97
-
98
-
99
- Install the package via pip:
100
- ```bash
101
- # NOTE: 3.10 <= PYTHON_VERSION < 3.14 is supported.
102
- pip install "qai-hub-models[trocr]"
103
- ```
104
-
105
-
106
- ## Configure Qualcomm® AI Hub Workbench to run this model on a cloud-hosted device
107
-
108
- Sign-in to [Qualcomm® AI Hub Workbench](https://workbench.aihub.qualcomm.com/) with your
109
- Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
110
-
111
- With this API token, you can configure your client to run models on the cloud
112
- hosted devices.
113
- ```bash
114
- qai-hub configure --api_token API_TOKEN
115
- ```
116
- Navigate to [docs](https://workbench.aihub.qualcomm.com/docs/) for more information.
117
-
118
-
119
-
120
- ## Demo off target
121
-
122
- The package contains a simple end-to-end demo that downloads pre-trained
123
- weights and runs this model on a sample input.
124
-
125
- ```bash
126
- python -m qai_hub_models.models.trocr.demo
127
- ```
128
-
129
- The above demo runs a reference implementation of pre-processing, model
130
- inference, and post processing.
131
-
132
- **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
133
- environment, please add the following to your cell (instead of the above).
134
- ```
135
- %run -m qai_hub_models.models.trocr.demo
136
- ```
137
-
138
-
139
- ### Run model on a cloud-hosted device
140
-
141
- In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
142
- device. This script does the following:
143
- * Performance check on-device on a cloud-hosted device
144
- * Downloads compiled assets that can be deployed on-device for Android.
145
- * Accuracy check between PyTorch and on-device outputs.
146
-
147
- ```bash
148
- python -m qai_hub_models.models.trocr.export
149
- ```
150
-
151
-
152
-
153
- ## How does this work?
154
-
155
- This [export script](https://aihub.qualcomm.com/models/trocr/qai_hub_models/models/TrOCR/export.py)
156
- leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
157
- on-device. Lets go through each step below in detail:
158
-
159
- Step 1: **Compile model for on-device deployment**
160
-
161
- To compile a PyTorch model for on-device deployment, we first trace the model
162
- in memory using the `jit.trace` and then call the `submit_compile_job` API.
163
-
164
- ```python
165
- import torch
166
-
167
- import qai_hub as hub
168
- from qai_hub_models.models.trocr import Model
169
-
170
- # Load the model
171
- torch_model = Model.from_pretrained()
172
-
173
- # Device
174
- device = hub.Device("Samsung Galaxy S25")
175
-
176
- # Trace model
177
- input_shape = torch_model.get_input_spec()
178
- sample_inputs = torch_model.sample_inputs()
179
-
180
- pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
181
-
182
- # Compile model on a specific device
183
- compile_job = hub.submit_compile_job(
184
- model=pt_model,
185
- device=device,
186
- input_specs=torch_model.get_input_spec(),
187
- )
188
-
189
- # Get target model to run on-device
190
- target_model = compile_job.get_target_model()
191
-
192
- ```
193
-
194
-
195
- Step 2: **Performance profiling on cloud-hosted device**
196
-
197
- After compiling models from step 1. Models can be profiled model on-device using the
198
- `target_model`. Note that this scripts runs the model on a device automatically
199
- provisioned in the cloud. Once the job is submitted, you can navigate to a
200
- provided job URL to view a variety of on-device performance metrics.
201
- ```python
202
- profile_job = hub.submit_profile_job(
203
- model=target_model,
204
- device=device,
205
- )
206
-
207
- ```
208
-
209
- Step 3: **Verify on-device accuracy**
210
-
211
- To verify the accuracy of the model on-device, you can run on-device inference
212
- on sample input data on the same cloud hosted device.
213
- ```python
214
- input_data = torch_model.sample_inputs()
215
- inference_job = hub.submit_inference_job(
216
- model=target_model,
217
- device=device,
218
- inputs=input_data,
219
- )
220
- on_device_output = inference_job.download_output_data()
221
-
222
- ```
223
- With the output of the model, you can compute like PSNR, relative errors or
224
- spot check the output with expected output.
225
-
226
- **Note**: This on-device profiling and inference requires access to Qualcomm®
227
- AI Hub Workbench. [Sign up for access](https://myaccount.qualcomm.com/signup).
228
-
229
-
230
-
231
-
232
- ## Deploying compiled model to Android
233
-
234
-
235
- The models can be deployed using multiple runtimes:
236
- - TensorFlow Lite (`.tflite` export): [This
237
- tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
238
- guide to deploy the .tflite model in an Android application.
239
-
240
-
241
- - QNN (`.so` export ): This [sample
242
- app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
243
- provides instructions on how to use the `.so` shared library in an Android application.
244
-
245
-
246
- ## View on Qualcomm® AI Hub
247
- Get more details on TrOCR's performance across various devices [here](https://aihub.qualcomm.com/models/trocr).
248
- Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
249
-
250
 
251
  ## License
252
  * The license for the original implementation of TrOCR can be found
253
  [here](https://github.com/microsoft/unilm/blob/master/LICENSE).
254
 
255
-
256
-
257
  ## References
258
  * [TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models](https://arxiv.org/abs/2109.10282)
259
  * [Source Model Implementation](https://huggingface.co/microsoft/trocr-small-stage1)
260
 
261
-
262
-
263
  ## Community
264
  * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
265
  * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
266
-
267
-
 
9
 
10
  ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/trocr/web-assets/model_demo.png)
11
 
12
+ # TrOCR: Optimized for Qualcomm Devices
 
 
13
 
14
  End-to-end text recognition approach with pre-trained image transformer and text transformer models for both image understanding and wordpiece-level text generation.
15
 
16
+ This is based on the implementation of TrOCR found [here](https://huggingface.co/microsoft/trocr-small-stage1).
17
+ This repository contains pre-exported model files optimized for Qualcomm® devices. You can use the [Qualcomm® AI Hub Models](https://github.com/quic/ai-hub-models/blob/main/qai_hub_models/models/trocr) library to export with custom configurations. More details on model performance across various devices, can be found [here](#performance-summary).
18
+
19
+ Qualcomm AI Hub Models uses [Qualcomm AI Hub Workbench](https://workbench.aihub.qualcomm.com) to compile, profile, and evaluate this model. [Sign up](https://myaccount.qualcomm.com/signup) to run these models on a hosted Qualcomm® device.
20
+
21
+ ## Getting Started
22
+ There are two ways to deploy this model on your device:
23
+
24
+ ### Option 1: Download Pre-Exported Models
25
+
26
+ Below are pre-exported model assets ready for deployment.
27
+
28
+ | Runtime | Precision | Chipset | SDK Versions | Download |
29
+ |---|---|---|---|---|
30
+ | ONNX | float | Universal | QAIRT 2.37, ONNX Runtime 1.23.0 | [Download](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/trocr/releases/v0.46.1/trocr-onnx-float.zip)
31
+ | QNN_DLC | float | Universal | QAIRT 2.42 | [Download](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/trocr/releases/v0.46.1/trocr-qnn_dlc-float.zip)
32
+ | TFLITE | float | Universal | QAIRT 2.42, TFLite 2.17.0 | [Download](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/trocr/releases/v0.46.1/trocr-tflite-float.zip)
33
+
34
+ For more device-specific assets and performance metrics, visit **[TrOCR on Qualcomm® AI Hub](https://aihub.qualcomm.com/models/trocr)**.
35
+
36
+
37
+ ### Option 2: Export with Custom Configurations
38
+
39
+ Use the [Qualcomm® AI Hub Models](https://github.com/quic/ai-hub-models/blob/main/qai_hub_models/models/trocr) Python library to compile and export the model with your own:
40
+ - Custom weights (e.g., fine-tuned checkpoints)
41
+ - Custom input shapes
42
+ - Target device and runtime configurations
43
+
44
+ This option is ideal if you need to customize the model beyond the default configuration provided here.
45
+
46
+ See our repository for [TrOCR on GitHub](https://github.com/quic/ai-hub-models/blob/main/qai_hub_models/models/trocr) for usage instructions.
47
+
48
+ ## Model Details
49
+
50
+ **Model Type:** Model_use_case.image_to_text
51
+
52
+ **Model Stats:**
53
+ - Model checkpoint: trocr-small-stage1
54
+ - Input resolution: 320x320
55
+ - Number of parameters (TrOCRDecoder): 38.3M
56
+ - Model size (TrOCRDecoder) (float): 146 MB
57
+ - Number of parameters (TrOCREncoder): 23.0M
58
+ - Model size (TrOCREncoder) (float): 87.8 MB
59
+
60
+ ## Performance Summary
61
+ | Model | Runtime | Precision | Chipset | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit
62
+ |---|---|---|---|---|---|---
63
+ | TrOCRDecoder | ONNX | float | Snapdragon® X Elite | 2.358 ms | 67 - 67 MB | NPU
64
+ | TrOCRDecoder | ONNX | float | Snapdragon® 8 Gen 3 Mobile | 1.842 ms | 0 - 287 MB | NPU
65
+ | TrOCRDecoder | ONNX | float | Qualcomm® QCS8550 (Proxy) | 2.51 ms | 0 - 350 MB | NPU
66
+ | TrOCRDecoder | ONNX | float | Qualcomm® QCS9075 | 2.962 ms | 7 - 17 MB | NPU
67
+ | TrOCRDecoder | ONNX | float | Snapdragon® 8 Elite For Galaxy Mobile | 1.587 ms | 0 - 271 MB | NPU
68
+ | TrOCRDecoder | ONNX | float | Snapdragon® 8 Elite Gen 5 Mobile | 1.424 ms | 0 - 258 MB | NPU
69
+ | TrOCRDecoder | QNN_DLC | float | Snapdragon® X Elite | 2.172 ms | 7 - 7 MB | NPU
70
+ | TrOCRDecoder | QNN_DLC | float | Snapdragon® 8 Gen 3 Mobile | 1.388 ms | 0 - 243 MB | NPU
71
+ | TrOCRDecoder | QNN_DLC | float | Qualcomm® QCS8275 (Proxy) | 4.138 ms | 7 - 148 MB | NPU
72
+ | TrOCRDecoder | QNN_DLC | float | Qualcomm® QCS8550 (Proxy) | 1.932 ms | 3 - 5 MB | NPU
73
+ | TrOCRDecoder | QNN_DLC | float | Qualcomm® SA8775P | 2.764 ms | 7 - 148 MB | NPU
74
+ | TrOCRDecoder | QNN_DLC | float | Qualcomm® QCS9075 | 2.54 ms | 7 - 15 MB | NPU
75
+ | TrOCRDecoder | QNN_DLC | float | Qualcomm® QCS8450 (Proxy) | 2.835 ms | 2 - 216 MB | NPU
76
+ | TrOCRDecoder | QNN_DLC | float | Qualcomm® SA7255P | 4.138 ms | 7 - 148 MB | NPU
77
+ | TrOCRDecoder | QNN_DLC | float | Qualcomm® SA8295P | 2.802 ms | 7 - 130 MB | NPU
78
+ | TrOCRDecoder | QNN_DLC | float | Snapdragon® 8 Elite For Galaxy Mobile | 1.208 ms | 0 - 227 MB | NPU
79
+ | TrOCRDecoder | QNN_DLC | float | Snapdragon® 8 Elite Gen 5 Mobile | 1.093 ms | 1 - 213 MB | NPU
80
+ | TrOCRDecoder | TFLITE | float | Snapdragon® 8 Gen 3 Mobile | 1.404 ms | 0 - 258 MB | NPU
81
+ | TrOCRDecoder | TFLITE | float | Qualcomm® QCS8275 (Proxy) | 4.162 ms | 0 - 160 MB | NPU
82
+ | TrOCRDecoder | TFLITE | float | Qualcomm® QCS8550 (Proxy) | 2.009 ms | 0 - 8 MB | NPU
83
+ | TrOCRDecoder | TFLITE | float | Qualcomm® SA8775P | 8.646 ms | 0 - 161 MB | NPU
84
+ | TrOCRDecoder | TFLITE | float | Qualcomm® QCS9075 | 2.547 ms | 0 - 83 MB | NPU
85
+ | TrOCRDecoder | TFLITE | float | Qualcomm® QCS8450 (Proxy) | 2.815 ms | 0 - 224 MB | NPU
86
+ | TrOCRDecoder | TFLITE | float | Qualcomm® SA7255P | 4.162 ms | 0 - 160 MB | NPU
87
+ | TrOCRDecoder | TFLITE | float | Qualcomm® SA8295P | 2.8 ms | 0 - 142 MB | NPU
88
+ | TrOCRDecoder | TFLITE | float | Snapdragon® 8 Elite For Galaxy Mobile | 1.166 ms | 0 - 235 MB | NPU
89
+ | TrOCRDecoder | TFLITE | float | Snapdragon® 8 Elite Gen 5 Mobile | 1.105 ms | 0 - 215 MB | NPU
90
+ | TrOCREncoder | ONNX | float | Snapdragon® X Elite | 18.045 ms | 48 - 48 MB | NPU
91
+ | TrOCREncoder | ONNX | float | Snapdragon® 8 Gen 3 Mobile | 11.593 ms | 14 - 389 MB | NPU
92
+ | TrOCREncoder | ONNX | float | Qualcomm® QCS8550 (Proxy) | 17.6 ms | 0 - 57 MB | NPU
93
+ | TrOCREncoder | ONNX | float | Qualcomm® QCS9075 | 21.826 ms | 15 - 19 MB | NPU
94
+ | TrOCREncoder | ONNX | float | Snapdragon® 8 Elite For Galaxy Mobile | 10.097 ms | 14 - 280 MB | NPU
95
+ | TrOCREncoder | ONNX | float | Snapdragon® 8 Elite Gen 5 Mobile | 7.252 ms | 1 - 245 MB | NPU
96
+ | TrOCREncoder | QNN_DLC | float | Snapdragon® X Elite | 18.938 ms | 2 - 2 MB | NPU
97
+ | TrOCREncoder | QNN_DLC | float | Snapdragon® 8 Gen 3 Mobile | 12.557 ms | 0 - 381 MB | NPU
98
+ | TrOCREncoder | QNN_DLC | float | Qualcomm® QCS8275 (Proxy) | 47.203 ms | 2 - 291 MB | NPU
99
+ | TrOCREncoder | QNN_DLC | float | Qualcomm® QCS8550 (Proxy) | 18.324 ms | 2 - 4 MB | NPU
100
+ | TrOCREncoder | QNN_DLC | float | Qualcomm® SA8775P | 20.83 ms | 2 - 292 MB | NPU
101
+ | TrOCREncoder | QNN_DLC | float | Qualcomm® QCS9075 | 22.183 ms | 2 - 12 MB | NPU
102
+ | TrOCREncoder | QNN_DLC | float | Qualcomm® QCS8450 (Proxy) | 28.527 ms | 0 - 360 MB | NPU
103
+ | TrOCREncoder | QNN_DLC | float | Qualcomm® SA7255P | 47.203 ms | 2 - 291 MB | NPU
104
+ | TrOCREncoder | QNN_DLC | float | Qualcomm® SA8295P | 26.372 ms | 2 - 291 MB | NPU
105
+ | TrOCREncoder | QNN_DLC | float | Snapdragon® 8 Elite For Galaxy Mobile | 8.827 ms | 2 - 312 MB | NPU
106
+ | TrOCREncoder | QNN_DLC | float | Snapdragon® 8 Elite Gen 5 Mobile | 7.254 ms | 2 - 303 MB | NPU
107
+ | TrOCREncoder | TFLITE | float | Snapdragon® 8 Gen 3 Mobile | 8.625 ms | 5 - 233 MB | NPU
108
+ | TrOCREncoder | TFLITE | float | Qualcomm® QCS8275 (Proxy) | 38.239 ms | 7 - 149 MB | NPU
109
+ | TrOCREncoder | TFLITE | float | Qualcomm® QCS8550 (Proxy) | 12.241 ms | 0 - 2 MB | NPU
110
+ | TrOCREncoder | TFLITE | float | Qualcomm® SA8775P | 14.713 ms | 7 - 161 MB | NPU
111
+ | TrOCREncoder | TFLITE | float | Qualcomm® QCS9075 | 15.775 ms | 6 - 66 MB | NPU
112
+ | TrOCREncoder | TFLITE | float | Qualcomm® QCS8450 (Proxy) | 22.075 ms | 7 - 348 MB | NPU
113
+ | TrOCREncoder | TFLITE | float | Qualcomm® SA7255P | 38.239 ms | 7 - 149 MB | NPU
114
+ | TrOCREncoder | TFLITE | float | Qualcomm® SA8295P | 20.792 ms | 7 - 286 MB | NPU
115
+ | TrOCREncoder | TFLITE | float | Snapdragon® 8 Elite For Galaxy Mobile | 5.851 ms | 6 - 151 MB | NPU
116
+ | TrOCREncoder | TFLITE | float | Snapdragon® 8 Elite Gen 5 Mobile | 4.58 ms | 6 - 212 MB | NPU
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
  ## License
119
  * The license for the original implementation of TrOCR can be found
120
  [here](https://github.com/microsoft/unilm/blob/master/LICENSE).
121
 
 
 
122
  ## References
123
  * [TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models](https://arxiv.org/abs/2109.10282)
124
  * [Source Model Implementation](https://huggingface.co/microsoft/trocr-small-stage1)
125
 
 
 
126
  ## Community
127
  * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
128
  * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
 
 
TrOCR_TrOCRDecoder_float.dlc DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:d48a713671e0f66ebad1722f2957105bb3c432eb37225af933b130599ae81a50
3
- size 153570124
 
 
 
 
TrOCR_TrOCRDecoder_float.onnx.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:50768d6c607f5b1e03be4e8b3869dd8e956c80e59c0797b93ec7718871b6e313
3
- size 95898938
 
 
 
 
TrOCR_TrOCRDecoder_float.tflite DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ab3c11fa287e5c12571860145f59d44c3a32c2cc82102aa87816ce78a4083551
3
- size 153358740
 
 
 
 
TrOCR_TrOCREncoder_float.dlc DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:7957580b509f53c025b9e6d463b20d40d9df268faa2666296e1a0c2c74e5054b
3
- size 92366908
 
 
 
 
TrOCR_TrOCREncoder_float.onnx.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:569104ca0a54f9d85b3cf9b540f93bbd29ac160d0005bf092d12142150e40096
3
- size 57594196
 
 
 
 
TrOCR_TrOCREncoder_float.tflite DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ec2b91b30886af5d150fcc5747365c6e7bd2367e34b3945e6489275211b8f317
3
- size 92088688
 
 
 
 
tool-versions.yaml DELETED
@@ -1,4 +0,0 @@
1
- tool_versions:
2
- onnx:
3
- qairt: 2.37.1.250807093845_124904
4
- onnx_runtime: 1.23.0