本文档记录 TrOCR-base-printed 在昇腾 NPU 环境的快速部署与验证结果。
TrOCR 是一个基于 Transformer 的光学字符识别 (OCR) 模型,由 Microsoft 开发。该模型在 SROIE 数据集上进行了微调,专门用于印刷体文字识别。
相关获取地址:
| 组件 | 版本 |
|---|---|
torch | 2.9.0+cpu |
torch_npu | 2.9.0.post1+gitee7ba04 |
transformers | 5.15.1 |
pillow | latest |
sentencepiece | 0.2.1 |
910B3/workspace/weights/tcroft-base-printedpip install torch torch_npu -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install transformers pillow sentencepiece -i https://pypi.tuna.tsinghua.edu.cn/simplenpu-smi infopython inference.py --input ./test_image.jpg --output ./output| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --input | str | - | 输入图像路径 |
| --output | str | ./output | 输出目录 |
| --model_path | str | /workspace/weights/tcroft-base-printed | 模型路径 |
| --device | str | auto | 推理设备 (npu/cuda/cpu) |
输入:
./test_image.jpg (包含印刷体文字的图像)输出:
[识别结果] 图像中的文字内容
[INFO] 推理完成,耗时: x.xxstransformers 和 torch_npu 调用 NPU 进行推理