README.md
1# ![MMdnn](https://ndqzpq.dm2304.livefilestore.com/y4mF9ON1vKrSy0ew9dM3Fw6KAvLzQza2nL9JiMSIfgfKLbqJPvuxwOC2VIur_Ycz4TvVpkibMkvKXrX-N9QOkyh0AaUW4qhWDak8cyM0UoLLxc57apyhfDaxflLlZrGqiJgzn1ztsxiaZMzglaIMhoo8kjPuZ5-vY7yoWXqJuhC1BDHOwgNPwIgzpxV1H4k1oQzmewThpAJ_w_fUHzianZtMw?width=35&height=35&cropmode=none) MMdnn
2
3[![PyPi Version](https://img.shields.io/pypi/v/mmdnn.svg)](https://pypi.org/project/mmdnn/)
4[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5[![Linux](https://travis-ci.org/Microsoft/MMdnn.svg?branch=master)](https://travis-ci.org/Microsoft/MMdnn)
6
7MMdnn is a comprehensive and cross-framework tool to convert, visualize and diagnose deep learning (DL) models.
8The "MM" stands for model management, and "dnn" is the acronym of deep neural network.
9
10Major features include:
11
12- <a href="#conversion">**Model Conversion**</a>
13
14 - We implement a universal converter to convert DL models between frameworks, which means you can train a model with one framework and deploy it with another.
15
16- **Model Retraining**
17
18 - During the model conversion, we generate some code snippets to simplify later retraining or inference.
19
20- **Model Search & Visualization**
21
22 - We provide a [model collection](mmdnn/models/README.md) to help you find some popular models.
23 - We provide a <a href="#visualization">model visualizer</a> to display the network architecture more intuitively.
24
25- **Model Deployment**
26
27 - We provide some guidelines to help you deploy DL models to another hardware platform.
28 - [Android](https://github.com/Microsoft/MMdnn/wiki/Deploy-your-TensorFlow-Lite-Model-in-Android)
29 - [Serving](https://github.com/Microsoft/MMdnn/wiki/Tensorflow-Serving-Via-Docker)
30
31 - We provide a guide to help you accelerate inference with TensorRT.
32 - [TensorRT](https://github.com/Microsoft/MMdnn/wiki/Using-TensorRT-to-Accelerate-Inference)
33
34
35## Related Projects
36
37Targeting at openness and advancing state-of-art technology, [Microsoft Research (MSR)](https://www.microsoft.com/en-us/research/group/systems-and-networking-research-group-asia/) and [Microsoft Software Technology Center (STC)](https://www.microsoft.com/en-us/ard/company/introduction.aspx) had also released few other open source projects:
38
39* [OpenPAI](https://github.com/Microsoft/pai) : an open source platform that provides complete AI model training and resource management capabilities, it is easy to extend and supports on-premise, cloud and hybrid environments in various scale.
40* [FrameworkController](https://github.com/Microsoft/frameworkcontroller) : an open source general-purpose Kubernetes Pod Controller that orchestrate all kinds of applications on Kubernetes by a single controller.
41* [NNI](https://github.com/Microsoft/nni) : a lightweight but powerful toolkit to help users automate Feature Engineering, Neural Architecture Search, Hyperparameter Tuning and Model Compression.
42* [NeuronBlocks](https://github.com/Microsoft/NeuronBlocks) : an NLP deep learning modeling toolkit that helps engineers to build DNN models like playing Lego. The main goal of this toolkit is to minimize developing cost for NLP deep neural network model building, including both training and inference stages.
43* [SPTAG](https://github.com/Microsoft/SPTAG) : Space Partition Tree And Graph (SPTAG) is an open source library for large scale vector approximate nearest neighbor search scenario.
44
45We encourage researchers, developers and students to leverage these projects to boost their AI / Deep Learning productivity.
46
47## Installation
48
49### Install manually
50
51You can get a stable version of MMdnn by
52
53```bash
54pip install mmdnn
55```
56And make sure to have [Python](https://www.python.org/) installed
57or you can try the newest version by
58
59```bash
60pip install -U git+https://github.com/Microsoft/MMdnn.git@master
61```
62
63### Install with docker image
64
65MMdnn provides a docker image, which packages MMdnn and Deep Learning frameworks that we support as well as other dependencies.
66You can easily try the image with the following steps:
67
681. Install Docker Community Edition(CE)
69
70 [_Learn more about how to install docker_](https://github.com/Microsoft/MMdnn/blob/master/docs/InstallDockerCE.md)
71
721. Pull MMdnn docker image
73 ```bash
74 docker pull mmdnn/mmdnn:cpu.small
75 ```
76
771. Run image in an interactive mode
78
79 ```bash
80 docker run -it mmdnn/mmdnn:cpu.small
81 ```
82
83## Features
84
85### <a name="conversion">Model Conversion</a>
86
87Across the industry and academia, there are a number of existing frameworks available for developers and researchers to design a model, where each framework has its own network structure definition and saving model format. The gaps between frameworks impede the inter-operation of the models.
88
89<img src="https://raw.githubusercontent.com/Microsoft/MMdnn/master/docs/supported.jpg" width="633" >
90
91We provide a model converter to help developers convert models between frameworks through an intermediate representation format.
92
93#### Support frameworks
94
95> [Note] You can click the links to get detailed README of each framework.
96
97- [Caffe](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/caffe/README.md)
98- [Microsoft Cognitive Toolkit (CNTK)](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/cntk/README.md)
99- [CoreML](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/coreml/README.md)
100- [Keras](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/keras/README.md)
101- [MXNet](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/mxnet/README.md)
102- [ONNX](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/onnx/README.md) (Destination only)
103- [PyTorch](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/pytorch/README.md)
104- [TensorFlow](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/tensorflow/README.md) (Experimental) (We highly recommend you read the README of TensorFlow first)
105- [DarkNet](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/darknet/README.md) (Source only, Experiment)
106
107#### Tested models
108
109The model conversion between currently supported frameworks is tested on some **ImageNet** models.
110
111Models | Caffe | Keras | TensorFlow | CNTK | MXNet | PyTorch | CoreML | ONNX
112:-----:|:-----:|:-----:|:----------:|:----:|:-----:|:--------:|:------:|:-----:|
113[VGG 19](https://arxiv.org/abs/1409.1556.pdf) | √ | √ | √ | √ | √ | √ | √ | √
114[Inception V1](https://arxiv.org/abs/1409.4842v1) | √ | √ | √ | √ | √ | √ | √ | √
115[Inception V3](https://arxiv.org/abs/1512.00567) | √ | √ | √ | √ | √ | √ | √ | √
116[Inception V4](https://arxiv.org/abs/1512.00567) | √ | √ | √ | o | √ | √ | √ | √
117[ResNet V1](https://arxiv.org/abs/1512.03385) | × | √ | √ | o | √ | √ | √ | √
118[ResNet V2](https://arxiv.org/abs/1603.05027) | √ | √ | √ | √ | √ | √ | √ | √
119[MobileNet V1](https://arxiv.org/pdf/1704.04861.pdf) | × | √ | √ | o | √ | √ | √ | √ | √
120[MobileNet V2](https://arxiv.org/pdf/1704.04861.pdf) | × | √ | √ | o | √ | √ | √ | √ | √
121[Xception](https://arxiv.org/pdf/1610.02357.pdf) | √ | √ | √ | o | × | √ | √ | √ | √
122[SqueezeNet](https://arxiv.org/pdf/1602.07360) | √ | √ | √ | √ | √ | √ | √ | √ | √
123[DenseNet](https://arxiv.org/abs/1608.06993) | √ | √ | √ | √ | √ | √ | √ | √
124[NASNet](https://arxiv.org/abs/1707.07012) | x | √ | √ | o | √ | √ | √ | x
125[ResNext](https://arxiv.org/abs/1611.05431) | √ | √ | √ | √ | √ | √ | √ | √ | √ | √
126[voc FCN](https://people.eecs.berkeley.edu/~jonlong/long_shelhamer_fcn.pdf) | | | √ | √ | |
127Yolo3 | | √ | | √ |
128
129#### Usage
130
131One command to achieve the conversion. Using TensorFlow **ResNet V2 152** to PyTorch as our example.
132
133```bash
134$ mmdownload -f tensorflow -n resnet_v2_152 -o ./
135$ mmconvert -sf tensorflow -in imagenet_resnet_v2_152.ckpt.meta -iw imagenet_resnet_v2_152.ckpt --dstNodeName MMdnn_Output -df pytorch -om tf_resnet_to_pth.pth
136```
137
138Done.
139
140#### On-going frameworks
141
142- Torch7 (help wanted)
143- Chainer (help wanted)
144
145#### On-going Models
146
147- Face Detection
148- Semantic Segmentation
149- Image Style Transfer
150- Object Detection
151- RNN
152
153---
154
155### <a name="visualization">Model Visualization</a>
156
157You can use the [MMdnn model visualizer](http://vis.mmdnn.com/) and submit your IR json file to visualize your model. In order to run the commands below, you will need to install [requests](https://anaconda.org/anaconda/requests), [keras](https://anaconda.org/anaconda/keras), and [TensorFlow](https://anaconda.org/anaconda/tensorflow) using your favorite package manager.
158
159Use the [Keras "inception_v3" model](https://github.com/fchollet/deep-learning-models) as an example again.
160
1611. Download the pre-trained models
162
163```bash
164$ mmdownload -f keras -n inception_v3
165```
166
1672. Convert the pre-trained model files into an intermediate representation
168
169```bash
170$ mmtoir -f keras -w imagenet_inception_v3.h5 -o keras_inception_v3
171```
172
1733. Open the [MMdnn model visualizer](http://mmdnn.eastasia.cloudapp.azure.com:8080/) and choose file *keras_inception_v3.json*
174
175![vismmdnn](docs/vismmdnn.png)
176
177---
178
179## Examples
180
181### Official Tutorial
182
183- [Keras "inception V3" to CNTK](https://github.com/Microsoft/MMdnn/blob/master/docs/keras2cntk.md) and [related issue](https://github.com/Microsoft/MMdnn/issues/19)
184
185- [TensorFlow slim model "ResNet V2 152" to PyTorch](https://github.com/Microsoft/MMdnn/blob/master/docs/tf2pytorch.md)
186
187- [Mxnet model "LResNet50E-IR" to TensorFlow](https://github.com/Microsoft/MMdnn/issues/85) and [related issue](https://github.com/Microsoft/MMdnn/issues/135)
188
189### Users' Examples
190
191- [MXNet "ResNet-152-11k" to PyTorch](https://github.com/Microsoft/MMdnn/issues/6)
192
193- [Another Example of MXNet "ResNet-152-11k" to PyTorch](https://blog.paperspace.com/convert-full-imagenet-pre-trained-model-from-mxnet-to-pytorch/)
194
195- [MXNet "ResNeXt" to Keras](https://github.com/Microsoft/MMdnn/issues/58)
196
197- [TensorFlow "ResNet-101" to PyTorch](https://github.com/Microsoft/MMdnn/issues/22)
198
199- [TensorFlow "mnist mlp model" to CNTK](https://github.com/Microsoft/MMdnn/issues/11)
200
201- [TensorFlow "Inception_v3" to MXNet](https://github.com/Microsoft/MMdnn/issues/30)
202
203- [Caffe "voc-fcn" to TensorFlow](https://github.com/Microsoft/MMdnn/issues/29)
204
205- [Caffe "AlexNet" to TensorFlow](https://github.com/Microsoft/MMdnn/issues/10)
206
207- [Caffe "inception_v4" to TensorFlow](https://github.com/Microsoft/MMdnn/issues/26)
208
209- [Caffe "VGG16_SOD" to TensorFlow](https://github.com/Microsoft/MMdnn/issues/27)
210
211- [Caffe "SqueezeNet v1.1" to CNTK](https://github.com/Microsoft/MMdnn/issues/48)
212
213---
214
215## Contributing
216
217Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to and actually do, grant us
218the rights to use your contribution. For details, visit https://cla.microsoft.com.
219
220When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
221a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
222provided by the bot. You will only need to do this once across all repos using our CLA.
223
224This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
225For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
226contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
227
228### Intermediate Representation
229
230The intermediate representation stores the **network architecture** in **protobuf binary** and **pre-trained weights** in **NumPy** native format.
231
232> [Note!] Currently the IR weights data is in NHWC (channel last) format.
233
234Details are in [ops.txt](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/common/IR/ops.pbtxt) and [graph.proto](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/common/IR/graph.proto). New operators and any comments are welcome.
235
236### Frameworks
237
238We are working on other frameworks conversion and visualization, such as PyTorch, CoreML and so on. We're investigating more RNN related operators. Any contributions and suggestions are welcome! Details in [Contribution Guideline](https://github.com/Microsoft/MMdnn/wiki/Contribution-Guideline).
239
240## Authors
241
242Yu Liu (Peking University): Project Developer & Maintainer
243
244Cheng CHEN (Microsoft Research Asia): Caffe, CNTK, CoreML Emitter, Keras, MXNet, TensorFlow
245
246Jiahao YAO (Peking University): CoreML, MXNet Emitter, PyTorch Parser; HomePage
247
248Ru ZHANG (Chinese Academy of Sciences): CoreML Emitter, DarkNet Parser, Keras, TensorFlow frozen graph Parser; Yolo and SSD models; Tests
249
250Yuhao ZHOU (Shanghai Jiao Tong University): MXNet
251
252Tingting QIN (Microsoft Research Asia): Caffe Emitter
253
254Tong ZHAN (Microsoft): ONNX Emitter
255
256Qianwen WANG (Hong Kong University of Science and Technology): Visualization
257
258## Acknowledgements
259
260Thanks to [Saumitro Dasgupta](https://github.com/ethereon), the initial code of *caffe -> IR converting* is references to his project [caffe-tensorflow](https://github.com/ethereon/caffe-tensorflow).
261
262## License
263Licensed under the [MIT](LICENSE) license.
264