@@ -3,9 +3,9 @@ Pytorch to Keras model convertor. Still beta for now.
3
3
4
4
## Important notice
5
5
6
- In that moment the only PyTorch 0.2 and PyTorch 0.4 (in master) are supported.
6
+ In that moment the only PyTorch 0.2 (deprecated) and PyTorch 0.4 (in master) are supported.
7
7
8
- To use converter properly, please, make changes in your ` ~/.keras/keras.json ` :
8
+ To use the converter properly, please, make changes in your ` ~/.keras/keras.json ` :
9
9
10
10
```
11
11
...
@@ -14,21 +14,19 @@ To use converter properly, please, make changes in your `~/.keras/keras.json`:
14
14
...
15
15
```
16
16
17
- Note 1: some layers parameters (like ceiling and etc) aren't supported.
17
+ ## How to build the latest PyTorch
18
18
19
- Note 2: recurrent layers aren't supported too .
19
+ Please, follow [ this guide ] ( https://github.com/pytorch/pytorch#from-source ) to compile the latest version .
20
20
21
- ## How to
21
+ ## How to use
22
22
23
- It's a convertor of pytorch graph to a keras (tensorflow backend) graph.
23
+ It's a convertor of pytorch graph to a Keras (Tensorflow backend) graph.
24
24
25
- Firstly, we need to load (or create) pytorch model.
26
-
27
- For example:
25
+ Firstly, we need to load (or create) pytorch model:
28
26
29
27
```
30
28
class TestConv2d(nn.Module):
31
- """Module for Conv2d conversion testing
29
+ """Module for Conv2d convertion testing
32
30
"""
33
31
34
32
def __init__(self, inp=10, out=16, kernel_size=3):
@@ -40,11 +38,12 @@ class TestConv2d(nn.Module):
40
38
return x
41
39
42
40
model = TestConv2d()
41
+
43
42
# load weights here
44
43
# model.load_state_dict(torch.load(path_to_weights.pth))
45
44
```
46
45
47
- The next step - iterate model with some data (for gradients computing) :
46
+ The next step - create a dummy variable with correct shapes :
48
47
49
48
```
50
49
input_np = np.random.uniform(0, 1, (1, 10, 32, 32))
@@ -55,10 +54,11 @@ We're using dummy-variable in order to trace the model.
55
54
56
55
```
57
56
from converter import pytorch_to_keras
58
- k_model = pytorch_to_keras(model, input_var, (10, 32, 32,), verbose=True) #we should specify shape of the input tensor
57
+ # we should specify shape of the input tensor
58
+ k_model = pytorch_to_keras(model, input_var, (10, 32, 32,), verbose=True)
59
59
```
60
60
61
- That's all! If all is ok, the Keras model stores to the ` k_model ` variable.
61
+ That's all! If all is ok, the Keras model is stores into the ` k_model ` variable.
62
62
63
63
## Supported layers
64
64
@@ -109,7 +109,7 @@ Misc:
109
109
110
110
* ResNet18
111
111
* ResNet50
112
- * SqueezeNet
112
+ * SqueezeNet (with ceil_mode=False)
113
113
* DenseNet
114
114
* AlexNet
115
115
* Inception (v4 only) (only with 0.2)
0 commit comments