{"id":18273597,"url":"https://github.com/rapidai/paddleocrmodelconvert","last_synced_at":"2025-04-24T01:47:24.941Z","repository":{"id":86197386,"uuid":"386896701","full_name":"RapidAI/PaddleOCRModelConvert","owner":"RapidAI","description":"Convert the model in PaddleOCR to ONNX format","archived":false,"fork":false,"pushed_at":"2025-03-07T05:59:08.000Z","size":60777,"stargazers_count":82,"open_issues_count":1,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-24T01:47:16.033Z","etag":null,"topics":["convert","onnx","paddle","paddleocr","rapidocr"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RapidAI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-17T09:39:30.000Z","updated_at":"2025-04-15T07:05:34.000Z","dependencies_parsed_at":"2023-09-22T05:42:43.656Z","dependency_job_id":"4040e27f-520a-4d73-b416-1be8e9d09c7e","html_url":"https://github.com/RapidAI/PaddleOCRModelConvert","commit_stats":null,"previous_names":["rapidai/paddleocrmodelconvert","rapidai/paddleocrmodelconverter"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RapidAI%2FPaddleOCRModelConvert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RapidAI%2FPaddleOCRModelConvert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RapidAI%2FPaddleOCRModelConvert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RapidAI%2FPaddleOCRModelConvert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RapidAI","download_url":"https://codeload.github.com/RapidAI/PaddleOCRModelConvert/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250546041,"owners_count":21448255,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convert","onnx","paddle","paddleocr","rapidocr"],"created_at":"2024-11-05T12:07:00.649Z","updated_at":"2025-04-24T01:47:24.925Z","avatar_url":"https://github.com/RapidAI.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n     \u003cdiv align=\"center\"\u003e\n        \u003ch1\u003e\u003cb\u003e\u003ci\u003e🔄 PaddleOCR Model Convert\u003c/i\u003e\u003c/b\u003e\u003c/h1\u003e\n     \u003c/div\u003e\n     \u003cdiv\u003e\u0026nbsp;\u003c/div\u003e\n     \u003ca href=\"https://huggingface.co/spaces/SWHL/PaddleOCRModelConverter\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/%F0%9F%A4%97 -Online Convert-blue\"\u003e\u003c/a\u003e\n     \u003ca href=\"https://www.modelscope.cn/studios/liekkas/PaddleOCRModelConverter/summary\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/ModelScope-Online Convert -blue\"\u003e\u003c/a\u003e\n     \u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/Python-\u003e=3.6,\u003c3.13-aff.svg\"\u003e\u003c/a\u003e\n     \u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg\"\u003e\u003c/a\u003e\n     \u003ca href=\"https://pypi.org/project/paddleocr_convert/\"\u003e\u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/paddleocr_convert\"\u003e\u003c/a\u003e\n     \u003ca href=\"https://pepy.tech/project/paddleocr_convert\"\u003e\u003cimg src=\"https://static.pepy.tech/personalized-badge/paddleocr_convert?period=total\u0026units=abbreviation\u0026left_color=grey\u0026right_color=blue\u0026left_text=Downloads \"\u003e\u003c/a\u003e\n    \u003ca href=\"https://semver.org/\"\u003e\u003cimg alt=\"SemVer2.0\" src=\"https://img.shields.io/badge/SemVer-2.0-brightgreen\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/psf/black\"\u003e\u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n### Introduction\n- This repository is mainly to convert [Inference Model in PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/models_list.md) into ONNX format.\n- **Input**: **url** or local **tar** path of inference model\n- **Output**: converted **ONNX** model\n- If it is a recognition model, you need to provide the original txt path of the corresponding dictionary (**Open the txt file in github, click the path after raw in the upper right corner, similar to [this](https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.6/ppocr/utils/ppocr_keys_v1.txt)**), used to write the dictionary into the ONNX model\n- ☆ It needs to be used with the relevant reasoning code in [RapidOCR](https://github.com/RapidAI/RapidOCR)\n- If you encounter a model that cannot be successfully converted, you can check which steps are wrong one by one according to the ideas in the figure below.\n\n\n### Overall framework\n```mermaid\nflowchart TD\n\nA([PaddleOCR inference model]) --paddle2onnx--\u003e B([ONNX])\nB --\u003e C([Change Dynamic Input]) --\u003e D([Rec: save the character dict to onnx])\nD --\u003e E([Save])\n```\n\n### Installation\n```bash\npip install paddleocr_convert\n```\n\n### Usage\n\u003e [!WARNING]\n\u003e\n\u003e Only support the **reasoning model** in the download address in [link](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/models_list.md), if it is a training model, Manual conversion to inference format is required.\n\u003e\n\u003e The **slim quantized model** in PaddleOCR does not support conversion.\n\n#### Using the command line\n- Usage:\n    ```bash\n    $ paddleocr_convert -h\n    usage: paddleocr_convert [-h] [-p MODEL_PATH] [-o SAVE_DIR]\n                            [-txt_path TXT_PATH]\n\n    optional arguments:\n    -h, --help show this help message and exit\n    -p MODEL_PATH, --model_path MODEL_PATH\n                            The inference model url or local path of paddleocr.\n                            e.g. https://paddleocr.bj.bcebos.com/PP-\n                            OCRv3/chinese/ch_PP-OCRv3_det_infer.tar or\n                            models/ch_PP-OCRv3_det_infer.tar\n    -o SAVE_DIR, --save_dir SAVE_DIR\n                            The directory of saving the model.\n    -txt_path TXT_PATH, --txt_path TXT_PATH\n                            The raw txt url or local txt path, if the model is\n                            recognition model.\n    ```\n- Example:\n    ```bash\n    #online\n    $ paddleocr_convert -p https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar \\\n                        -o models\n\n    $ paddleocr_convert -p https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar\\\n                        -o models\\\n                        -txt_path https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.6/ppocr/utils/ppocr_keys_v1.txt\n\n    # offline\n    $ paddleocr_convert -p models/ch_PP-OCRv3_det_infer.tar\\\n                        -o models\n\n    $ paddleocr_convert -p models/ch_PP-OCRv3_rec_infer.tar\\\n                        -o models\\\n                        -txt_path models/ppocr_keys_v1.txt\n    ```\n\n#### Script use\n- online mode\n    ```python\n    from paddleocr_convert import PaddleOCRModelConvert\n\n    converter = PaddleOCRModelConvert()\n    save_dir = 'models'\n    url = 'https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar'\n    txt_url = 'https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.6/ppocr/utils/ppocr_keys_v1.txt'\n\n    converter(url, save_dir, txt_path=txt_url)\n    ```\n- offline mode\n    ```python\n    from paddleocr_convert import PaddleOCRModelConvert\n\n    converter = PaddleOCRModelConvert()\n    save_dir = 'models'\n    model_path = 'models/ch_PP-OCRv3_rec_infer.tar'\n    txt_path = 'models/ppocr_keys_v1.txt'\n    converter(model_path, save_dir, txt_path=txt_path)\n    ```\n\n### Use the model\nAssuming that the model needs to be recognized in Japanese, and it has been converted, the path is `local/models/japan.onnx`\n\n1. Install `rapidocr_onnxruntime` library\n    ```bash\n    pip install rapidocr_onnxruntime\n    ```\n2. Script use\n    ```python\n    from rapidocr_onnxruntime import RapidOCR\n\n    model_path = 'local/models/japan.onnx'\n    engine = RapidOCR(rec_model_path=model_path)\n\n    img = '1.jpg'\n    result, elapse = engine(img)\n    ```\n3. CLI use\n    ```bash\n    rapidocr_onnxruntime -img 1.jpg --rec_model_path local/models/japan.onnx\n    ```\n\n### Changelog\n\n\u003cdetails\u003e\n    \u003csummary\u003eClick to expand\u003c/summary\u003e\n\n- 2023-09-22 v0.0.17 update:\n    - Improve the log when meets the error.\n- 2023-07-27 v0.0.16 update:\n   - Added the online conversion version of ModelScope.\n   - Change python version from python 3.6 ~ 3.11.\n- 2023-04-13 update:\n   - Add online conversion program [link](https://huggingface.co/spaces/SWHL/PaddleOCRModelConverter)\n- 2023-03-05 v0.0.4~7 update:\n   - Support transliteration of local models and dictionaries\n   - Optimize internal logic and error feedback\n- 2023-02-28 v0.0.3 update:\n   - Added setting to automatically change to dynamic input for models that are not dynamic input\n- 2023-02-27 v0.0.2 update:\n   - Encapsulate the conversion model code into a package, which is convenient for self-help model conversion\n- 2022-08-15 v0.0.1 update:\n   - Write the dictionary of the recognition model into the meta in the onnx model for subsequent distribution.\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frapidai%2Fpaddleocrmodelconvert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frapidai%2Fpaddleocrmodelconvert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frapidai%2Fpaddleocrmodelconvert/lists"}