--- library_name: pytorch license: other tags: - android pipeline_tag: image-to-text --- ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/trocr/web-assets/model_demo.png) # TrOCR: Optimized for Qualcomm Devices End-to-end text recognition approach with pre-trained image transformer and text transformer models for both image understanding and wordpiece-level text generation. This is based on the implementation of TrOCR found [here](https://huggingface.co/microsoft/trocr-small-stage1). This repository contains pre-exported model files optimized for Qualcomm® devices. You can use the [Qualcomm® AI Hub Models](https://github.com/qualcomm/ai-hub-models/blob/main/src/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). 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. ## Getting Started There are two ways to deploy this model on your device: ### Option 1: Download Pre-Exported Models Below are pre-exported model assets ready for deployment. | Runtime | Precision | Chipset | SDK Versions | Download | |---|---|---|---|---| | ONNX | float | Universal | QAIRT 2.42, ONNX Runtime 1.24.3 | [Download](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/trocr/releases/v0.51.0/trocr-onnx-float.zip) | QNN_DLC | float | Universal | QAIRT 2.45 | [Download](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/trocr/releases/v0.51.0/trocr-qnn_dlc-float.zip) | TFLITE | float | Universal | QAIRT 2.45 | [Download](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/trocr/releases/v0.51.0/trocr-tflite-float.zip) For more device-specific assets and performance metrics, visit **[TrOCR on Qualcomm® AI Hub](https://aihub.qualcomm.com/models/trocr)**. ### Option 2: Export with Custom Configurations Use the [Qualcomm® AI Hub Models](https://github.com/qualcomm/ai-hub-models/blob/main/src/qai_hub_models/models/trocr) Python library to compile and export the model with your own: - Custom weights (e.g., fine-tuned checkpoints) - Custom input shapes - Target device and runtime configurations This option is ideal if you need to customize the model beyond the default configuration provided here. See our repository for [TrOCR on GitHub](https://github.com/qualcomm/ai-hub-models/blob/main/src/qai_hub_models/models/trocr) for usage instructions. ## Model Details **Model Type:** Model_use_case.image_to_text **Model Stats:** - Model checkpoint: trocr-small-stage1 - Input resolution: 320x320 - Number of parameters (decoder): 38.3M - Model size (decoder) (float): 146 MB - Number of parameters (encoder): 23.0M - Model size (encoder) (float): 87.8 MB ## Performance Summary | Model | Runtime | Precision | Chipset | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit |---|---|---|---|---|---|--- | decoder | ONNX | float | Snapdragon® 8 Elite Gen 5 Mobile | 1.169 ms | 1 - 225 MB | NPU | decoder | ONNX | float | Snapdragon® X2 Elite | 1.162 ms | 68 - 68 MB | NPU | decoder | ONNX | float | Snapdragon® X Elite | 2.277 ms | 67 - 67 MB | NPU | decoder | ONNX | float | Snapdragon® 8 Gen 3 Mobile | 1.472 ms | 0 - 268 MB | NPU | decoder | ONNX | float | Qualcomm® QCS8550 (Proxy) | 2.132 ms | 0 - 87 MB | NPU | decoder | ONNX | float | Qualcomm® QCS9075 | 2.715 ms | 7 - 16 MB | NPU | decoder | ONNX | float | Snapdragon® 8 Elite For Galaxy Mobile | 1.245 ms | 0 - 215 MB | NPU | decoder | QNN_DLC | float | Snapdragon® 8 Elite Gen 5 Mobile | 1.132 ms | 1 - 173 MB | NPU | decoder | QNN_DLC | float | Snapdragon® X2 Elite | 1.667 ms | 7 - 7 MB | NPU | decoder | QNN_DLC | float | Snapdragon® X Elite | 2.177 ms | 7 - 7 MB | NPU | decoder | QNN_DLC | float | Snapdragon® 8 Gen 3 Mobile | 1.41 ms | 0 - 278 MB | NPU | decoder | QNN_DLC | float | Qualcomm® QCS8275 (Proxy) | 4.178 ms | 1 - 102 MB | NPU | decoder | QNN_DLC | float | Qualcomm® QCS8550 (Proxy) | 2.003 ms | 2 - 184 MB | NPU | decoder | QNN_DLC | float | Qualcomm® SA8775P | 2.94 ms | 0 - 102 MB | NPU | decoder | QNN_DLC | float | Qualcomm® QCS9075 | 2.557 ms | 7 - 15 MB | NPU | decoder | QNN_DLC | float | Qualcomm® QCS8450 (Proxy) | 2.62 ms | 2 - 215 MB | NPU | decoder | QNN_DLC | float | Qualcomm® SA7255P | 4.178 ms | 1 - 102 MB | NPU | decoder | QNN_DLC | float | Qualcomm® SA8295P | 2.661 ms | 0 - 44 MB | NPU | decoder | QNN_DLC | float | Snapdragon® 8 Elite For Galaxy Mobile | 1.262 ms | 0 - 189 MB | NPU | decoder | TFLITE | float | Snapdragon® 8 Elite Gen 5 Mobile | 1.124 ms | 0 - 175 MB | NPU | decoder | TFLITE | float | Snapdragon® 8 Gen 3 Mobile | 1.389 ms | 0 - 280 MB | NPU | decoder | TFLITE | float | Qualcomm® QCS8275 (Proxy) | 4.222 ms | 0 - 103 MB | NPU | decoder | TFLITE | float | Qualcomm® QCS8550 (Proxy) | 1.989 ms | 0 - 2 MB | NPU | decoder | TFLITE | float | Qualcomm® SA8775P | 2.865 ms | 0 - 102 MB | NPU | decoder | TFLITE | float | Qualcomm® QCS9075 | 2.575 ms | 0 - 83 MB | NPU | decoder | TFLITE | float | Qualcomm® QCS8450 (Proxy) | 2.431 ms | 0 - 217 MB | NPU | decoder | TFLITE | float | Qualcomm® SA7255P | 4.222 ms | 0 - 103 MB | NPU | decoder | TFLITE | float | Qualcomm® SA8295P | 2.67 ms | 0 - 37 MB | NPU | decoder | TFLITE | float | Snapdragon® 8 Elite For Galaxy Mobile | 1.254 ms | 0 - 191 MB | NPU | encoder | ONNX | float | Snapdragon® 8 Elite Gen 5 Mobile | 7.282 ms | 16 - 326 MB | NPU | encoder | ONNX | float | Snapdragon® X2 Elite | 7.5 ms | 48 - 48 MB | NPU | encoder | ONNX | float | Snapdragon® X Elite | 18.697 ms | 48 - 48 MB | NPU | encoder | ONNX | float | Snapdragon® 8 Gen 3 Mobile | 12.55 ms | 16 - 410 MB | NPU | encoder | ONNX | float | Qualcomm® QCS8550 (Proxy) | 18.134 ms | 0 - 57 MB | NPU | encoder | ONNX | float | Qualcomm® QCS9075 | 21.863 ms | 15 - 19 MB | NPU | encoder | ONNX | float | Snapdragon® 8 Elite For Galaxy Mobile | 8.973 ms | 16 - 329 MB | NPU | encoder | QNN_DLC | float | Snapdragon® 8 Elite Gen 5 Mobile | 7.228 ms | 2 - 294 MB | NPU | encoder | QNN_DLC | float | Snapdragon® X2 Elite | 7.921 ms | 2 - 2 MB | NPU | encoder | QNN_DLC | float | Snapdragon® X Elite | 19.081 ms | 2 - 2 MB | NPU | encoder | QNN_DLC | float | Snapdragon® 8 Gen 3 Mobile | 12.807 ms | 0 - 348 MB | NPU | encoder | QNN_DLC | float | Qualcomm® QCS8275 (Proxy) | 47.865 ms | 2 - 265 MB | NPU | encoder | QNN_DLC | float | Qualcomm® QCS8550 (Proxy) | 18.433 ms | 2 - 4 MB | NPU | encoder | QNN_DLC | float | Qualcomm® SA8775P | 20.558 ms | 2 - 264 MB | NPU | encoder | QNN_DLC | float | Qualcomm® QCS9075 | 22.582 ms | 2 - 12 MB | NPU | encoder | QNN_DLC | float | Qualcomm® QCS8450 (Proxy) | 28.071 ms | 1 - 331 MB | NPU | encoder | QNN_DLC | float | Qualcomm® SA7255P | 47.865 ms | 2 - 265 MB | NPU | encoder | QNN_DLC | float | Qualcomm® SA8295P | 25.905 ms | 2 - 266 MB | NPU | encoder | QNN_DLC | float | Snapdragon® 8 Elite For Galaxy Mobile | 9.008 ms | 2 - 302 MB | NPU | encoder | TFLITE | float | Snapdragon® 8 Elite Gen 5 Mobile | 4.425 ms | 6 - 155 MB | NPU | encoder | TFLITE | float | Snapdragon® 8 Gen 3 Mobile | 8.405 ms | 6 - 228 MB | NPU | encoder | TFLITE | float | Qualcomm® QCS8275 (Proxy) | 38.155 ms | 7 - 173 MB | NPU | encoder | TFLITE | float | Qualcomm® QCS8550 (Proxy) | 11.945 ms | 7 - 9 MB | NPU | encoder | TFLITE | float | Qualcomm® SA8775P | 14.542 ms | 7 - 175 MB | NPU | encoder | TFLITE | float | Qualcomm® QCS9075 | 15.179 ms | 6 - 66 MB | NPU | encoder | TFLITE | float | Qualcomm® QCS8450 (Proxy) | 20.852 ms | 7 - 343 MB | NPU | encoder | TFLITE | float | Qualcomm® SA7255P | 38.155 ms | 7 - 173 MB | NPU | encoder | TFLITE | float | Qualcomm® SA8295P | 20.577 ms | 7 - 289 MB | NPU | encoder | TFLITE | float | Snapdragon® 8 Elite For Galaxy Mobile | 5.663 ms | 5 - 153 MB | NPU ## License * The license for the original implementation of TrOCR can be found [here](https://github.com/microsoft/unilm/blob/master/LICENSE). ## References * [TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models](https://arxiv.org/abs/2109.10282) * [Source Model Implementation](https://huggingface.co/microsoft/trocr-small-stage1) ## Community * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI. * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).