README.md 1.9 KB
Newer Older
J
Jason 已提交
1
### Warning
J
Jason 已提交
2
> **TensorFlow2Paddle is not stable and lots of tensorflow operations are not supported yet**
J
Jason 已提交
3

J
Jason 已提交
4
> **Only tested on vgg_16/resnet_v1_50/inception_v3 with is_training=False**
J
Jason 已提交
5

J
Jason 已提交
6
### Dependency
J
Jason 已提交
7 8 9
> 1. python = 2.7
> 2. PaddlePaddle >= 1.2.0
> 3. TensorFlow >= 1.12.0
J
Jason 已提交
10

J
Jason 已提交
11
**Notice:You can install PaddlePaddle and Tensorflow in different virtual environment since there's dependency conflict between PaddlePaddle and TensorFlow**
J
Jason 已提交
12

J
Jason 已提交
13 14
### Demo: How to change tensorflow resnet_v1_50 pretrained model to PaddlePaddle model for inference
#### 1. Get pretrained_model
J
Jason 已提交
15 16 17 18 19 20 21 22

```
git clone https://github.com/PaddlePaddle/X2Paddle.git
cd X2Paddle/TensorFlow2Paddle
wget http://download.tensorflow.org/models/resnet_v1_50_2016_08_28.tar.gz
tar xzvf resnet_v2_50_2017_04_14.tar.gz
```

J
Jason 已提交
23
#### 2. Change model to ckpt model with meta file
J
Jason 已提交
24 25 26 27 28 29


```
python demo/save_resnet_ckpt_model.py resnet_v1_50.ckpt ./new_ckpt_model
```

J
Jason 已提交
30
#### 3. Export PaddlePaddle model
J
Jason 已提交
31 32 33 34 35

```
python demo/export_resnet_to_paddle_model.py new_ckpt_model/resnet.meta new_ckpt_model fluid_model
```

J
Jason 已提交
36
#### 4. Test PaddlePaddle model
J
Jason 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
```python 
from fluid_model.mymodel import KitModel
import paddle.fluid as fluid
import numpy
import os

result = KitModel()
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())

var_list = list()
for f in os.listdir('./fluid_model'):
    f = f.split('/fluid')[-1]
    if f.startswith("param_"):
        var_list.append(fluid.default_main_program().global_block().var(f))
J
Jason 已提交
52
fluid.io.load_vars(exe, './fluid_model', vars=var_list)
J
Jason 已提交
53 54 55 56 57 58 59 60

test_data = numpy.random.rand(1, 3, 224, 224)
test_data = numpy.array(test_data, dtype='float32')
result = exe.run(fluid.default_main_program(), 
      feed={'input_0':numpy.array(img_data, dtype='float32')}, 
      fetch_list=[result])
print(result)
```
J
Jason 已提交
61 62

### Link
J
Jason 已提交
63
[MMdnn-Tensorflow](https://github.com/Microsoft/MMdnn/tree/master/mmdnn/conversion/tensorflow)