- Notifications
You must be signed in to change notification settings - Fork34
Tengine Convert Tool supports converting multi framworks' models into tmfile that suitable for Tengine-Lite AI framework.
License
NotificationsYou must be signed in to change notification settings
OAID/Tengine-Convert-Tools
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Tengine Convert Tool supports converting multi framworks' models into tmfile that suitable forTengine-Lite AI framework.Since 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.
- For loading caffe model or TensorFlow model.
sudo apt install libprotobuf-dev protobuf-compiler
- If use the Fedora/CentOS ,use follow command instead.
sudo dnf install protobuf-develsudo dnf install boost-devel glog-devel
mkdir build&&cd buildcmake ..make -j`nproc`&& make install
- The exection should be under
./build/install/bin/named asconvert_tool.
$ ./convert_tool -h[Convert Tools Info]: optional arguments: -h help show this help message and exit -f input type path to input float32 tmfile -p input structure path to the network structure of input model(*.prototxt, *.symbol, *.cfg) -m input params path to the network params of input model(*.caffemodel, *.params, *.weight, *.pb, *.onnx, *.tflite) -o output model path to output fp32 tmfileTo run the convert tool, running as following command, Note: The command examples are based onmobilenet model:
- Caffe
./install/bin/convert_tool -f caffe -p mobilenet_deploy.prototxt -m mobilenet.caffemodel -o mobilenet.tmfile
- MxNet
./install/bin/convert_tool -f mxnet -p mobilenet1_0-symbol.json -m mobilene1_0-0000.params -o mobileent.tmfile
- ONNX
./install/bin/convert_tool -f onnx -m mobilenet.onnx -o mobilenet.tmfile
- TensorFlow
./install/bin/convert_tool -f tensorflow -m mobielenet_v1_1.0_224_frozen.pb -o mobilenet.tmfile
- TFLITE
./install/bin/convert_tool -f tflite -m mobielenet.tflite -o mobilenet.tmfile
- DarkNet: darknet only support for yolov3 model
./install/bin/convert_tool -f darknet -p yolov3.cfg -m yolov3.weights -o yolov3.tmfile
- NCNN
./install/bin/convert_tool -f ncnn -p mobilenet.param -m mobilenet.bin -o mobilenet.tmfile
- MegEngine
./install/bin/convert_tool -f megengine -m mobilenet.pkl -o mobilenet.tmfile
- PaddlePaddle
./install/bin/convert_tool -f paddle -p inference.pdmodel -m inference.pdiparams -o mobilenetv2_paddle.tmfile
- First of all, build MegEngine withDEBUG mode:
# clone MegEnginegit clone https://github.com/MegEngine/MegEngine.git# prepare for buildingcd MegEngine./third_party/prepare.sh./third_party/install-mkl.shmkdir build&&cd build# build MegEngine with DEBUG modecmake .. -DMGE_WITH_TEST=OFF -DMGE_BUILD_SDK=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX={PREDEFINED_INSTALL_PATH}make -j`nproc`make installmake develop# export environmentexport PYTHONPATH=/path/to/MegEngine/python_module# test with python python3 -c"import megengine"
- Build Tengine convert tool
# clone Tengine convert toolgit clone https://github.com/OAID/Tengine-Convert-Tools# build with MegEngine supportcmake -DBUILD_MEGENGINE_SERIALIZER=ON -DMEGENGINE_INSTALL_PATH={PREDEFINED_INSTALL_PATH} ..make -j`nproc`make install
- Serialize your MegEngine model
# get a pre-trained resnet18 model from MegEngine Model Hubimportmegengine.hubresnet18=megengine.hub.load("megengine/models","resnet18",pretrained=True)# use MegEngine trace to deal with downloaded modelfrommegengine.jitimporttraceimportmegengine.functionalasF@trace(symbolic=True)defpred_fun(data,*,net):net.eval()pred=net(data)# if model has softmaxpred_normalized=F.softmax(pred)returnpred_normalized# fill a random input for modelimportnumpyasnpdata=np.random.random((1,3,224,224)).astype(np.float32)# trace and save the modelpred_fun.trace(data,net=resnet18)pred_fun.dump('new_model.pkl')
A jupyter notebook was offered for users, checkMegEngine.ipynb.
- Convert MegEngine .pkl model to Tengine .tmfile
./install/bin/convert_tool -f megengine -m new_model.pkl -o resnet18.tmfile
- Adding operator's name defined file under operator/include directory that likes xxx.hpp and xxx_param.hpp (including operator's params);
- Adding operator's memory allocation (calculate the memory) under operator/operator directory;
- Register operator in project operators' registery under operator/operator/plugin/init.cpp file;
- 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.
- Github issues
- QQ groupchat: 829565581
- Email:Support@openailab.com
- Tengine Community:http://www.tengine.org.cn/
About
Tengine Convert Tool supports converting multi framworks' models into tmfile that suitable for Tengine-Lite AI framework.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published