Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
bb7b74ec
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看板
未验证
提交
bb7b74ec
编写于
12月 28, 2020
作者:
J
Jason
提交者:
GitHub
12月 28, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #471 from PaddlePaddle/onnx
fix the onnx bug
上级
89a673c1
86e20086
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
53 addition
and
23 deletion
+53
-23
x2paddle/decoder/onnx_decoder.py
x2paddle/decoder/onnx_decoder.py
+20
-5
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
+18
-10
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
+15
-8
未找到文件。
x2paddle/decoder/onnx_decoder.py
浏览文件 @
bb7b74ec
...
@@ -205,7 +205,7 @@ class ONNXGraph(Graph):
...
@@ -205,7 +205,7 @@ class ONNXGraph(Graph):
shape
=
raw_input
(
shape
=
raw_input
(
"Shape of Input(e.g. -1,3,224,224), enter 'N' to skip: "
"Shape of Input(e.g. -1,3,224,224), enter 'N' to skip: "
)
)
except
:
except
NameError
:
shape
=
input
(
shape
=
input
(
"Shape of Input(e.g. -1,3,224,224), enter 'N' to skip: "
"Shape of Input(e.g. -1,3,224,224), enter 'N' to skip: "
)
)
...
@@ -302,7 +302,18 @@ class ONNXGraph(Graph):
...
@@ -302,7 +302,18 @@ class ONNXGraph(Graph):
if
opt
==
in_node
:
if
opt
==
in_node
:
self
.
connect
(
nd
.
name
,
layer_name
)
self
.
connect
(
nd
.
name
,
layer_name
)
flag
=
1
flag
=
1
node
.
which_child
[
nd
.
name
]
=
idx
if
nd
.
name
in
node
.
which_child
:
for
n_i
,
n_ipt
in
enumerate
(
node
.
inputs
):
if
first_i
==
n_i
:
continue
if
n_ipt
==
nd
.
name
:
new_nd_name
=
"{}/{}"
.
format
(
nd
.
name
,
n_i
)
if
new_nd_name
not
in
node
.
which_child
:
node
.
which_child
[
new_nd_name
]
=
idx
break
else
:
first_i
=
node
.
inputs
.
index
(
nd
.
name
)
node
.
which_child
[
nd
.
name
]
=
idx
self
.
node_map
[
nd
.
name
].
index
=
0
self
.
node_map
[
nd
.
name
].
index
=
0
break
break
if
flag
==
1
:
if
flag
==
1
:
...
@@ -318,11 +329,15 @@ class ONNXGraph(Graph):
...
@@ -318,11 +329,15 @@ class ONNXGraph(Graph):
if
len
(
node
.
which_child
)
==
0
:
if
len
(
node
.
which_child
)
==
0
:
ipt_node
=
super
(
ONNXGraph
,
self
).
get_node
(
node
.
inputs
[
idx
],
copy
)
ipt_node
=
super
(
ONNXGraph
,
self
).
get_node
(
node
.
inputs
[
idx
],
copy
)
return
ipt_node
return
ipt_node
else
:
else
:
ipt_node
=
super
(
ONNXGraph
,
self
).
get_node
(
node
.
inputs
[
idx
],
copy
)
ipt_node
=
super
(
ONNXGraph
,
self
).
get_node
(
node
.
inputs
[
idx
],
copy
)
if
ipt_node
.
layer_name
in
node
.
which_child
:
new_ipt_name
=
"{}/{}"
.
format
(
ipt_node
.
layer_name
,
idx
)
ipt_node
.
index
=
node
.
which_child
[
ipt_node
.
layer_name
]
if
new_ipt_name
in
node
.
which_child
:
ipt_node
.
index
=
node
.
which_child
[
new_ipt_name
]
else
:
if
ipt_node
.
layer_name
in
node
.
which_child
:
ipt_node
.
index
=
node
.
which_child
[
ipt_node
.
layer_name
]
return
ipt_node
return
ipt_node
...
...
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
浏览文件 @
bb7b74ec
...
@@ -250,15 +250,22 @@ class OpSet9():
...
@@ -250,15 +250,22 @@ class OpSet9():
def
_interpolate
(
self
,
node
):
def
_interpolate
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
inputs
=
{
'x'
:
val_x
.
name
}
inputs
=
{
'x'
:
val_x
.
name
}
attrs
=
dict
()
if
node
.
layer_type
==
'Resize'
:
if
node
.
layer_type
==
'Resize'
:
if
len
(
node
.
layer
.
input
)
==
2
:
if
len
(
node
.
layer
.
input
)
==
2
:
# opset 10
# opset 10
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
.
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
:
elif
len
(
node
.
layer
.
input
)
==
3
:
# opset 11
# opset 11
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
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
:
elif
len
(
node
.
layer
.
input
)
==
4
:
# opset 11
# opset 11
val_sizes
=
self
.
graph
.
get_input_node
(
node
,
idx
=
3
,
copy
=
True
)
val_sizes
=
self
.
graph
.
get_input_node
(
node
,
idx
=
3
,
copy
=
True
)
...
@@ -281,7 +288,7 @@ class OpSet9():
...
@@ -281,7 +288,7 @@ class OpSet9():
ipt
=
inputs
.
pop
(
"x"
)
ipt
=
inputs
.
pop
(
"x"
)
inputs
[
"input"
]
=
ipt
inputs
[
"input"
]
=
ipt
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
attrs
=
{
"align_corners"
:
False
}
attrs
.
update
({
"align_corners"
:
False
})
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
kernel
=
"fluid.layers.resize_nearest"
,
kernel
=
"fluid.layers.resize_nearest"
,
inputs
=
inputs
,
inputs
=
inputs
,
...
@@ -290,12 +297,12 @@ class OpSet9():
...
@@ -290,12 +297,12 @@ 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
inputs
[
'scale
_factor
'
]
=
val_scales
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
attrs
=
{
"align_corners"
:
False
,
attrs
.
update
(
{
"align_corners"
:
False
,
"mode"
:
string
(
mode
),
"mode"
:
string
(
mode
),
"align_mode"
:
1
}
"align_mode"
:
1
})
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
kernel
=
"paddle.nn.functional.interpolate"
,
kernel
=
"paddle.nn.functional.interpolate"
,
inputs
=
inputs
,
inputs
=
inputs
,
...
@@ -926,16 +933,17 @@ class OpSet9():
...
@@ -926,16 +933,17 @@ class OpSet9():
'max'
:
max_value
,
'max'
:
max_value
,
'min'
:
min_value
,
'min'
:
min_value
,
}
}
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
'paddle.clip'
,
'paddle.clip'
,
inputs
=
{
"x"
:
val_x
.
name
},
inputs
=
{
"x"
:
val_x
.
name
},
outputs
=
[
node
.
name
],
outputs
=
[
node
.
name
],
**
layer_attrs
)
**
layer_attrs
)
else
:
else
:
max_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
min_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
min_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
max_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
max_value
=
_const_weight_or_none
(
max_ipt
)
min_value
=
_const_weight_or_none
(
min_ipt
)
min_value
=
_const_weight_or_none
(
min_ipt
)
max_value
=
_const_weight_or_none
(
max_ipt
)
if
max_value
.
shape
==
(
1
,
):
if
max_value
.
shape
==
(
1
,
):
max_value
=
max_value
[
0
]
max_value
=
max_value
[
0
]
if
min_value
.
shape
==
(
1
,
):
if
min_value
.
shape
==
(
1
,
):
...
...
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
浏览文件 @
bb7b74ec
...
@@ -240,15 +240,22 @@ class OpSet9():
...
@@ -240,15 +240,22 @@ class OpSet9():
def
_interpolate
(
self
,
node
):
def
_interpolate
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
inputs
=
{
'x'
:
val_x
.
name
}
inputs
=
{
'x'
:
val_x
.
name
}
attrs
=
dict
()
if
node
.
layer_type
==
'Resize'
:
if
node
.
layer_type
==
'Resize'
:
if
len
(
node
.
layer
.
input
)
==
2
:
if
len
(
node
.
layer
.
input
)
==
2
:
# opset 10
# opset 10
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
.
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
:
elif
len
(
node
.
layer
.
input
)
==
3
:
# opset 11
# opset 11
val_scales
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
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
:
elif
len
(
node
.
layer
.
input
)
==
4
:
# opset 11
# opset 11
val_sizes
=
self
.
graph
.
get_input_node
(
node
,
idx
=
3
,
copy
=
True
)
val_sizes
=
self
.
graph
.
get_input_node
(
node
,
idx
=
3
,
copy
=
True
)
...
@@ -271,7 +278,7 @@ class OpSet9():
...
@@ -271,7 +278,7 @@ class OpSet9():
ipt
=
inputs
.
pop
(
"x"
)
ipt
=
inputs
.
pop
(
"x"
)
inputs
[
"input"
]
=
ipt
inputs
[
"input"
]
=
ipt
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
attrs
=
{
"align_corners"
:
False
}
attrs
.
update
({
"align_corners"
:
False
})
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
kernel
=
"fluid.layers.resize_nearest"
,
kernel
=
"fluid.layers.resize_nearest"
,
inputs
=
inputs
,
inputs
=
inputs
,
...
@@ -283,9 +290,9 @@ class OpSet9():
...
@@ -283,9 +290,9 @@ class OpSet9():
inputs
[
'scale'
]
=
val_scales
inputs
[
'scale'
]
=
val_scales
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
mode
=
node
.
get_attr
(
'mode'
,
'nearest'
)
attrs
=
{
"align_corners"
:
False
,
attrs
.
update
(
{
"align_corners"
:
False
,
"mode"
:
string
(
mode
),
"mode"
:
string
(
mode
),
"align_mode"
:
1
}
"align_mode"
:
1
}
)
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
kernel
=
"paddle.nn.functional.interpolate"
,
kernel
=
"paddle.nn.functional.interpolate"
,
inputs
=
inputs
,
inputs
=
inputs
,
...
@@ -917,10 +924,10 @@ class OpSet9():
...
@@ -917,10 +924,10 @@ class OpSet9():
outputs
=
[
node
.
name
],
outputs
=
[
node
.
name
],
**
layer_attrs
)
**
layer_attrs
)
else
:
else
:
max_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
min_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
min_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
max_ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
max_value
=
_const_weight_or_none
(
max_ipt
)
min_value
=
_const_weight_or_none
(
min_ipt
)
min_value
=
_const_weight_or_none
(
min_ipt
)
max_value
=
_const_weight_or_none
(
max_ipt
)
if
max_value
.
shape
==
(
1
,
):
if
max_value
.
shape
==
(
1
,
):
max_value
=
max_value
[
0
]
max_value
=
max_value
[
0
]
if
min_value
.
shape
==
(
1
,
):
if
min_value
.
shape
==
(
1
,
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录