Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
e679f82c
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看板
提交
e679f82c
编写于
7月 07, 2020
作者:
M
mamingjie-China
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add Fill Minimun DepthToSpace Floor, and fix bug in Conv2D
上级
b434b7db
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
67 addition
and
9 deletion
+67
-9
x2paddle/op_mapper/tf_op_mapper_nhwc.py
x2paddle/op_mapper/tf_op_mapper_nhwc.py
+67
-9
未找到文件。
x2paddle/op_mapper/tf_op_mapper_nhwc.py
浏览文件 @
e679f82c
...
@@ -46,7 +46,8 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -46,7 +46,8 @@ class TFOpMapperNHWC(OpMapper):
'Softplus'
:
[
'softplus'
],
'Softplus'
:
[
'softplus'
],
'LeakyRelu'
:
[
'leaky_relu'
,
{
'LeakyRelu'
:
[
'leaky_relu'
,
{
'alpha'
:
'alpha'
'alpha'
:
'alpha'
}]
}],
'Floor'
:
[
'floor'
]
}
}
elementwise_ops
=
{
elementwise_ops
=
{
'Add'
:
'elementwise_add'
,
'Add'
:
'elementwise_add'
,
...
@@ -54,6 +55,7 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -54,6 +55,7 @@ class TFOpMapperNHWC(OpMapper):
'RealDiv'
:
'elementwise_div'
,
'RealDiv'
:
'elementwise_div'
,
'Sub'
:
'elementwise_sub'
,
'Sub'
:
'elementwise_sub'
,
'Maximum'
:
'elementwise_max'
,
'Maximum'
:
'elementwise_max'
,
'Minimum'
:
'elementwise_min'
,
'Mul'
:
'elementwise_mul'
,
'Mul'
:
'elementwise_mul'
,
'FloorDiv'
:
'elementwise_floordiv'
'FloorDiv'
:
'elementwise_floordiv'
}
}
...
@@ -202,6 +204,52 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -202,6 +204,52 @@ class TFOpMapperNHWC(OpMapper):
node
.
fluid_code
.
add_layer
(
node
.
fluid_code
.
add_layer
(
"transpose"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
"transpose"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
def
Fill
(
self
,
node
):
dims
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
input_value
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
assert
input_value
.
layer_type
==
"Const"
,
"Value of fill OP should be Const"
self
.
add_omit_nodes
(
input_value
.
layer_name
,
node
.
layer_name
)
input_value
=
input_value
.
value
input_dtype
=
string
(
input_value
.
dtype
)
attr
=
{
'value'
:
input_value
,
'dtype'
:
input_dtype
}
node
.
fluid_code
.
add_layer
(
"fill_constant"
,
inputs
=
dims
,
output
=
node
,
param_attr
=
attr
)
def
DepthToSpace
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
block_size
=
node
.
get_attr
(
"block_size"
)
data_format
=
node
.
get_attr
(
"data_format"
).
decode
()
if
data_format
==
"NHWC"
:
attr
=
{
"perm"
:
[
0
,
3
,
1
,
2
]}
node
.
fluid_code
.
add_layer
(
"transpose"
,
inputs
=
input
,
output
=
input
,
param_attr
=
attr
)
n
,
h
,
w
,
c
=
input
.
out_shapes
[
0
]
attr
=
{
'shape'
:
[
0
,
block_size
*
block_size
,
-
1
,
h
,
w
]}
node
.
fluid_code
.
add_layer
(
"reshape"
,
inputs
=
input
,
output
=
input
,
param_attr
=
attr
)
attr
=
{
'perm'
:
[
0
,
2
,
1
,
3
,
4
]}
node
.
fluid_code
.
add_layer
(
"transpose"
,
inputs
=
input
,
output
=
input
,
param_attr
=
attr
)
attr
=
{
'shape'
:
[
0
,
c
,
h
,
w
]}
node
.
fluid_code
.
add_layer
(
"reshape"
,
inputs
=
input
,
output
=
input
,
param_attr
=
attr
)
attr
=
{
'upscale_factor'
:
block_size
}
node
.
fluid_code
.
add_layer
(
"pixel_shuffle"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
if
data_format
==
"NHWC"
:
attr
=
{
"perm"
:
[
0
,
2
,
3
,
1
]}
node
.
fluid_code
.
add_layer
(
"transpose"
,
inputs
=
node
,
output
=
node
,
param_attr
=
attr
)
def
MaxPool
(
self
,
node
):
def
MaxPool
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
...
@@ -236,6 +284,7 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -236,6 +284,7 @@ class TFOpMapperNHWC(OpMapper):
def
Conv2D
(
self
,
node
):
def
Conv2D
(
self
,
node
):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
0
],
copy
=
True
)
kernel
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
kernel
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
1
],
copy
=
True
)
self
.
add_omit_nodes
(
kernel
.
layer_name
,
node
.
layer_name
)
k_size
=
kernel
.
out_shapes
[
0
]
k_size
=
kernel
.
out_shapes
[
0
]
strides
=
node
.
get_attr
(
"strides"
)
strides
=
node
.
get_attr
(
"strides"
)
...
@@ -245,10 +294,17 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -245,10 +294,17 @@ class TFOpMapperNHWC(OpMapper):
channel_first
=
data_format
==
"NCHW"
channel_first
=
data_format
==
"NCHW"
if
kernel
.
layer_type
==
'Const'
:
if
kernel
.
layer_type
==
'Const'
:
self
.
add_omit_nodes
(
kernel
.
layer_name
,
node
.
layer_name
)
kernel_value
=
kernel
.
value
kernel_value
=
kernel
.
value
self
.
weights
[
kernel
.
layer_name
.
replace
(
'/'
,
'_'
)]
=
numpy
.
transpose
(
kernel_weight_name
=
kernel
.
layer_name
.
replace
(
'/'
,
'_'
)
kernel_value
,
(
3
,
2
,
0
,
1
))
else
:
kernel_value
=
self
.
decoder
.
infer_tensor
(
kernel
)
if
kernel
.
layer_type
==
'Split'
:
kernel_weight_name
=
"{}_{}_kernel"
.
format
(
node
.
layer_name
,
kernel
.
layer_name
)
else
:
kernel_weight_name
=
kernel
.
layer_name
.
replace
(
'/'
,
'_'
)
self
.
weights
[
kernel_weight_name
]
=
numpy
.
transpose
(
kernel_value
,
(
3
,
2
,
0
,
1
))
if
not
channel_first
:
if
not
channel_first
:
strides
=
[
strides
[
i
]
for
i
in
[
0
,
3
,
1
,
2
]]
strides
=
[
strides
[
i
]
for
i
in
[
0
,
3
,
1
,
2
]]
...
@@ -257,10 +313,9 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -257,10 +313,9 @@ class TFOpMapperNHWC(OpMapper):
node
.
fluid_code
.
add_layer
(
node
.
fluid_code
.
add_layer
(
"transpose"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
"transpose"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
input
=
node
input
=
node
attr
=
{
attr
=
{
"bias_attr"
:
False
,
"bias_attr"
:
False
,
"param_attr"
:
string
(
kernel
.
layer
_name
),
"param_attr"
:
string
(
kernel
_weight
_name
),
"num_filters"
:
k_size
[
3
],
"num_filters"
:
k_size
[
3
],
"filter_size"
:
k_size
[
0
:
2
],
"filter_size"
:
k_size
[
0
:
2
],
"stride"
:
strides
[
2
:
4
],
"stride"
:
strides
[
2
:
4
],
...
@@ -700,13 +755,16 @@ class TFOpMapperNHWC(OpMapper):
...
@@ -700,13 +755,16 @@ class TFOpMapperNHWC(OpMapper):
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
2
],
copy
=
True
)
input
=
self
.
graph
.
get_node
(
node
.
layer
.
input
[
2
],
copy
=
True
)
assert
kernel
.
layer_type
==
"Const"
,
"Kernel of Conv2DBackpropInput should be Const"
assert
kernel
.
layer_type
==
"Const"
,
"Kernel of Conv2DBackpropInput should be Const"
assert
out_shape
.
layer_type
==
"Const"
,
"Out_shape of Conv2DBackpropInput should be Const"
self
.
add_omit_nodes
(
kernel
.
layer_name
,
node
.
layer_name
)
self
.
add_omit_nodes
(
kernel
.
layer_name
,
node
.
layer_name
)
out_shape
=
out_shape
.
value
.
tolist
()
self
.
add_omit_nodes
(
out_shape
.
layer_name
,
node
.
layer_name
)
self
.
add_omit_nodes
(
out_shape
.
layer_name
,
node
.
layer_name
)
if
out_shape
.
layer_type
==
"Const"
:
out_shape
=
out_shape
.
value
.
tolist
()
else
:
out_shape
=
self
.
decoder
.
infer_shape_tensor
(
out_shape
,
node
.
out_shapes
[
0
])
in_shape
=
input
.
out_shapes
[
0
]
in_shape
=
input
.
out_shapes
[
0
]
if
in_shape
.
count
(
-
1
)
>
2
:
if
in_shape
.
count
(
-
1
)
>
2
:
in_shape
=
self
.
decoder
.
infer_tensor
(
input
).
shape
in_shape
=
self
.
decoder
.
infer_tensor
(
input
).
shape
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录