--- 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/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). 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.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.0/trocr-onnx-float.zip) | 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.0/trocr-qnn_dlc-float.zip) | 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.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/quic/ai-hub-models/blob/main/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/quic/ai-hub-models/blob/main/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 (TrOCRDecoder): 38.3M - Model size (TrOCRDecoder) (float): 146 MB - Number of parameters (TrOCREncoder): 23.0M - Model size (TrOCREncoder) (float): 87.8 MB ## Performance Summary | Model | Runtime | Precision | Chipset | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit |---|---|---|---|---|---|--- | TrOCRDecoder | ONNX | float | Snapdragon® X Elite | 2.358 ms | 67 - 67 MB | NPU | TrOCRDecoder | ONNX | float | Snapdragon® 8 Gen 3 Mobile | 1.842 ms | 0 - 287 MB | NPU | TrOCRDecoder | ONNX | float | Qualcomm® QCS8550 (Proxy) | 2.51 ms | 0 - 350 MB | NPU | TrOCRDecoder | ONNX | float | Qualcomm® QCS9075 | 2.962 ms | 7 - 17 MB | NPU | TrOCRDecoder | ONNX | float | Snapdragon® 8 Elite For Galaxy Mobile | 1.587 ms | 0 - 271 MB | NPU | TrOCRDecoder | ONNX | float | Snapdragon® 8 Elite Gen 5 Mobile | 1.424 ms | 0 - 258 MB | NPU | TrOCRDecoder | QNN_DLC | float | Snapdragon® X Elite | 2.172 ms | 7 - 7 MB | NPU | TrOCRDecoder | QNN_DLC | float | Snapdragon® 8 Gen 3 Mobile | 1.388 ms | 0 - 243 MB | NPU | TrOCRDecoder | QNN_DLC | float | Qualcomm® QCS8275 (Proxy) | 4.138 ms | 7 - 148 MB | NPU | TrOCRDecoder | QNN_DLC | float | Qualcomm® QCS8550 (Proxy) | 1.932 ms | 3 - 5 MB | NPU | TrOCRDecoder | QNN_DLC | float | Qualcomm® SA8775P | 2.764 ms | 7 - 148 MB | NPU | TrOCRDecoder | QNN_DLC | float | Qualcomm® QCS9075 | 2.54 ms | 7 - 15 MB | NPU | TrOCRDecoder | QNN_DLC | float | Qualcomm® QCS8450 (Proxy) | 2.835 ms | 2 - 216 MB | NPU | TrOCRDecoder | QNN_DLC | float | Qualcomm® SA7255P | 4.138 ms | 7 - 148 MB | NPU | TrOCRDecoder | QNN_DLC | float | Qualcomm® SA8295P | 2.802 ms | 7 - 130 MB | NPU | TrOCRDecoder | QNN_DLC | float | Snapdragon® 8 Elite For Galaxy Mobile | 1.208 ms | 0 - 227 MB | NPU | TrOCRDecoder | QNN_DLC | float | Snapdragon® 8 Elite Gen 5 Mobile | 1.093 ms | 1 - 213 MB | NPU | TrOCRDecoder | TFLITE | float | Snapdragon® 8 Gen 3 Mobile | 1.404 ms | 0 - 258 MB | NPU | TrOCRDecoder | TFLITE | float | Qualcomm® QCS8275 (Proxy) | 4.162 ms | 0 - 160 MB | NPU | TrOCRDecoder | TFLITE | float | Qualcomm® QCS8550 (Proxy) | 2.009 ms | 0 - 8 MB | NPU | TrOCRDecoder | TFLITE | float | Qualcomm® SA8775P | 8.646 ms | 0 - 161 MB | NPU | TrOCRDecoder | TFLITE | float | Qualcomm® QCS9075 | 2.547 ms | 0 - 83 MB | NPU | TrOCRDecoder | TFLITE | float | Qualcomm® QCS8450 (Proxy) | 2.815 ms | 0 - 224 MB | NPU | TrOCRDecoder | TFLITE | float | Qualcomm® SA7255P | 4.162 ms | 0 - 160 MB | NPU | TrOCRDecoder | TFLITE | float | Qualcomm® SA8295P | 2.8 ms | 0 - 142 MB | NPU | TrOCRDecoder | TFLITE | float | Snapdragon® 8 Elite For Galaxy Mobile | 1.166 ms | 0 - 235 MB | NPU | TrOCRDecoder | TFLITE | float | Snapdragon® 8 Elite Gen 5 Mobile | 1.105 ms | 0 - 215 MB | NPU | TrOCREncoder | ONNX | float | Snapdragon® X Elite | 18.045 ms | 48 - 48 MB | NPU | TrOCREncoder | ONNX | float | Snapdragon® 8 Gen 3 Mobile | 11.593 ms | 14 - 389 MB | NPU | TrOCREncoder | ONNX | float | Qualcomm® QCS8550 (Proxy) | 17.6 ms | 0 - 57 MB | NPU | TrOCREncoder | ONNX | float | Qualcomm® QCS9075 | 21.826 ms | 15 - 19 MB | NPU | TrOCREncoder | ONNX | float | Snapdragon® 8 Elite For Galaxy Mobile | 10.097 ms | 14 - 280 MB | NPU | TrOCREncoder | ONNX | float | Snapdragon® 8 Elite Gen 5 Mobile | 7.252 ms | 1 - 245 MB | NPU | TrOCREncoder | QNN_DLC | float | Snapdragon® X Elite | 18.938 ms | 2 - 2 MB | NPU | TrOCREncoder | QNN_DLC | float | Snapdragon® 8 Gen 3 Mobile | 12.557 ms | 0 - 381 MB | NPU | TrOCREncoder | QNN_DLC | float | Qualcomm® QCS8275 (Proxy) | 47.203 ms | 2 - 291 MB | NPU | TrOCREncoder | QNN_DLC | float | Qualcomm® QCS8550 (Proxy) | 18.324 ms | 2 - 4 MB | NPU | TrOCREncoder | QNN_DLC | float | Qualcomm® SA8775P | 20.83 ms | 2 - 292 MB | NPU | TrOCREncoder | QNN_DLC | float | Qualcomm® QCS9075 | 22.183 ms | 2 - 12 MB | NPU | TrOCREncoder | QNN_DLC | float | Qualcomm® QCS8450 (Proxy) | 28.527 ms | 0 - 360 MB | NPU | TrOCREncoder | QNN_DLC | float | Qualcomm® SA7255P | 47.203 ms | 2 - 291 MB | NPU | TrOCREncoder | QNN_DLC | float | Qualcomm® SA8295P | 26.372 ms | 2 - 291 MB | NPU | TrOCREncoder | QNN_DLC | float | Snapdragon® 8 Elite For Galaxy Mobile | 8.827 ms | 2 - 312 MB | NPU | TrOCREncoder | QNN_DLC | float | Snapdragon® 8 Elite Gen 5 Mobile | 7.254 ms | 2 - 303 MB | NPU | TrOCREncoder | TFLITE | float | Snapdragon® 8 Gen 3 Mobile | 8.625 ms | 5 - 233 MB | NPU | TrOCREncoder | TFLITE | float | Qualcomm® QCS8275 (Proxy) | 38.239 ms | 7 - 149 MB | NPU | TrOCREncoder | TFLITE | float | Qualcomm® QCS8550 (Proxy) | 12.241 ms | 0 - 2 MB | NPU | TrOCREncoder | TFLITE | float | Qualcomm® SA8775P | 14.713 ms | 7 - 161 MB | NPU | TrOCREncoder | TFLITE | float | Qualcomm® QCS9075 | 15.775 ms | 6 - 66 MB | NPU | TrOCREncoder | TFLITE | float | Qualcomm® QCS8450 (Proxy) | 22.075 ms | 7 - 348 MB | NPU | TrOCREncoder | TFLITE | float | Qualcomm® SA7255P | 38.239 ms | 7 - 149 MB | NPU | TrOCREncoder | TFLITE | float | Qualcomm® SA8295P | 20.792 ms | 7 - 286 MB | NPU | TrOCREncoder | TFLITE | float | Snapdragon® 8 Elite For Galaxy Mobile | 5.851 ms | 6 - 151 MB | NPU | TrOCREncoder | TFLITE | float | Snapdragon® 8 Elite Gen 5 Mobile | 4.58 ms | 6 - 212 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).