Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
20265d73
X
X2Paddle
项目概览
PaddlePaddle
/
X2Paddle
大约 1 年 前同步成功
通知
328
Star
698
Fork
167
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
26
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
X2Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
26
Issue
26
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
20265d73
编写于
8月 11, 2020
作者:
J
Jason
提交者:
GitHub
8月 11, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #357 from mamingjie-China/develop
fix bug in 1.8.2
上级
432612f4
3e2459d1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
25 addition
and
12 deletion
+25
-12
README.md
README.md
+1
-1
x2paddle/convert.py
x2paddle/convert.py
+7
-6
x2paddle/op_mapper/tf_op_mapper_nhwc.py
x2paddle/op_mapper/tf_op_mapper_nhwc.py
+14
-2
x2paddle/optimizer/tf_optimizer.py
x2paddle/optimizer/tf_optimizer.py
+3
-3
未找到文件。
README.md
浏览文件 @
20265d73
...
@@ -58,7 +58,7 @@ x2paddle --framework=paddle2onnx --model=paddle_infer_model_dir --save_dir=onnx_
...
@@ -58,7 +58,7 @@ x2paddle --framework=paddle2onnx --model=paddle_infer_model_dir --save_dir=onnx_
|--save_dir | 指定转换后的模型保存目录路径 |
|--save_dir | 指定转换后的模型保存目录路径 |
|--model | 当framework为tensorflow/onnx时,该参数指定tensorflow的pb模型文件或onnx模型路径 |
|--model | 当framework为tensorflow/onnx时,该参数指定tensorflow的pb模型文件或onnx模型路径 |
|--caffe_proto |
**[可选]**
由caffe.proto编译成caffe_pb2.py文件的存放路径,当存在自定义Layer时使用,默认为None |
|--caffe_proto |
**[可选]**
由caffe.proto编译成caffe_pb2.py文件的存放路径,当存在自定义Layer时使用,默认为None |
|--without_data_format_optimization |
**[可选]**
For TensorFlow, 当指定该参数
时,关闭NHWC->NCHW的优化,见
[
文档Q2
](
FAQ.md
)
|
|--without_data_format_optimization |
**[可选]**
For TensorFlow, 当指定该参数
为False时,打开NHWC->NCHW的优化,见
[
文档Q2
](
FAQ.md
)
,默认为True
|
|--define_input_shape |
**[可选]**
For TensorFlow, 当指定该参数时,强制用户输入每个Placeholder的shape,见
[
文档Q2
](
FAQ.md
)
|
|--define_input_shape |
**[可选]**
For TensorFlow, 当指定该参数时,强制用户输入每个Placeholder的shape,见
[
文档Q2
](
FAQ.md
)
|
|--params_merge |
**[可选]**
当指定该参数时,转换完成后,inference_model中的所有模型参数将合并保存为一个文件__params__ |
|--params_merge |
**[可选]**
当指定该参数时,转换完成后,inference_model中的所有模型参数将合并保存为一个文件__params__ |
|--onnx_opset |
**[可选]**
当framework为paddle2onnx时,该参数可设置转换为ONNX的OpSet版本,目前支持9、10、11,默认为10 |
|--onnx_opset |
**[可选]**
当framework为paddle2onnx时,该参数可设置转换为ONNX的OpSet版本,目前支持9、10、11,默认为10 |
...
...
x2paddle/convert.py
浏览文件 @
20265d73
...
@@ -66,8 +66,8 @@ def arg_parser():
...
@@ -66,8 +66,8 @@ def arg_parser():
parser
.
add_argument
(
parser
.
add_argument
(
"--without_data_format_optimization"
,
"--without_data_format_optimization"
,
"-wo"
,
"-wo"
,
action
=
"store_true"
,
type
=
_text_type
,
default
=
False
,
default
=
"True"
,
help
=
"tf model conversion without data format optimization"
)
help
=
"tf model conversion without data format optimization"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--define_input_shape"
,
"--define_input_shape"
,
...
@@ -93,7 +93,7 @@ def arg_parser():
...
@@ -93,7 +93,7 @@ def arg_parser():
def
tf2paddle
(
model_path
,
def
tf2paddle
(
model_path
,
save_dir
,
save_dir
,
without_data_format_optimization
=
False
,
without_data_format_optimization
,
define_input_shape
=
False
,
define_input_shape
=
False
,
params_merge
=
False
):
params_merge
=
False
):
# check tensorflow installation and version
# check tensorflow installation and version
...
@@ -240,11 +240,12 @@ def main():
...
@@ -240,11 +240,12 @@ def main():
if
args
.
framework
==
"tensorflow"
:
if
args
.
framework
==
"tensorflow"
:
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
without_data_format_optimization
=
False
assert
args
.
without_data_format_optimization
in
[
"True"
,
"False"
],
"--the param without_data_format_optimization should be defined True or False"
define_input_shape
=
False
define_input_shape
=
False
params_merge
=
False
params_merge
=
False
if
args
.
without_data_format_optimization
:
without_data_format_optimization
=
True
if
args
.
without_data_format_optimization
==
"True"
else
False
without_data_format_optimization
=
True
if
args
.
define_input_shape
:
if
args
.
define_input_shape
:
define_input_shape
=
True
define_input_shape
=
True
if
args
.
params_merge
:
if
args
.
params_merge
:
...
...
x2paddle/op_mapper/tf_op_mapper_nhwc.py
浏览文件 @
20265d73
...
@@ -1068,13 +1068,25 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -1068,13 +1068,25 @@ class TFOpMapperNHWC(OpMapper):
axis
=
axis
.
value
.
tolist
()
axis
=
axis
.
value
.
tolist
()
assert
axis
==
0
,
"Only support axis=0 in GatherV2 OP"
assert
axis
==
0
,
"Only support axis=0 in GatherV2 OP"
attr
=
{
'overwrite'
:
False
}
attr
=
{
'overwrite'
:
False
}
embeddings_shape
=
embeddings
.
out_shapes
[
0
][
-
1
]
reshape_list
=
list
()
reshape_name
=
index
.
layer_name
if
len
(
index
.
out_shapes
[
0
])
!=
1
:
if
len
(
index
.
out_shapes
[
0
])
!=
1
:
reshape_list
=
index
.
out_shapes
[
0
]
reshape_attr
=
{
"shape"
:
[
-
1
]}
reshape_attr
=
{
"shape"
:
[
-
1
]}
reshape_name
=
"{}_reshape"
.
format
(
index
.
layer_name
)
node
.
fluid_code
.
add_layer
(
node
.
fluid_code
.
add_layer
(
"reshape"
,
inputs
=
index
,
output
=
index
,
param_attr
=
reshape_attr
)
"reshape"
,
inputs
=
{
'input'
:
embeddings
,
'index'
:
index
}
inputs
=
index
,
output
=
reshape_name
,
param_attr
=
reshape_attr
)
inputs
=
{
'input'
:
embeddings
,
'index'
:
reshape_name
}
node
.
fluid_code
.
add_layer
(
node
.
fluid_code
.
add_layer
(
"gather"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
attr
)
"gather"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
attr
)
if
len
(
index
.
out_shapes
[
0
])
!=
1
:
reshape_attr
=
{
"shape"
:
reshape_list
+
[
embeddings_shape
]}
node
.
fluid_code
.
add_layer
(
"reshape"
,
inputs
=
node
,
output
=
node
,
param_attr
=
reshape_attr
)
def
OneShotIterator
(
self
,
node
):
def
OneShotIterator
(
self
,
node
):
return
self
.
Placeholder
(
node
)
return
self
.
Placeholder
(
node
)
...
...
x2paddle/optimizer/tf_optimizer.py
浏览文件 @
20265d73
...
@@ -864,8 +864,8 @@ class TFOptimizer(object):
...
@@ -864,8 +864,8 @@ class TFOptimizer(object):
weight
=
numpy
.
expand_dims
(
weight
,
3
)
weight
=
numpy
.
expand_dims
(
weight
,
3
)
self
.
op_mapper
.
weights
[
in_nodes3
[
0
].
layer_name
]
=
weight
self
.
op_mapper
.
weights
[
in_nodes3
[
0
].
layer_name
]
=
weight
# fix bug in Paddle1.8.3 and may change in next version.
# fix bug in Paddle1.8.3 and may change in next version.
self
.
op_mapper
.
weights
[
in_nodes3
[
0
].
layer_name
+
#
self.op_mapper.weights[in_nodes3[0].layer_name +
'_1'
]
=
weight
.
reshape
(
1
,
-
1
)
#
'_1'] = weight.reshape(1, -1)
in_nodes3
[
0
].
fluid_code
.
layers
[
0
].
param_attr
[
"shape"
]
=
[
in_nodes3
[
0
].
fluid_code
.
layers
[
0
].
param_attr
[
"shape"
]
=
[
1
,
in_shape
[
-
1
],
1
,
1
1
,
in_shape
[
-
1
],
1
,
1
]
]
...
@@ -888,7 +888,7 @@ class TFOptimizer(object):
...
@@ -888,7 +888,7 @@ class TFOptimizer(object):
node
.
fluid_code
.
clear
()
node
.
fluid_code
.
clear
()
attr
=
{
attr
=
{
"mode"
:
string
(
mode
),
"mode"
:
string
(
mode
),
"param_attr"
:
string
(
in_nodes3
[
0
].
layer_name
+
"_1"
)
"param_attr"
:
string
(
in_nodes3
[
0
].
layer_name
)
}
}
node
.
fluid_code
.
add_layer
(
node
.
fluid_code
.
add_layer
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录