• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..24-Jul-2020-

README.mdH A D24-Jul-20204.9 KiB15199

__init__.pyH A D24-Jul-2020109 43

extra_layers.pyH A D24-Jul-20203.7 KiB10988

keras2_emitter.pyH A D24-Jul-202046.9 KiB1,3601,052

keras2_graph.pyH A D24-Jul-20201.8 KiB5733

keras2_parser.pyH A D24-Jul-202025.4 KiB794452

saver.pyH A D24-Jul-2020300 65

README.md

1# Keras README
2
3
4## Keras pre-trained model
5
6We tested some Keras pre-trained models to others, get more detail from [this file](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/examples/keras/extractor.py)
7
8|    Models    | Caffe | Keras | Tensorflow | CNTK | MXNet | PyTorch | CoreML | ONNX |
9| :----------: | :---: | :---: | :--------: | :--: | :---: | :-----: | :----: | :--: |
10|     Vgg16    |   √   |   √   |      √     |   √  |   √   |    √    |    √   |   √  |
11|     Vgg19    |   √   |   √   |      √     |   √  |   √   |    √    |    √   |   √  |
12| inception_v3 |   √   |   √   |      √     |   √  |   √   |    √    |    √   |   √  |
13|   resnet50   |   √   |   √   |      √     |   √  |   √   |    √    |    √   |   √  |
14|   densenet   |   √   |   √   |      √     |   √  |   √   |    √    |    √   |   √  |
15|   xception   |       |   √   |      √     |      |       |         |    √   |      |
16|   mobilenet  |       |   √   |      √     |      |       |         |    √   |   √  |
17|    nasnet    |       |   √   |      √     |      |       |         |    √   |      |
18|     yolo2    |       |   √   |            |      |       |         |        |   √  |
19
20**√** - Correctness tested
21
22**o** - Some difference after conversion
23
24**space** - not tested
25
26---
27
28# Usage
29
30## Download Keras pre-trained model
31
32```bash
33$ mmdownload -f keras
34
35Support frameworks: set(['resnet50', 'mobilenet', 'vgg19', 'vgg16', 'inception_v3', 'nasnet', 'inception_resnet_v2', 'xception', 'yolo2', 'densenet'])
36
37$ mmdownload -f keras -n resnet50 -o ./
38
39Keras model resnet50 is saved in [./imagenet_resnet50.h5]
40
41```
42---
43
44## One-step conversion
45
46Above MMdnn@0.1.4, we provide one command to achieve the conversion
47
48```bash
49$ mmconvert -sf keras -iw imagenet_resnet50.h5 -df cntk -om keras_resnet50.dnn
50.
51.
52.
53CNTK model file is saved as [keras_resnet50.dnn], generated by [8275ad5170f6441caa0b96a94d467b8e.py] and [8275ad5170f6441caa0b96a94d467b8e.npy].
54```
55
56Then you get the CNTK original model *keras_resnet50.dnn* converted from Caffe. Temporal files are removed automatically.
57
58---
59
60## Step-by-step conversion (for debugging)
61
62### Convert architecture from Keras to IR
63
64You can use following bash command to convert the network architecture [*imagenet_inceptionv3.json*] to IR architecture file [*inception_v3.pb*], [*inception_v3.json*]. You can convert only network structure to IR for visualization or training in other frameworks.
65
66```bash
67$ mmtoir -f keras -d inception_v3 -n imagenet_inceptionv3.json
68
69Using TensorFlow backend.
70IR network structure is saved as [inception_v3.json].
71IR network structure is saved as [inception_v3.pb].
72Warning: weights are not loaded.
73```
74
75
76
77### Convert model (including architecture and weights) from Keras to IR
78
79You can use following bash command to convert the network architecture [*imagenet_inceptionv3.json*] with weights [*imagenet_inceptionv3.h5*] to IR architecture file [*inception_v3.pb*], [*inception_v3.json*] and IR weights file [*inception_v3.npy*]
80
81```bash
82$ mmtoir -f keras -d inception_v3 -n imagenet_inceptionv3.json -w imagenet_inceptionv3.h5
83
84Using TensorFlow backend.
85.
86.
87.
88Network file [imagenet_inceptionv3.json] is loaded successfully.
89IR network structure is saved as [inception_v3.json].
90IR network structure is saved as [inception_v3.pb].
91IR weights are saved as [inception_v3.npy].
92```
93
94### Convert models from IR to Keras code snippet
95
96Since the generated Keras model code snippet can restore weights from IR weights file directly, you don't need to convert weights in this step.You can use following bash command to convert the IR architecture file [*inception_v3.pb*] to Keras Python code file[*keras_inception_v3.py*]
97
98```bash
99$ mmtocode -f keras --IRModelPath inception_v3.pb --IRWeightPath inception_v3.npy --dstModelPath keras_inception_v3.py
100
101Parse file [inception_v3.pb] with binary format successfully.
102Target network code snippet is saved as [keras_inception_v3.py].
103```
104
105### Generate Keras model from code snippet file and weight file
106
107After generating the keras code snippet, you can convert the Keras code snippet [*keras_inception_v3.py*] and IR weights file [*inception_v3.npy*] to Keras original model for further usage.
108
109```bash
110$ python -m mmdnn.conversion.examples.keras.imagenet_test -n keras_inception_v3.py -w inception_v3.npy --dump keras_inception_v3.h5
111
112Using TensorFlow backend.
113.
114.
115.
116Keras model file is saved as [keras_inception_v3.h5], generated by [keras_inception_v3.py] and [inception_v3.npy].
117```
118
119## Support Operators
120
121- Add
122- Concat
123- Relu
124- Softmax
125- Tanh
126- Sigmoid
127- Softplus
128- Softsign
129- HardSigmoid
130- Elu
131
132## Develop version
133
134Ubuntu 16.04 with
135
136- Keras 2.1.3
137
138- Tensorflow GPU 1.4.0
139
140@ 11/21/2017
141
142## Limitation
143
144- Lambda layer no support
145
146  - *inception_resnet_v2* pre-trained model no support
147
148- Currently no RNN related operations support
149
150- Model in model is not supported yet. We can implement it if needed.
151