Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
b780979b
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看板
提交
b780979b
编写于
1月 08, 2021
作者:
S
SunAhong1993
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix onnx
上级
bbbbd42e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
15 deletion
+32
-15
x2paddle/core/program.py
x2paddle/core/program.py
+6
-1
x2paddle/decoder/onnx_decoder.py
x2paddle/decoder/onnx_decoder.py
+13
-3
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
+3
-2
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
+10
-9
未找到文件。
x2paddle/core/program.py
浏览文件 @
b780979b
...
@@ -210,9 +210,12 @@ class PaddleGraph(object):
...
@@ -210,9 +210,12 @@ class PaddleGraph(object):
if
self
.
edges_in
.
get
(
layer_id
,
0
)
==
0
and
self
.
edges_out
.
get
(
if
self
.
edges_in
.
get
(
layer_id
,
0
)
==
0
and
self
.
edges_out
.
get
(
layer_id
,
0
)
==
0
and
layer
.
kernel
!=
"prim.assert"
\
layer_id
,
0
)
==
0
and
layer
.
kernel
!=
"prim.assert"
\
and
layer
.
kernel
!=
"prim.exception"
\
and
layer
.
kernel
!=
"prim.exception"
\
and
layer
.
kernel
!=
"prim.warnings"
and
layer
.
outputs
[
0
]
not
in
self
.
outputs
:
and
layer
.
kernel
!=
"prim.warnings"
\
and
layer
.
outputs
[
0
]
not
in
self
.
outputs
:
if
layer
.
kernel
==
"paddle.to_tensor"
and
layer
.
outputs
[
0
]
in
self
.
inputs_info
:
if
layer
.
kernel
==
"paddle.to_tensor"
and
layer
.
outputs
[
0
]
in
self
.
inputs_info
:
self
.
inputs_info
.
pop
(
layer
.
outputs
[
0
])
self
.
inputs_info
.
pop
(
layer
.
outputs
[
0
])
if
layer
.
outputs
[
0
]
in
self
.
inputs
:
self
.
inputs
.
pop
(
self
.
inputs
.
index
(
layer
.
outputs
[
0
]))
invalid_list
.
append
(
layer_id
)
invalid_list
.
append
(
layer_id
)
for
layer_id
in
invalid_list
:
for
layer_id
in
invalid_list
:
self
.
layers
.
pop
(
layer_id
)
self
.
layers
.
pop
(
layer_id
)
...
@@ -355,6 +358,8 @@ class PaddleGraph(object):
...
@@ -355,6 +358,8 @@ class PaddleGraph(object):
edges_in
=
self
.
edges_in
.
get
(
layer_id
,
[])
edges_in
=
self
.
edges_in
.
get
(
layer_id
,
[])
edges_out
=
self
.
edges_out
.
get
(
layer_id
,
[])
edges_out
=
self
.
edges_out
.
get
(
layer_id
,
[])
if
len
(
edges_in
)
==
0
and
len
(
edges_out
)
==
0
and
layer
.
outputs
[
0
]
not
in
self
.
outputs
:
if
len
(
edges_in
)
==
0
and
len
(
edges_out
)
==
0
and
layer
.
outputs
[
0
]
not
in
self
.
outputs
:
if
layer
.
outputs
[
0
]
in
self
.
inputs
:
self
.
inputs
.
pop
(
self
.
inputs
.
index
(
layer
.
outputs
[
0
]))
continue
continue
line
=
""
line
=
""
...
...
x2paddle/decoder/onnx_decoder.py
浏览文件 @
b780979b
...
@@ -31,6 +31,7 @@ import numpy as np
...
@@ -31,6 +31,7 @@ import numpy as np
from
copy
import
deepcopy
from
copy
import
deepcopy
import
logging
as
_logging
import
logging
as
_logging
import
os
import
os
import
copy
default_op_domain
=
'ai.onnx'
default_op_domain
=
'ai.onnx'
_logger
=
_logging
.
getLogger
(
__name__
)
_logger
=
_logging
.
getLogger
(
__name__
)
...
@@ -125,6 +126,17 @@ class ONNXGraphDataNode(GraphNode):
...
@@ -125,6 +126,17 @@ class ONNXGraphDataNode(GraphNode):
shape
.
append
(
dim
.
dim_value
)
shape
.
append
(
dim
.
dim_value
)
out_shapes
.
append
(
shape
)
out_shapes
.
append
(
shape
)
return
out_shapes
return
out_shapes
elif
isinstance
(
self
.
layer
,
TensorProto
):
values
=
self
.
layer
.
dims
out_shapes
=
list
()
shape
=
list
()
for
dim
in
values
:
if
dim
==
0
:
shape
.
append
(
-
1
)
else
:
shape
.
append
(
dim
)
out_shapes
.
append
(
shape
)
return
out_shapes
else
:
else
:
values
=
self
.
layer
.
dims
values
=
self
.
layer
.
dims
out_shapes
=
list
()
out_shapes
=
list
()
...
@@ -227,8 +239,6 @@ class ONNXGraph(Graph):
...
@@ -227,8 +239,6 @@ class ONNXGraph(Graph):
inner_nodes
=
self
.
get_inner_nodes
()
inner_nodes
=
self
.
get_inner_nodes
()
for
ipt_vi
in
self
.
graph
.
input
:
for
ipt_vi
in
self
.
graph
.
input
:
if
ipt_vi
.
name
not
in
inner_nodes
:
if
ipt_vi
.
name
not
in
inner_nodes
:
if
len
(
ipt_vi
.
type
.
tensor_type
.
shape
.
dim
)
==
0
:
continue
self
.
check_input_shape
(
ipt_vi
)
self
.
check_input_shape
(
ipt_vi
)
self
.
place_holder_nodes
.
append
(
ipt_vi
.
name
)
self
.
place_holder_nodes
.
append
(
ipt_vi
.
name
)
...
@@ -289,7 +299,7 @@ class ONNXGraph(Graph):
...
@@ -289,7 +299,7 @@ class ONNXGraph(Graph):
#generate topo
#generate topo
super
(
ONNXGraph
,
self
).
build
()
super
(
ONNXGraph
,
self
).
build
()
self
.
input_nodes
=
self
.
place_holder_nodes
self
.
input_nodes
=
copy
.
deepcopy
(
self
.
place_holder_nodes
)
def
build_connection
(
self
,
layer_name
,
node
):
def
build_connection
(
self
,
layer_name
,
node
):
"""
"""
...
...
x2paddle/op_mapper/dygraph/onnx2paddle/opset9/opset.py
浏览文件 @
b780979b
...
@@ -299,6 +299,9 @@ class OpSet9():
...
@@ -299,6 +299,9 @@ class OpSet9():
attrs
.
update
({
"align_corners"
:
False
,
attrs
.
update
({
"align_corners"
:
False
,
"mode"
:
string
(
mode
),
"mode"
:
string
(
mode
),
"align_mode"
:
1
})
"align_mode"
:
1
})
val_x_shape
=
val_x
.
out_shapes
[
0
]
if
mode
==
"linear"
and
len
(
val_x_shape
)
==
4
:
attrs
[
"mode"
]
=
string
(
"bilinear"
)
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
kernel
=
"paddle.nn.functional.interpolate"
,
kernel
=
"paddle.nn.functional.interpolate"
,
inputs
=
inputs
,
inputs
=
inputs
,
...
@@ -1386,9 +1389,7 @@ class OpSet9():
...
@@ -1386,9 +1389,7 @@ class OpSet9():
outputs
=
[
output_name
])
outputs
=
[
output_name
])
else
:
else
:
if
mode
==
'channel'
and
len
(
shape_slope
)
==
1
:
if
mode
==
'channel'
and
len
(
shape_slope
)
==
1
:
# paddle params shape need be [1, channel]
slope_data
=
_const_weight_or_none
(
val_slope
)
slope_data
=
_const_weight_or_none
(
val_slope
)
slope_data
=
np
.
reshape
(
slope_data
,
[
1
]
+
shape_slope
)
self
.
weights
[
val_slope
.
name
]
=
slope_data
self
.
weights
[
val_slope
.
name
]
=
slope_data
num_parameters
=
val_x
.
out_shapes
[
0
][
1
]
num_parameters
=
val_x
.
out_shapes
[
0
][
1
]
else
:
else
:
...
...
x2paddle/op_mapper/static/onnx2paddle/opset9/opset.py
浏览文件 @
b780979b
...
@@ -289,6 +289,9 @@ class OpSet9():
...
@@ -289,6 +289,9 @@ class OpSet9():
attrs
.
update
({
"align_corners"
:
False
,
attrs
.
update
({
"align_corners"
:
False
,
"mode"
:
string
(
mode
),
"mode"
:
string
(
mode
),
"align_mode"
:
1
})
"align_mode"
:
1
})
val_x_shape
=
val_x
.
out_shapes
[
0
]
if
mode
==
"linear"
and
len
(
val_x_shape
)
==
4
:
attrs
[
"mode"
]
=
string
(
"bilinear"
)
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
kernel
=
"paddle.nn.functional.interpolate"
,
kernel
=
"paddle.nn.functional.interpolate"
,
inputs
=
inputs
,
inputs
=
inputs
,
...
@@ -1323,9 +1326,6 @@ class OpSet9():
...
@@ -1323,9 +1326,6 @@ class OpSet9():
@
print_mapping_info
@
print_mapping_info
def
PRelu
(
self
,
node
):
def
PRelu
(
self
,
node
):
op_name
=
name_generator
(
"prelu"
,
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_slope
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
val_slope
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
...
@@ -1342,12 +1342,13 @@ class OpSet9():
...
@@ -1342,12 +1342,13 @@ class OpSet9():
outputs
=
[
node
.
name
],
outputs
=
[
node
.
name
],
mode
=
"element"
)
mode
=
"element"
)
else
:
else
:
if
mode
==
'channel'
and
len
(
shape_slope
)
==
1
:
if
mode
==
'channel'
:
# paddle params shape need be [1, channel]
if
len
(
shape_slope
)
>
1
:
slope_data
=
_const_weight_or_none
(
val_slope
)
self
.
paddle_graph
.
add_layer
(
slope_data
=
np
.
reshape
(
slope_data
,
[
1
]
+
shape_slope
)
"paddle.reshape"
,
self
.
params
[
val_slope
.
name
]
=
slope_data
inputs
=
{
"x"
:
val_slope
.
name
},
outputs
=
[
val_slope
.
name
],
shape
=
[
shape_slope
[
0
]])
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
"paddle.nn.functional.prelu"
,
"paddle.nn.functional.prelu"
,
inputs
=
{
"x"
:
val_x
.
name
,
inputs
=
{
"x"
:
val_x
.
name
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录