{"id":18277450,"url":"https://github.com/oaid/tengine-convert-tools","last_synced_at":"2026-03-15T23:43:14.039Z","repository":{"id":48594480,"uuid":"284660339","full_name":"OAID/Tengine-Convert-Tools","owner":"OAID","description":"Tengine Convert Tool supports converting multi framworks' models into tmfile that suitable for Tengine-Lite AI framework.","archived":false,"fork":false,"pushed_at":"2021-07-19T05:42:47.000Z","size":1003,"stargazers_count":93,"open_issues_count":16,"forks_count":34,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-02T02:44:17.377Z","etag":null,"topics":["artificial-intelligence","cnn","dnn","mxnet","onnx","pytorch","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"C++","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/OAID.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}},"created_at":"2020-08-03T09:39:05.000Z","updated_at":"2025-03-24T10:14:25.000Z","dependencies_parsed_at":"2022-08-27T21:23:34.694Z","dependency_job_id":null,"html_url":"https://github.com/OAID/Tengine-Convert-Tools","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OAID%2FTengine-Convert-Tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OAID%2FTengine-Convert-Tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OAID%2FTengine-Convert-Tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OAID%2FTengine-Convert-Tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OAID","download_url":"https://codeload.github.com/OAID/Tengine-Convert-Tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289382,"owners_count":20914463,"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":["artificial-intelligence","cnn","dnn","mxnet","onnx","pytorch","tensorflow"],"created_at":"2024-11-05T12:19:13.196Z","updated_at":"2026-03-15T23:43:09.005Z","avatar_url":"https://github.com/OAID.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tengine Convert Tools\n\n[![GitHub license](http://OAID.github.io/pics/apache_2.0.svg)](./LICENSE) [![Build Status](https://img.shields.io/github/workflow/status/OAID/Tengine-Convert-Tools/Tengine-Convert-Tools-Actions)](https://github.com/OAID/Tengine-Convert-Tools/actions?query=workflow%3ATengine-Convert-Tools-Actions) [![codecov](https://codecov.io/gh/OAID/Tengine-Convert-Tools/branch/master/graph/badge.svg?token=YY4A9HUIUF)](https://codecov.io/gh/OAID/Tengine-Convert-Tools)\n\n# Introduction\n\nTengine Convert Tool supports converting multi framworks' models into tmfile that suitable for [Tengine-Lite AI framework](https://github.com/OAID/Tengine/tree/tengine-lite).\nSince this tool relys on protobuf to resolve proto file of Caffe, ONNX, TensorFlow, TFLite and so on, it can only run under x86 Linux system.\n\n## Install dependent libraries\n- For loading caffe model or TensorFlow model.\n``` shell\nsudo apt install libprotobuf-dev protobuf-compiler\n```\n\n- If use the Fedora/CentOS ,use follow command instead.\n``` shell\nsudo dnf install protobuf-devel\nsudo dnf install boost-devel glog-devel\n```\n\n## Build Convert Tool\n``` shell\nmkdir build \u0026\u0026 cd build\ncmake ..\nmake -j`nproc` \u0026\u0026 make install\n```\n\n## Exection File\n\n- The exection should be under `./build/install/bin/` named as `convert_tool`.\n\n## Run Convert Tool\n\n### How to use\n\n```\n$ ./convert_tool -h\n[Convert Tools Info]: optional arguments:\n        -h    help            show this help message and exit\n        -f    input type      path to input float32 tmfile\n        -p    input structure path to the network structure of input model(*.prototxt, *.symbol, *.cfg)\n        -m    input params    path to the network params of input model(*.caffemodel, *.params, *.weight, *.pb, *.onnx, *.tflite)\n        -o    output model    path to output fp32 tmfile\n```\n\nTo run the convert tool, running as following command, Note: The command examples are based on `mobilenet` model:\n\n- Caffe\n``` shell\n./install/bin/convert_tool -f caffe -p mobilenet_deploy.prototxt -m mobilenet.caffemodel -o mobilenet.tmfile\n```\n\n- MxNet\n``` shell\n./install/bin/convert_tool -f mxnet -p mobilenet1_0-symbol.json -m mobilene1_0-0000.params -o mobileent.tmfile\n```\n\n- ONNX\n``` shell\n./install/bin/convert_tool -f onnx -m mobilenet.onnx -o mobilenet.tmfile\n```\n\n- TensorFlow\n``` shell\n./install/bin/convert_tool -f tensorflow -m mobielenet_v1_1.0_224_frozen.pb -o mobilenet.tmfile\n```\n\n- TFLITE\n``` shell\n./install/bin/convert_tool -f tflite -m mobielenet.tflite -o mobilenet.tmfile\n```\n\n- DarkNet: darknet only support for yolov3 model\n``` shell\n./install/bin/convert_tool -f darknet -p yolov3.cfg -m yolov3.weights -o yolov3.tmfile\n```\n\n- NCNN\n``` shell\n./install/bin/convert_tool -f ncnn -p mobilenet.param -m mobilenet.bin -o mobilenet.tmfile\n```\n\n- MegEngine\n``` shell\n./install/bin/convert_tool -f megengine -m mobilenet.pkl -o mobilenet.tmfile\n```\n\n- PaddlePaddle\n``` shell\n./install/bin/convert_tool -f paddle -p inference.pdmodel -m inference.pdiparams -o mobilenetv2_paddle.tmfile\n```\n\n## How to enable MegEngine support[optional]\n- First of all, build MegEngine with **DEBUG** mode:\n\n``` bash\n# clone MegEngine\ngit clone https://github.com/MegEngine/MegEngine.git\n\n# prepare for building\ncd MegEngine\n./third_party/prepare.sh\n./third_party/install-mkl.sh\nmkdir build \u0026\u0026 cd build\n\n# build MegEngine with DEBUG mode\ncmake .. -DMGE_WITH_TEST=OFF -DMGE_BUILD_SDK=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX={PREDEFINED_INSTALL_PATH}\nmake -j`nproc`\nmake install\nmake develop\n\n# export environment\nexport PYTHONPATH=/path/to/MegEngine/python_module\n\n# test with python\n python3 -c \"import megengine\"\n```\n\n- Build Tengine convert tool\n\n``` bash\n# clone Tengine convert tool\ngit clone https://github.com/OAID/Tengine-Convert-Tools\n\n# build with MegEngine support\ncmake -DBUILD_MEGENGINE_SERIALIZER=ON -DMEGENGINE_INSTALL_PATH={PREDEFINED_INSTALL_PATH} ..\nmake -j`nproc`\nmake install\n```\n\n- Serialize your MegEngine model\n\n``` python\n# get a pre-trained resnet18 model from MegEngine Model Hub\nimport megengine.hub\nresnet18 = megengine.hub.load(\"megengine/models\", \"resnet18\", pretrained=True)\n\n# use MegEngine trace to deal with downloaded model\nfrom megengine.jit import trace\nimport megengine.functional as F\n\n@trace(symbolic=True)\ndef pred_fun(data, *, net):\n    net.eval()\n    pred = net(data)\n    # if model has softmax\n    pred_normalized = F.softmax(pred)\n    return pred_normalized\n\n# fill a random input for model\nimport numpy as np\ndata = np.random.random((1, 3, 224, 224)).astype(np.float32)\n\n# trace and save the model\npred_fun.trace(data, net=resnet18)\npred_fun.dump('new_model.pkl')\n```\nA jupyter notebook was offered for users, check [MegEngine.ipynb](https://github.com/OAID/Tengine-Convert-Tools/blob/master/megengine.ipynb).\n\n- Convert MegEngine .pkl model to Tengine .tmfile\n\n``` bash\n./install/bin/convert_tool -f megengine -m new_model.pkl -o resnet18.tmfile\n```\n\n\n## How to add self define operator\n\n- Adding operator's name defined file under operator/include directory that likes xxx.hpp and xxx_param.hpp (including operator's params);\n- Adding operator's memory allocation (calculate the memory) under operator/operator directory;\n- Register operator in project operators' registery under operator/operator/plugin/init.cpp file;\n- After adding operator definition, you need to add operator into model serializers, these files are under tools directory. There are multiply framework model serializers, finding file name and .cpp file under that corresponding framwork folder. Following the other operator's definition in that .cpp file.\n\n## License\n\n- [Apache 2.0](LICENSE)\n\n## Tech Forum\n- Github issues\n- QQ groupchat: 829565581\n- Email: Support@openailab.com\n- Tengine Community: http://www.tengine.org.cn/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foaid%2Ftengine-convert-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foaid%2Ftengine-convert-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foaid%2Ftengine-convert-tools/lists"}