Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tf2paddle to convert models #483

Merged
merged 4 commits into from
Dec 4, 2017

Conversation

guoshengCS
Copy link
Collaborator

Fix #482


为使TensorFlow模型中的variable能够正确对应到PaddlePaddle模型中layer的参数,正确完成转换,模型转换具有如下约束:

- 支持TensorFlow中conv2d,batchnorm,fc这三种带有trainable variable的Operator中参数的转换。- TensorFlow配置中同一Operator内的variable属于相同的scope,以此将variable划分到不同的layer。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm ^M

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@lcy-seso lcy-seso force-pushed the add-tf2paddle branch 8 times, most recently from 9e7e9ae to fc163e6 Compare December 4, 2017 05:39
```
1. 目前仅支持将TensorFlow中 `conv2d`,`batchnorm`,`fc`这三种带有可学习`Variable`的Operator训练出的参数向PaddlePaddle模型参数转换。
1. TensorFlow网络配置中同一Operator内的`Variable`属于相同的scope,以此为依据将`Variable`划分到不同的`paddle.layer`。
1. `conv2d`、`batchnorm`、`fc`的scope需分别包含`conv`、`bn`、`fc`,以此获取对应`paddle.layer`的类型。也可以通过为`TFModelConverter`传入`layer_type_map`的`dict`,将scope映射到对应的`paddle.layer`的type来规避此项约束。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 conv2dbatchnormfc 能否换成精确的 TensorFlow 中的调用接口,比如 :conv2d --> tf.nn.conv2d,方便使用者在看到文档时候,能够精确定位到自己配置中的 operator。

1. 目前仅支持将TensorFlow中 `conv2d`,`batchnorm`,`fc`这三种带有可学习`Variable`的Operator训练出的参数向PaddlePaddle模型参数转换。
1. TensorFlow网络配置中同一Operator内的`Variable`属于相同的scope,以此为依据将`Variable`划分到不同的`paddle.layer`。
1. `conv2d`、`batchnorm`、`fc`的scope需分别包含`conv`、`bn`、`fc`,以此获取对应`paddle.layer`的类型。也可以通过为`TFModelConverter`传入`layer_type_map`的`dict`,将scope映射到对应的`paddle.layer`的type来规避此项约束。
1. `conv2d`、`fc`中`Variable`的顺序为:先可学习`Weight`后`Bias`;`batchnorm`中`Variable`的顺序为:`scale`、`shift`、`mean`、`var`,请注意参数存储的顺序将`Variable`对应到`paddle.layer.batch_norm`相应位置的参数。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,请把 conv2dbatchnormfc 换成精确的 TensorFlow 中的调用接口。

1. TensorFlow网络配置中同一Operator内的`Variable`属于相同的scope,以此为依据将`Variable`划分到不同的`paddle.layer`。
1. `conv2d`、`batchnorm`、`fc`的scope需分别包含`conv`、`bn`、`fc`,以此获取对应`paddle.layer`的类型。也可以通过为`TFModelConverter`传入`layer_type_map`的`dict`,将scope映射到对应的`paddle.layer`的type来规避此项约束。
1. `conv2d`、`fc`中`Variable`的顺序为:先可学习`Weight`后`Bias`;`batchnorm`中`Variable`的顺序为:`scale`、`shift`、`mean`、`var`,请注意参数存储的顺序将`Variable`对应到`paddle.layer.batch_norm`相应位置的参数。
1. TensorFlow网络拓扑顺序需和PaddlePaddle网络拓扑顺序一致,尤其注意具有分支时左右分支的顺序。这是针对模型转换和PaddlePaddle网络配置均使用PaddlePaddle默认参数命名的情况,此时将根据拓扑顺序进行参数命名。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句话我不是非常理解 “尤其注意具有分支时左右分支的顺序”,能否进一步解释一下。这里值的“左右分支”是什么呢?

Copy link
Collaborator

@lcy-seso lcy-seso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lcy-seso lcy-seso merged commit 08c8532 into PaddlePaddle:develop Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants