You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CNTK model file is saved as [keras_to_cntk_inception_v3.dnn], generated by [2c33f7f278cb46be992f50226fcfdb5d.py] and [2c33f7f278cb46be992f50226fcfdb5d.npy].
53
53
```
54
54
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.
Copy file name to clipboardexpand all lines: docs/tf2pytorch.md
+32-9
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,14 @@ Source: TensorFlow
6
6
7
7
Destination: PyTorch
8
8
9
-
0. Prepare the TensorFlow model
9
+
---
10
+
11
+
## Prepare the TensorFlow model
10
12
11
13
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.
@@ -21,12 +23,12 @@ Model saved in file: ./imagenet_resnet_v2_152.ckpt
21
23
22
24
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.
23
25
24
-
1. Find the output node of the model
26
+
##Find the output node of the model
25
27
26
28
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.
@@ -39,10 +41,31 @@ The you can open URL above to find the output node of your model,
39
41
40
42
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)
41
43
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
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
Parse file [converted.pb] with binary format successfully.
63
86
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
68
91
69
92
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.
@@ -30,7 +30,6 @@ Model saved in file: ./imagenet_resnet_v2_152.ckpt
30
30
31
31
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.
32
32
33
-
34
33
Mainly extract code like:
35
34
36
35
```python
@@ -48,7 +47,7 @@ with slim.arg_scope(...):
48
47
When you prepared your checkpoint, you can find the output node name from the graph by Tensorboard.
0 commit comments