Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
ff5cdb1a
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看板
提交
ff5cdb1a
编写于
12月 15, 2020
作者:
S
SunAhong1993
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
262229f5
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
24 addition
and
48 deletion
+24
-48
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
+16
-35
x2paddle/op_mapper/static/onnx2paddle/opset9/__init__.py
x2paddle/op_mapper/static/onnx2paddle/opset9/__init__.py
+0
-1
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
+8
-12
未找到文件。
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
浏览文件 @
ff5cdb1a
...
@@ -1588,9 +1588,6 @@ class OpSet9():
...
@@ -1588,9 +1588,6 @@ class OpSet9():
@
print_mapping_info
@
print_mapping_info
def
ConvTranspose
(
self
,
node
):
def
ConvTranspose
(
self
,
node
):
op_name
=
name_generator
(
"conv"
,
self
.
nn_name2id
)
output_name
=
node
.
name
layer_outputs
=
[
op_name
,
output_name
]
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_w
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
val_w
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
val_b
=
None
val_b
=
None
...
@@ -1604,7 +1601,7 @@ class OpSet9():
...
@@ -1604,7 +1601,7 @@ class OpSet9():
assert
2
<=
convnd
<=
3
,
'only Conv2DTranspose and Conv3DTranspose supported'
assert
2
<=
convnd
<=
3
,
'only Conv2DTranspose and Conv3DTranspose supported'
num_in_channels
=
val_w
.
out_shapes
[
0
][
0
]
num_in_channels
=
val_w
.
out_shapes
[
0
][
0
]
num_out_channels
=
val_w
.
out_shapes
[
0
][
1
]
num_out_channels
=
val_w
.
out_shapes
[
0
][
1
]
paddle_op
=
'paddle.nn.
Conv{}DT
ranspose'
.
format
(
convnd
)
paddle_op
=
'paddle.nn.
functional.conv{}d_t
ranspose'
.
format
(
convnd
)
num_groups
=
node
.
get_attr
(
'group'
,
1
)
num_groups
=
node
.
get_attr
(
'group'
,
1
)
strides
=
node
.
get_attr
(
'strides'
,
[
1
]
*
convnd
)
strides
=
node
.
get_attr
(
'strides'
,
[
1
]
*
convnd
)
...
@@ -1622,37 +1619,21 @@ class OpSet9():
...
@@ -1622,37 +1619,21 @@ class OpSet9():
output_size
[
1
]
=
(
val_x
.
out_shapes
[
0
][
3
]
-
1
output_size
[
1
]
=
(
val_x
.
out_shapes
[
0
][
3
]
-
1
)
*
strides
[
1
]
-
2
*
paddings
[
1
]
+
dilations
[
1
]
*
(
)
*
strides
[
1
]
-
2
*
paddings
[
1
]
+
dilations
[
1
]
*
(
kernel_shape
[
1
]
-
1
)
+
1
+
out_padding
[
1
]
kernel_shape
[
1
]
-
1
)
+
1
+
out_padding
[
1
]
# Conv2DTranspose缺少output_size,只能在forward里头传进output_size
inputs_dict
=
{
'x'
:
val_x
if
isinstance
(
val_x
,
str
)
else
val_x
.
name
,
"weight"
:
val_w
.
name
}
layer_attrs
=
{
layer_attrs
=
{
'in_channels'
:
num_in_channels
,
"stride"
:
strides
,
'out_channels'
:
num_out_channels
,
"dilation"
:
dilations
,
'output_size'
:
output_size
or
None
,
"padding"
:
paddings
,
'kernel_size'
:
kernel_shape
,
"groups"
:
num_groups
,
'padding'
:
paddings
,
"output_size"
:
node
.
out_shapes
[
0
][
2
:]}
'stride'
:
strides
,
if
val_b
is
not
None
:
'dilation'
:
dilations
,
inputs_dict
[
"bias"
]
=
val_b
.
name
'groups'
:
num_groups
,
else
:
'weight_attr'
:
string
(
val_w
.
name
),
layer_attrs
[
"bias"
]
=
None
'bias_attr'
:
None
if
val_b
is
None
else
string
(
val_b
.
name
),
}
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
paddle_op
,
kernel
=
"paddle.nn.functional.conv2d_transpose"
,
inputs
=
{
"x"
:
val_x
.
name
},
inputs
=
inputs_dict
,
outputs
=
layer_outputs
,
outputs
=
[
node
.
name
],
**
layer_attrs
)
**
layer_attrs
)
# inputs_dict = {'x': val_x if isinstance(val_x, str) else val_x.name,
# "weight": val_w.name}
# layer_attrs = {
# "stride": strides,
# "dilation": dilations,
# "padding": paddings,
# "groups": num_groups,
# "output_size": node.out_shapes[0][2:]}
# if val_b is not None:
# inputs_dict["bias"] = val_b.name
# else:
# layer_attrs["bias"] = None
# self.paddle_graph.add_layer(
# kernel="paddle.nn.functional.conv2d_transpose",
# inputs=inputs_dict,
# outputs=[node.name],
# **layer_attrs)
x2paddle/op_mapper/static/onnx2paddle/opset9/__init__.py
浏览文件 @
ff5cdb1a
from
.opset
import
OpSet9
from
.opset
import
OpSet9
from
.custom_layer
import
custom_layers
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
浏览文件 @
ff5cdb1a
...
@@ -17,7 +17,6 @@ from x2paddle.core.graph import GraphNode
...
@@ -17,7 +17,6 @@ from x2paddle.core.graph import GraphNode
from
x2paddle.core.fluid_code
import
Layer
from
x2paddle.core.fluid_code
import
Layer
from
x2paddle.core.fluid_code
import
FluidCode
from
x2paddle.core.fluid_code
import
FluidCode
from
x2paddle.core.util
import
string
from
x2paddle.core.util
import
string
from
x2paddle.op_mapper.static.onnx2paddle.opset9.custom_layer
import
*
from
functools
import
reduce
from
functools
import
reduce
import
numpy
as
np
import
numpy
as
np
import
onnx
import
onnx
...
@@ -508,33 +507,30 @@ class OpSet9():
...
@@ -508,33 +507,30 @@ class OpSet9():
@
print_mapping_info
@
print_mapping_info
def
InstanceNormalization
(
self
,
node
):
def
InstanceNormalization
(
self
,
node
):
op_name
=
name_generator
(
"instanse_norm"
,
self
.
nn_name2id
)
output_name
=
node
.
name
layer_outputs
=
[
op_name
,
output_name
]
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_scale
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
val_scale
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
val_b
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
val_b
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
epsilon
=
node
.
get_attr
(
'epsilon'
,
1e-5
)
epsilon
=
node
.
get_attr
(
'epsilon'
,
1e-5
)
layer_attrs
=
{
layer_attrs
=
{
'eps
ilon
'
:
epsilon
,
'eps'
:
epsilon
,
}
}
dim
=
len
(
val_x
.
out_shapes
[
0
])
dim
=
len
(
val_x
.
out_shapes
[
0
])
if
dim
==
2
:
if
dim
==
2
:
layer_attrs
[
"data_format"
]
=
"NC"
layer_attrs
[
"data_format"
]
=
string
(
"NC"
)
elif
dim
==
3
:
elif
dim
==
3
:
layer_attrs
[
"data_format"
]
=
"NCL"
layer_attrs
[
"data_format"
]
=
string
(
"NCL"
)
elif
dim
==
4
:
elif
dim
==
4
:
layer_attrs
[
"data_format"
]
=
"NCHW"
layer_attrs
[
"data_format"
]
=
string
(
"NCHW"
)
elif
dim
==
5
:
elif
dim
==
5
:
layer_attrs
[
"data_format"
]
=
"NCDHW"
layer_attrs
[
"data_format"
]
=
string
(
"NCDHW"
)
else
:
else
:
raise
Exception
(
"The paddle only support 2D, 3D, 4D or 5D input in InstanceNormalization."
)
raise
Exception
(
"The paddle only support 2D, 3D, 4D or 5D input in InstanceNormalization."
)
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
paddle_op
,
"paddle.nn.functional.instance_norm"
,
inputs
=
{
"x"
:
val_x
.
name
,
inputs
=
{
"x"
:
val_x
.
name
,
"weight"
:
val_scale
.
name
,
"weight"
:
val_scale
.
name
,
"bias"
:
val_b
.
name
},
"bias"
:
val_b
.
name
},
outputs
=
layer_outputs
,
outputs
=
[
node
.
name
]
,
**
layer_attrs
)
**
layer_attrs
)
@
print_mapping_info
@
print_mapping_info
...
@@ -1577,7 +1573,7 @@ class OpSet9():
...
@@ -1577,7 +1573,7 @@ class OpSet9():
if
val_b
is
not
None
:
if
val_b
is
not
None
:
layer_inputs
[
"bias"
]
=
val_b
.
name
layer_inputs
[
"bias"
]
=
val_b
.
name
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
kernel
=
"paddle.nn.functional.conv2d_transpose"
,
kernel
=
paddle_op
,
inputs
=
layer_inputs
,
inputs
=
layer_inputs
,
outputs
=
[
node
.
name
],
outputs
=
[
node
.
name
],
**
layer_attrs
)
**
layer_attrs
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录