Skip to content

Commit 352e7fc

Browse files
committedMar 22, 2018
refine README for 0.1.4 version.
1 parent c6ec848 commit 352e7fc

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed
 

‎docs/keras2cntk.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ $ mmconvert -sf keras -iw imagenet_inception_v3.h5 -df cntk -om keras_to_cntk_in
5252
CNTK model file is saved as [keras_to_cntk_inception_v3.dnn], generated by [2c33f7f278cb46be992f50226fcfdb5d.py] and [2c33f7f278cb46be992f50226fcfdb5d.npy].
5353
```
5454

55-
Then you get the CNTK original model *keras_to_cntk_inception_v3.dnn* converted from Keras.
55+
Then you get the CNTK original model *keras_to_cntk_inception_v3.dnn* converted from Keras. **2c33f7f278cb46be992f50226fcfdb5d.py** and **2c33f7f278cb46be992f50226fcfdb5d.npy** are temporal files which will be removed automatically.
5656

5757
### **Step-by-step Command (for debugging)**
5858

‎docs/tf2pytorch.md

+32-9
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ Source: TensorFlow
66

77
Destination: PyTorch
88

9-
0. Prepare the TensorFlow model
9+
---
10+
11+
## Prepare the TensorFlow model
1012

1113
You need to prepare your pre-trained TensorFlow model firstly. And there is a pre-trained model extractor for frameworks to help you. You can refer it to extract your TensorFlow model checkpoint files.
1214

1315
```bash
14-
$ python -m mmdnn.conversion._script.extractModel -f tensorflow -n resnet_v2_152
16+
$ mmdownload -f tensorflow -n resnet_v2_152
1517

1618
Downloading file [./resnet_v2_152_2017_04_14.tar.gz] from [http://download.tensorflow.org/models/resnet_v2_152_2017_04_14.tar.gz]
1719
100% [......................................................................] 675629399 / 675629399
@@ -21,12 +23,12 @@ Model saved in file: ./imagenet_resnet_v2_152.ckpt
2123

2224
The you got the TensorFlow checkpoint files for *ResNet V2 152* model which is in your current working directory, including *imagenet_resnet_v2_152.ckpt.meta* for architecture , *imagenet_resnet_v2_152.ckpt.data-00000-of-00001* and *imagenet_resnet_v2_152.ckpt.index* for weights.
2325

24-
1. Find the output node of the model
26+
## Find the output node of the model
2527

2628
TensorFlow original checkpoint files contain many operators (if you tried tensorboard to visualize the graph) which is not used in our toolkits. we should prune them with specifying the output node of your model.
2729

2830
```bash
29-
$ python -m mmdnn.conversion.examples.tensorflow.vis_meta imagenet_resnet_v2_152.ckpt.meta ./log/
31+
$ mmvismeta imagenet_resnet_v2_152.ckpt.meta ./log/
3032
.
3133
.
3234
.
@@ -39,10 +41,31 @@ The you can open URL above to find the output node of your model,
3941

4042
like the squeeze node named *MMdnn_Output* we setup in our tensorflow model extractor. Detail information is in [TensorFlow README](https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/tensorflow/README.md)
4143

42-
2. Convert the pre-trained model files to intermediate representation
44+
## Convert TensorFlow Model to PyTorch
45+
46+
We provide two ways to convert models.
47+
48+
### **One-step Command**
49+
50+
Above MMdnn@0.1.4, we provide one command to achieve the conversion
51+
52+
```bash
53+
$ mmconvert -sf tensorflow -in imagenet_resnet_v2_152.ckpt.meta -iw imagenet_resnet_v2_152.ckpt --dstNode MMdnn_Output -df pytorch -om tf_to_pytorch_resnet_152.pth
54+
.
55+
.
56+
.
57+
PyTorch model file is saved as [tf_to_pytorch_resnet_152.pth], generated by [052eb72db9934edc90d8e1ffa48144d7.py] and [052eb72db9934edc90d8e1ffa48144d7.npy].
58+
```
59+
60+
Then you get the PyTorch original model *tf_to_pytorch_resnet_152.pth* converted from TensorFlow. **052eb72db9934edc90d8e1ffa48144d7.py** and **052eb72db9934edc90d8e1ffa48144d7.npy** are temporal files which will be removed automatically.
61+
62+
63+
### Step-by-step Command for debugging
64+
65+
#### Convert the pre-trained model files to intermediate representation
4366

4467
```bash
45-
$ python -m mmdnn.conversion._script.convertToIR -f tensorflow -n imagenet_resnet_v2_152.ckpt.meta -w imagenet_resnet_v2_152.ckpt --dstNode MMdnn_Output -o converted
68+
$ mmtoir -f tensorflow -n imagenet_resnet_v2_152.ckpt.meta -w imagenet_resnet_v2_152.ckpt --dstNode MMdnn_Output -o converted
4669

4770
Parse file [imagenet_resnet_v2_152.ckpt.meta] with binary format successfully.
4871
Tensorflow model file [imagenet_resnet_v2_152.ckpt.meta] loaded successfully.
@@ -54,10 +77,10 @@ IR weights are saved as [converted.npy].
5477

5578
Then you got the **intermediate representation** files *converted.json* for visualization, *converted.proto* and *converted.npy* for next steps.
5679

57-
3. Convert the IR files to PyTorch code
80+
#### Convert the IR files to PyTorch code
5881

5982
```bash
60-
$ python -m mmdnn.conversion._script.IRToCode -f pytorch -n converted.pb -w converted.npy -d converted_pytorch.py -dw converted_pytorch.npy
83+
$ mmtocode -f pytorch -n converted.pb -w converted.npy -d converted_pytorch.py -dw converted_pytorch.npy
6184

6285
Parse file [converted.pb] with binary format successfully.
6386
Target network code snippet is saved as [converted_pytorch.py].
@@ -68,7 +91,7 @@ And you will get a filename *converted_pytorch.py*, which contains the **origina
6891

6992
With the three steps, you have already converted the pre-trained TensorFlow *ResNet V2 152* models to PyTorch network building file *converted_pytorch.py* and weights file *converted_pytorch.npy*. You can use these two files to fine-tune training or inference.
7093

71-
4. Dump the original PyTorch model
94+
#### Dump the original PyTorch model
7295

7396
```bash
7497
$ python -m mmdnn.conversion.examples.pytorch.imagenet_test -n converted_pytorch.py -w converted_pytorch.npy --dump converted_pytorch.pth

‎mmdnn/conversion/examples/tensorflow/extractor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ def handle_checkpoint(cls, architecture, path):
155155

156156
init = tf.global_variables_initializer()
157157
with tf.Session() as sess:
158-
writer = tf.summary.FileWriter('./graphs', sess.graph)
158+
# tf.train.export_meta_graph("kit.meta", as_text=True)
159+
# writer = tf.summary.FileWriter('./graphs', sess.graph)
159160
writer.close()
160161
sess.run(init)
161162
saver = tf.train.Saver()
162-
tf.train.export_meta_graph("kit.meta", as_text=True)
163163
saver.restore(sess, path + cls.architecture_map[architecture]['filename'])
164164
save_path = saver.save(sess, path + "imagenet_{}.ckpt".format(architecture))
165165
print("Model saved in file: %s" % save_path)

‎mmdnn/conversion/tensorflow/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Support frameworks: ['resnet_v1_152', 'inception_v3', 'resnet_v2_50', 'resnet_v2
1919
Example:
2020

2121
```bash
22-
$ python -m mmdnn.conversion._script.extractModel -f tensorflow -n resnet_v2_152
22+
$ mmdownload -f tensorflow -n resnet_v2_152
2323

2424
Downloading file [./resnet_v2_152_2017_04_14.tar.gz] from [http://download.tensorflow.org/models/resnet_v2_152_2017_04_14.tar.gz]
2525
100% [......................................................................] 675629399 / 675629399
@@ -30,7 +30,6 @@ Model saved in file: ./imagenet_resnet_v2_152.ckpt
3030
3131
Then you can see files *imagenet_resnet_v2_152.ckpt.data-00000-of-00001*, *imagenet_resnet_v2_152.ckpt.index* and *imagenet_resnet_v2_152.ckpt.meta*, which can be handled by Tensorflow parser.
3232

33-
3433
Mainly extract code like:
3534

3635
```python
@@ -48,7 +47,7 @@ with slim.arg_scope(...):
4847
When you prepared your checkpoint, you can find the output node name from the graph by Tensorboard.
4948

5049
```bash
51-
$ python -m mmdnn.conversion.examples.tensorflow.vis_meta imagenet_resnet_v2_152.ckpt.meta ./logs/
50+
$ mmvismeta imagenet_resnet_v2_152.ckpt.meta ./logs/
5251

5352
TensorBoard 0.4.0rc3 at http://kit-station:6006 (Press CTRL+C to quit)
5453
```

0 commit comments

Comments
 (0)
Please sign in to comment.