Currently there are many available deep learning frameworks for researchers and engineers to implement their desired deep models. Sometimes, when you find a fantastic GitHub repository which share a pre-trained model on a framework which you are not familiar with. For example, you are an expert PyTorch deep learning code developer, meanwhile you find a great code with its pre-trained model on MXNet; and you want to modify this model according to your needs. Thus, deep learning model conversion tools are extremely needed. As each framework has its own structure, converting a model between two different frameworks requires a great knowledge of both of them. However, There are many fantastic model conversion tools such as ONNX, MMdnn, and etc. for converting and visualizing deep models between a wide collection of frameworks.
ONNX is an effort to unify converters for neural networks in order to bring some sanity to the NN world. Released by Facebook and Microsoft.
MMdnn (Model Management Deep Neural Network) is supported by Microsoft, By using MMdnn, one can convert each model from the origin framework to a standard Intermediate Representation (IR), and then convert the IR format to the target framework structure. It can convert models between CaffeEmit, CNTK, CoreML, Keras, MXNet, ONNX, PyTorch and TensorFlow.
PyTorch convertor can convert models to PyTorch model.
TensorFlow convertor can convert models to TensorFlow model.
Keras convertor can convert models to Keras model.
MXNet convertor can convert models to MXNet model.
Caffe convertor can convert models to Caffe model.
Caffe2 convertor can convert models to Caffe2 model.
CNTK convertor can convert models to CNTK model.
Theano/Lasagne convertor can convert models to Theano/Lasagne model.
Darknet convertor can convert models to Darknet model.
Torch convertor can convert models to Torch model.
Neon convertor can convert models to Neon model.
CoreML convertor can convert models to coreML model.
Paddle convertor can convert models to Paddle model.
Chainer convertor can convert models to Chainer model.
Here is an appropriate example to convert the Full ImageNet pre-trained model from MXNet to PyTorch via MMdnn convertor. ImageNet is an image database organized according to the WordNet hierarchy, in which each node of the hierarchy is depicted by hundreds and thousands of images. Since 2010, the annual ImageNet Large Scale Visual Recognition Challenge (ILSVRC) is a competition where research teams evaluate their algorithms on the given data set, and compete to achieve higher accuracy on several visual recognition tasks. A common reason to train a network on ImageNet data is to use it for transfer learning (including feature extraction or fine-tuning other models). Having a pre-trained model which is trained on such a huge training data set (i.e., full ImageNet), would be a really valuable network. It can speed up the convergence early in the training phase, and also improves the target task accuracy in some scenarios.
1 | sudo pip3 install --upgrade mmdnn |
1 | sudo pip3 install --upgrade torch torchvision |
1 | import os |
1 | python3 -m mmdnn.conversion._script.convertToIR -f mxnet -n imagenet11k-resnet-152-symbol.json -w imagenet11k-resnet-152-0000.params -d resnet152 --inputShape 3,224,224 |
1 | python3 -m mmdnn.conversion._script.IRToCode -f pytorch --IRModelPath resnet152.pb --dstModelPath kit_imagenet.py --IRWeightPath resnet152.npy -dw kit_pytorch.npy |
1 | python3 -m mmdnn.conversion.examples.pytorch.imagenet_test --dump resnet152Full.pth -n kit_imagenet.py -w kit_pytorch.npy |
1 | import torch |
Pre-trained-Model, PyTorch, TenforFlow — Apr 20, 2020
Made with ❤️ and ☀️ on Earth.