Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
ebff5970
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看板
提交
ebff5970
编写于
1月 25, 2021
作者:
S
SunAhong1993
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the onnx
上级
b541e4a5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
87 addition
and
25 deletion
+87
-25
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
+50
-13
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
+37
-12
未找到文件。
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
浏览文件 @
ebff5970
...
@@ -119,19 +119,19 @@ class OpSet9():
...
@@ -119,19 +119,19 @@ class OpSet9():
# reduce function
# reduce function
'ReduceMean'
:
[
'paddle.mean'
,
'ReduceMean'
:
[
'paddle.mean'
,
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
keepdims
=
1
)],
dict
(
axes
=
None
,
keepdims
=
1
)],
'ReduceSum'
:
[
'paddle.sum'
,
'ReduceSum'
:
[
'paddle.sum'
,
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
keepdims
=
1
)],
dict
(
axes
=
None
,
keepdims
=
1
)],
'ReduceMin'
:
[
'paddle.min'
,
'ReduceMin'
:
[
'paddle.min'
,
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
keepdim
=
1
)],
dict
(
axes
=
None
,
keepdim
=
1
)],
'ReduceMax'
:
[
'paddle.max'
,
'ReduceMax'
:
[
'paddle.max'
,
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
keepdim
=
1
)],
dict
(
axes
=
None
,
keepdim
=
1
)],
'ReduceProd'
:
[
'paddle.prod'
,
'ReduceProd'
:
[
'paddle.prod'
,
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
keepdim
=
1
)],
dict
(
axes
=
None
,
keepdim
=
1
)],
# active function
# active function
'Relu'
:
[
'paddle.nn.ReLU'
],
'Relu'
:
[
'paddle.nn.ReLU'
],
'LeakyRelu'
:
[
'paddle.nn.LeakyReLU'
,
'LeakyRelu'
:
[
'paddle.nn.LeakyReLU'
,
...
@@ -150,6 +150,7 @@ class OpSet9():
...
@@ -150,6 +150,7 @@ class OpSet9():
dict
(
threshold
=
'threshold'
),
dict
(
threshold
=
'threshold'
),
dict
(
threshold
=
float
(
sys
.
maxsize
))],
dict
(
threshold
=
float
(
sys
.
maxsize
))],
'Exp'
:
[
'paddle.exp'
],
'Exp'
:
[
'paddle.exp'
],
'Log'
:
[
'paddle.log'
],
'LogSoftmax'
:
[
'paddle.nn.functional.log_softmax'
,
'LogSoftmax'
:
[
'paddle.nn.functional.log_softmax'
,
dict
(
axis
=
'axis'
),
dict
(
axis
=
'axis'
),
dict
(
axis
=
1
)],
dict
(
axis
=
1
)],
...
@@ -320,8 +321,15 @@ class OpSet9():
...
@@ -320,8 +321,15 @@ class OpSet9():
return
return
elif
node
.
layer_type
==
'Upsample'
:
elif
node
.
layer_type
==
'Upsample'
:
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
inputs
[
'scale_factor'
]
=
val_scales
self
.
paddle_graph
.
add_layer
(
"paddle.slice"
,
inputs
=
{
"input"
:
val_scales
.
name
},
outputs
=
[
val_scales
.
name
],
axes
=
[
0
],
starts
=
[
2
],
ends
=
[
4
])
inputs
[
'scale_factor'
]
=
val_scales
.
name
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
attrs
.
update
({
"align_corners"
:
False
,
attrs
.
update
({
"align_corners"
:
False
,
"mode"
:
string
(
mode
),
"mode"
:
string
(
mode
),
...
@@ -1013,13 +1021,12 @@ class OpSet9():
...
@@ -1013,13 +1021,12 @@ class OpSet9():
if
len
(
value
)
==
1
:
if
len
(
value
)
==
1
:
value
=
value
[
0
]
value
=
value
[
0
]
layer_attrs
=
{
layer_attrs
=
{
'shape'
:
val_shape
.
name
,
'dtype'
:
string
(
dtype
),
'dtype'
:
string
(
dtype
),
'fill_value'
:
value
'fill_value'
:
value
}
}
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
"paddle.full"
,
"paddle.full"
,
inputs
=
{},
inputs
=
{
'shape'
:
val_shape
.
name
},
outputs
=
[
node
.
name
],
outputs
=
[
node
.
name
],
**
layer_attrs
)
**
layer_attrs
)
...
@@ -1072,8 +1079,11 @@ class OpSet9():
...
@@ -1072,8 +1079,11 @@ class OpSet9():
}
}
outputs_list
=
list
()
outputs_list
=
list
()
if
isinstance
(
split
,
list
)
or
isinstance
(
split
,
tuple
):
if
isinstance
(
split
,
list
)
or
isinstance
(
split
,
tuple
):
for
i
in
range
(
len
(
split
)):
if
len
(
split
)
==
1
:
outputs_list
.
append
(
"{}_p{}"
.
format
(
node
.
layer_name
,
i
))
outputs_list
.
append
(
node
.
name
)
else
:
for
i
in
range
(
len
(
split
)):
outputs_list
.
append
(
"{}_p{}"
.
format
(
node
.
layer_name
,
i
))
else
:
else
:
outputs_list
.
append
(
node
.
name
)
outputs_list
.
append
(
node
.
name
)
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
...
@@ -1415,6 +1425,18 @@ class OpSet9():
...
@@ -1415,6 +1425,18 @@ class OpSet9():
else
:
else
:
if
mode
==
'channel'
:
if
mode
==
'channel'
:
slope_data
=
_const_weight_or_none
(
val_slope
)
slope_data
=
_const_weight_or_none
(
val_slope
)
if
slope_data
is
None
:
self
.
paddle_graph
.
add_layer
(
"paddle.reshape"
,
inputs
=
{
"x"
:
val_slope
.
name
},
outputs
=
[
val_slope
.
name
],
shape
=
[
shape_slope
[
0
]])
self
.
paddle_graph
.
add_layer
(
"paddle.nn.functional.prelu"
,
inputs
=
{
"x"
:
val_x
.
name
,
"weight"
:
val_slope
.
name
},
outputs
=
[
node
.
name
])
return
_rename_or_remove_weight
(
self
.
weights
,
val_slope
.
name
)
_rename_or_remove_weight
(
self
.
weights
,
val_slope
.
name
)
if
len
(
shape_slope
)
>
1
:
if
len
(
shape_slope
)
>
1
:
self
.
weights
[
op_name
+
'._weight'
]
=
np
.
reshape
(
slope_data
,
shape_slope
[
0
])
self
.
weights
[
op_name
+
'._weight'
]
=
np
.
reshape
(
slope_data
,
shape_slope
[
0
])
...
@@ -1464,7 +1486,7 @@ class OpSet9():
...
@@ -1464,7 +1486,7 @@ class OpSet9():
"paddle.greater_than"
,
"paddle.greater_than"
,
inputs
=
{
'x'
:
val_x
.
name
,
inputs
=
{
'x'
:
val_x
.
name
,
'y'
:
val_y
.
name
},
'y'
:
val_y
.
name
},
outputs
=
node
,
outputs
=
[
node
.
name
]
,
param_attr
=
None
)
param_attr
=
None
)
@
print_mapping_info
@
print_mapping_info
...
@@ -1521,7 +1543,7 @@ class OpSet9():
...
@@ -1521,7 +1543,7 @@ class OpSet9():
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
"paddle.transpose"
,
"paddle.transpose"
,
inputs
=
{
"x"
:
val_x
.
name
},
inputs
=
{
"x"
:
val_x
.
name
},
outputs
=
[
node
.
layer_na
em
],
outputs
=
[
node
.
layer_na
me
],
perm
=
[
1
,
0
])
perm
=
[
1
,
0
])
if
val_x_dim
>
1
:
if
val_x_dim
>
1
:
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
...
@@ -1977,3 +1999,18 @@ class OpSet9():
...
@@ -1977,3 +1999,18 @@ class OpSet9():
outputs
=
[
y_out
],
outputs
=
[
y_out
],
perm
=
[
0
,
2
,
1
,
3
]
perm
=
[
0
,
2
,
1
,
3
]
)
)
@
print_mapping_info
def
TopK
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_k
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
layer_attrs
=
dict
()
layer_attrs
[
"axis"
]
=
node
.
get_attr
(
'axis'
,
-
1
)
layer_attrs
[
"largest"
]
=
True
if
node
.
get_attr
(
'largest'
,
1
)
==
1
else
False
layer_attrs
[
"sorted"
]
=
True
if
node
.
get_attr
(
'sorted'
,
1
)
==
1
else
False
self
.
paddle_graph
.
add_layer
(
"paddle.topk"
,
inputs
=
{
"x"
:
val_x
.
name
,
"k"
:
val_k
.
name
},
outputs
=
[
"{}_p{}"
.
format
(
node
.
layer_name
,
0
),
"{}_p{}"
.
format
(
node
.
layer_name
,
1
)],
**
layer_attrs
)
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
浏览文件 @
ebff5970
...
@@ -96,19 +96,19 @@ class OpSet9():
...
@@ -96,19 +96,19 @@ class OpSet9():
# reduce function
# reduce function
'ReduceMean'
:
[
'paddle.mean'
,
'ReduceMean'
:
[
'paddle.mean'
,
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
keepdims
=
1
)],
dict
(
axes
=
None
,
keepdims
=
1
)],
'ReduceSum'
:
[
'paddle.sum'
,
'ReduceSum'
:
[
'paddle.sum'
,
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
keepdims
=
1
)],
dict
(
axes
=
None
,
keepdims
=
1
)],
'ReduceMin'
:
[
'paddle.min'
,
'ReduceMin'
:
[
'paddle.min'
,
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
keepdim
=
1
)],
dict
(
axes
=
None
,
keepdim
=
1
)],
'ReduceMax'
:
[
'paddle.max'
,
'ReduceMax'
:
[
'paddle.max'
,
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
keepdim
=
1
)],
dict
(
axes
=
None
,
keepdim
=
1
)],
'ReduceProd'
:
[
'paddle.prod'
,
'ReduceProd'
:
[
'paddle.prod'
,
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
axes
=
'axis'
,
keepdims
=
'keepdim'
),
dict
(
keepdim
=
1
)],
dict
(
axes
=
None
,
keepdim
=
1
)],
# active function
# active function
'Relu'
:
[
'paddle.nn.functional.relu'
],
'Relu'
:
[
'paddle.nn.functional.relu'
],
'LeakyRelu'
:
[
'paddle.nn.functional.leaky_relu'
,
'LeakyRelu'
:
[
'paddle.nn.functional.leaky_relu'
,
...
@@ -127,6 +127,7 @@ class OpSet9():
...
@@ -127,6 +127,7 @@ class OpSet9():
dict
(
threshold
=
'threshold'
),
dict
(
threshold
=
'threshold'
),
dict
(
threshold
=
float
(
sys
.
maxsize
))],
dict
(
threshold
=
float
(
sys
.
maxsize
))],
'Exp'
:
[
'paddle.exp'
],
'Exp'
:
[
'paddle.exp'
],
'Log'
:
[
'paddle.log'
],
'Softmax'
:
[
'paddle.nn.functional.softmax'
,
'Softmax'
:
[
'paddle.nn.functional.softmax'
,
dict
(
axis
=
'axis'
),
dict
(
axis
=
'axis'
),
dict
(
axis
=
1
)],
dict
(
axis
=
1
)],
...
@@ -283,7 +284,14 @@ class OpSet9():
...
@@ -283,7 +284,14 @@ class OpSet9():
return
return
elif
node
.
layer_type
==
'Upsample'
:
elif
node
.
layer_type
==
'Upsample'
:
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
inputs
[
'scale'
]
=
val_scales
self
.
paddle_graph
.
add_layer
(
"paddle.slice"
,
inputs
=
{
"input"
:
val_scales
.
name
},
outputs
=
[
val_scales
.
name
],
axes
=
[
0
],
starts
=
[
2
],
ends
=
[
4
])
inputs
[
'scale_factor'
]
=
val_scales
.
name
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
attrs
.
update
({
"align_corners"
:
False
,
attrs
.
update
({
"align_corners"
:
False
,
...
@@ -977,13 +985,12 @@ class OpSet9():
...
@@ -977,13 +985,12 @@ class OpSet9():
if
len
(
value
)
==
1
:
if
len
(
value
)
==
1
:
value
=
value
[
0
]
value
=
value
[
0
]
layer_attrs
=
{
layer_attrs
=
{
'shape'
:
val_shape
.
name
,
'dtype'
:
string
(
dtype
),
'dtype'
:
string
(
dtype
),
'fill_value'
:
value
'fill_value'
:
value
}
}
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
"paddle.full"
,
"paddle.full"
,
inputs
=
{},
inputs
=
{
'shape'
:
val_shape
.
name
},
outputs
=
[
node
.
name
],
outputs
=
[
node
.
name
],
**
layer_attrs
)
**
layer_attrs
)
...
@@ -1035,8 +1042,11 @@ class OpSet9():
...
@@ -1035,8 +1042,11 @@ class OpSet9():
}
}
outputs_list
=
list
()
outputs_list
=
list
()
if
isinstance
(
split
,
list
)
or
isinstance
(
split
,
tuple
):
if
isinstance
(
split
,
list
)
or
isinstance
(
split
,
tuple
):
for
i
in
range
(
len
(
split
)):
if
len
(
split
)
==
1
:
outputs_list
.
append
(
"{}_p{}"
.
format
(
node
.
layer_name
,
i
))
outputs_list
.
append
(
node
.
name
)
else
:
for
i
in
range
(
len
(
split
)):
outputs_list
.
append
(
"{}_p{}"
.
format
(
node
.
layer_name
,
i
))
else
:
else
:
outputs_list
.
append
(
node
.
name
)
outputs_list
.
append
(
node
.
name
)
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
...
@@ -1391,7 +1401,7 @@ class OpSet9():
...
@@ -1391,7 +1401,7 @@ class OpSet9():
"paddle.greater_than"
,
"paddle.greater_than"
,
inputs
=
{
'x'
:
val_x
.
name
,
inputs
=
{
'x'
:
val_x
.
name
,
'y'
:
val_y
.
name
},
'y'
:
val_y
.
name
},
outputs
=
node
,
outputs
=
[
node
.
name
]
,
param_attr
=
None
)
param_attr
=
None
)
@
print_mapping_info
@
print_mapping_info
...
@@ -1448,7 +1458,7 @@ class OpSet9():
...
@@ -1448,7 +1458,7 @@ class OpSet9():
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
"paddle.transpose"
,
"paddle.transpose"
,
inputs
=
{
"x"
:
val_x
.
name
},
inputs
=
{
"x"
:
val_x
.
name
},
outputs
=
[
node
.
layer_na
em
],
outputs
=
[
node
.
layer_na
me
],
perm
=
[
1
,
0
])
perm
=
[
1
,
0
])
if
val_x_dim
>
1
:
if
val_x_dim
>
1
:
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
...
@@ -1758,3 +1768,18 @@ class OpSet9():
...
@@ -1758,3 +1768,18 @@ class OpSet9():
"paddle.reciprocal"
,
"paddle.reciprocal"
,
inputs
=
{
"x"
:
val_x
.
name
},
inputs
=
{
"x"
:
val_x
.
name
},
outputs
=
[
node
.
name
])
outputs
=
[
node
.
name
])
@
print_mapping_info
def
TopK
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_k
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
layer_attrs
=
dict
()
layer_attrs
[
"axis"
]
=
node
.
get_attr
(
'axis'
,
-
1
)
layer_attrs
[
"largest"
]
=
True
if
node
.
get_attr
(
'largest'
,
1
)
==
1
else
False
layer_attrs
[
"sorted"
]
=
True
if
node
.
get_attr
(
'sorted'
,
1
)
==
1
else
False
self
.
paddle_graph
.
add_layer
(
"paddle.topk"
,
inputs
=
{
"x"
:
val_x
.
name
,
"k"
:
val_k
.
name
},
outputs
=
[
"{}_p{}"
.
format
(
node
.
layer_name
,
0
),
"{}_p{}"
.
format
(
node
.
layer_name
,
1
)],
**
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录