Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
842ea89f
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看板
提交
842ea89f
编写于
12月 29, 2020
作者:
S
SunAhong1993
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
398d82d3
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
59 addition
and
43 deletion
+59
-43
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
+31
-22
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
+28
-21
未找到文件。
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
浏览文件 @
842ea89f
...
...
@@ -248,15 +248,22 @@ class OpSet9():
def
_interpolate
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
inputs
=
{
'x'
:
val_x
.
name
}
attrs
=
dict
()
if
node
.
layer_type
==
'Resize'
:
if
len
(
node
.
layer
.
input
)
==
2
:
# opset 10
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
inputs
[
'scale_factor'
]
=
val_scales
.
name
# TODO(syf): paddle.nn.functional.interpolate will support the length
# which is the same as the rank of input.
# inputs['scale_factor'] = val_scales.name
attrs
[
'scale_factor'
]
=
self
.
weights
[
val_scales
.
name
].
tolist
()[
2
:]
elif
len
(
node
.
layer
.
input
)
==
3
:
# opset 11
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
inputs
[
'scale_factor'
]
=
val_scales
.
name
# TODO(syf): paddle.nn.functional.interpolate will support the length
# which is the same as the rank of input.
# inputs['scale_factor'] = val_scales.name
attrs
[
'scale_factor'
]
=
self
.
weights
[
val_scales
.
name
].
tolist
()[
2
:]
elif
len
(
node
.
layer
.
input
)
==
4
:
# opset 11
val_sizes
=
self
.
graph
.
get_input_node
(
node
,
idx
=
3
,
copy
=
True
)
...
...
@@ -280,27 +287,15 @@ class OpSet9():
inputs
=
inputs
,
outputs
=
[
node
.
name
],
**
attrs
)
# # TODO(syf): all use
# inputs['out_shape'] = var_hw
# ipt = inputs.pop("x")
# inputs["input"] = ipt
# mode = node.get_attr('mode', 'nearest')
# attrs = {"align_corners": False}
# self.paddle_graph.add_layer(
# kernel="fluid.layers.resize_nearest",
# inputs=inputs,
# outputs=[node.name],
# **attrs)
return
elif
node
.
layer_type
==
'Upsample'
:
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
inputs
[
'scale'
]
=
val_scales
inputs
[
'scale
_factor
'
]
=
val_scales
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
attrs
=
{
"align_corners"
:
False
,
attrs
.
update
(
{
"align_corners"
:
False
,
"mode"
:
string
(
mode
),
"align_mode"
:
1
}
"align_mode"
:
1
})
self
.
paddle_graph
.
add_layer
(
kernel
=
"paddle.nn.functional.interpolate"
,
inputs
=
inputs
,
...
...
@@ -403,7 +398,7 @@ class OpSet9():
layer_attrs
[
'data_format'
]
=
string
(
'NCHW'
)
layer_attrs
[
'value'
]
=
value
else
:
paddle_op
=
'fluid.layers.pad'
paddle_op
=
'
paddle.
fluid.layers.pad'
layer_attrs
[
"pad_value"
]
=
value
if
len
(
pads
)
==
4
:
paddings
=
np
.
array
(
pads
).
reshape
(
...
...
@@ -931,16 +926,17 @@ class OpSet9():
'max'
:
max_value
,
'min'
:
min_value
,
}
self
.
paddle_graph
.
add_layer
(
'paddle.clip'
,
inputs
=
{
"x"
:
val_x
.
name
},
outputs
=
[
node
.
name
],
**
layer_attrs
)
else
:
max_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
min_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
max_value
=
_const_weight_or_none
(
max_ipt
)
min_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
max_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
min_value
=
_const_weight_or_none
(
min_ipt
)
max_value
=
_const_weight_or_none
(
max_ipt
)
if
max_value
.
shape
==
(
1
,
):
max_value
=
max_value
[
0
]
if
min_value
.
shape
==
(
1
,
):
...
...
@@ -1625,3 +1621,16 @@ class OpSet9():
inputs
=
inputs_dict
,
outputs
=
[
node
.
name
],
**
layer_attrs
)
@
print_mapping_info
def
ArgMax
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
axis
=
node
.
get_attr
(
'axis'
)
keepdims
=
False
if
node
.
get_attr
(
'keepdims'
)
==
0
else
True
layer_attrs
=
{
'axis'
:
axis
,
'keepdim'
:
keepdims
}
self
.
paddle_graph
.
add_layer
(
'paddle.argmax'
,
inputs
=
{
"x"
:
val_x
.
name
},
outputs
=
[
node
.
name
],
**
layer_attrs
)
\ No newline at end of file
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
浏览文件 @
842ea89f
...
...
@@ -86,7 +86,7 @@ class OpSet9():
elementwise_ops
=
{
'Add'
:
'paddle.add'
,
'Div'
:
'paddle.divide'
,
'Sub'
:
'paddle.sub
s
tract'
,
'Sub'
:
'paddle.subtract'
,
'Mul'
:
'paddle.multiply'
,
'Pow'
:
'paddle.pow'
,
}
...
...
@@ -238,15 +238,22 @@ class OpSet9():
def
_interpolate
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
inputs
=
{
'x'
:
val_x
.
name
}
attrs
=
dict
()
if
node
.
layer_type
==
'Resize'
:
if
len
(
node
.
layer
.
input
)
==
2
:
# opset 10
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
inputs
[
'scale_factor'
]
=
val_scales
.
name
# TODO(syf): paddle.nn.functional.interpolate will support the length
# which is the same as the rank of input.
# inputs['scale_factor'] = val_scales.name
attrs
[
'scale_factor'
]
=
self
.
params
[
val_scales
.
name
].
tolist
()[
2
:]
elif
len
(
node
.
layer
.
input
)
==
3
:
# opset 11
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
inputs
[
'scale_factor'
]
=
val_scales
.
name
# TODO(syf): paddle.nn.functional.interpolate will support the length
# which is the same as the rank of input.
# inputs['scale_factor'] = val_scales.name
attrs
[
'scale_factor'
]
=
self
.
params
[
val_scales
.
name
].
tolist
()[
2
:]
elif
len
(
node
.
layer
.
input
)
==
4
:
# opset 11
val_sizes
=
self
.
graph
.
get_input_node
(
node
,
idx
=
3
,
copy
=
True
)
...
...
@@ -270,27 +277,15 @@ class OpSet9():
inputs
=
inputs
,
outputs
=
[
node
.
name
],
**
attrs
)
# # TODO(syf): all use
# inputs['out_shape'] = var_hw
# ipt = inputs.pop("x")
# inputs["input"] = ipt
# mode = node.get_attr('mode', 'nearest')
# attrs = {"align_corners": False}
# self.paddle_graph.add_layer(
# kernel="fluid.layers.resize_nearest",
# inputs=inputs,
# outputs=[node.name],
# **attrs)
return
elif
node
.
layer_type
==
'Upsample'
:
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
inputs
[
'scale'
]
=
val_scales
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
attrs
=
{
"align_corners"
:
False
,
attrs
.
update
(
{
"align_corners"
:
False
,
"mode"
:
string
(
mode
),
"align_mode"
:
1
}
"align_mode"
:
1
}
)
self
.
paddle_graph
.
add_layer
(
kernel
=
"paddle.nn.functional.interpolate"
,
inputs
=
inputs
,
...
...
@@ -922,10 +917,10 @@ class OpSet9():
outputs
=
[
node
.
name
],
**
layer_attrs
)
else
:
max_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
min_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
max_value
=
_const_weight_or_none
(
max_ipt
)
min_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
max_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
min_value
=
_const_weight_or_none
(
min_ipt
)
max_value
=
_const_weight_or_none
(
max_ipt
)
if
max_value
.
shape
==
(
1
,
):
max_value
=
max_value
[
0
]
if
min_value
.
shape
==
(
1
,
):
...
...
@@ -1059,7 +1054,6 @@ class OpSet9():
inputs
=
{
'x'
:
val_x
if
isinstance
(
val_x
,
str
)
else
val_x
.
name
},
outputs
=
[
node
.
name
],
**
layer_attrs
)
# TODO(syf): op has diff
@
print_mapping_info
def
Concat
(
self
,
node
):
...
...
@@ -1581,3 +1575,16 @@ class OpSet9():
inputs
=
layer_inputs
,
outputs
=
[
node
.
name
],
**
layer_attrs
)
@
print_mapping_info
def
ArgMax
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
axis
=
node
.
get_attr
(
'axis'
)
keepdims
=
False
if
node
.
get_attr
(
'keepdims'
)
==
0
else
True
layer_attrs
=
{
'axis'
:
axis
,
'keepdim'
:
keepdims
}
self
.
paddle_graph
.
add_layer
(
'paddle.argmax'
,
inputs
=
{
"x"
:
val_x
.
name
},
outputs
=
[
node
.
name
],
**
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录