Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
2b30df83
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看板
提交
2b30df83
编写于
6月 16, 2020
作者:
J
jiangjiajun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
paddle2onnx support unet and deeplab
上级
de295641
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
144 addition
and
6 deletion
+144
-6
x2paddle/op_mapper/paddle_op_mapper.py
x2paddle/op_mapper/paddle_op_mapper.py
+144
-6
未找到文件。
x2paddle/op_mapper/paddle_op_mapper.py
浏览文件 @
2b30df83
...
...
@@ -78,6 +78,11 @@ class PaddleOpMapper(object):
'Relu'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
op
.
output
(
'Out'
))
return
node
def
sigmoid
(
self
,
op
,
block
):
node
=
helper
.
make_node
(
'Sigmoid'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
op
.
output
(
'Out'
))
return
node
def
elementwise_add
(
self
,
op
,
block
):
axis
=
op
.
attr
(
'axis'
)
x_shape
=
block
.
var
(
op
.
input
(
'X'
)[
0
]).
shape
...
...
@@ -129,12 +134,40 @@ class PaddleOpMapper(object):
return
node
def
softmax
(
self
,
op
,
block
):
axis
=
op
.
attr
(
'axis'
)
shape
=
block
.
var
(
op
.
output
(
'Out'
)[
0
]).
shape
if
axis
<
0
:
axis
+=
len
(
shape
)
if
axis
==
len
(
shape
)
-
1
:
node
=
helper
.
make_node
(
'Softmax'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
op
.
output
(
'Out'
),
axis
=
op
.
attr
(
'axis'
))
return
node
else
:
perm
=
[
i
for
i
in
range
(
len
(
shape
))]
perm
[
-
1
]
=
axis
perm
[
axis
]
=
len
(
shape
)
-
1
transpose_name0
=
self
.
get_name
(
op
.
type
,
'transpose'
)
transpose_node0
=
helper
.
make_node
(
'Transpose'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
[
transpose_name0
],
perm
=
perm
)
softmax_name
=
self
.
get_name
(
op
.
type
,
'softmax'
)
softmax_node
=
helper
.
make_node
(
'Softmax'
,
inputs
=
[
transpose_name0
],
outputs
=
[
softmax_name
],
axis
=-
1
)
transpose_name1
=
self
.
get_name
(
op
.
type
,
'transpose'
)
transpose_node1
=
helper
.
make_node
(
'Transpose'
,
inputs
=
[
softmax_name
],
outputs
=
op
.
output
(
'Out'
),
perm
=
perm
)
return
[
transpose_node0
,
softmax_node
,
transpose_node1
]
def
scale
(
self
,
op
,
block
):
scale
=
op
.
attr
(
'scale'
)
...
...
@@ -376,6 +409,94 @@ class PaddleOpMapper(object):
keepdims
=
op
.
attr
(
'keep_dim'
))
return
node
def
bilinear_interp
(
self
,
op
,
block
):
input_names
=
op
.
input_names
coordinate_transformation_mode
=
'half_pixel'
shape_dtype
=
block
.
var
(
op
.
input
(
'OutSize'
)[
0
]).
dtype
if
op
.
attr
(
'align_corners'
):
coordinate_transformation_mode
=
'align_corners'
if
'OutSize'
in
input_names
and
len
(
op
.
input
(
'OutSize'
))
>
0
:
roi_node
=
self
.
make_constant_node
(
self
.
get_name
(
op
.
type
,
'roi'
),
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
])
roi_name
=
self
.
get_name
(
op
.
type
,
'roi'
)
roi_node
=
self
.
make_constant_node
(
roi_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
])
empty_name
=
self
.
get_name
(
op
.
type
,
'empty'
)
empty_tensor
=
helper
.
make_tensor
(
empty_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
(
0
,
),
np
.
array
([]).
astype
(
'float32'
),
raw
=
False
)
empty_node
=
helper
.
make_node
(
'Constant'
,
[],
outputs
=
[
empty_name
],
value
=
empty_tensor
)
shape_name0
=
self
.
get_name
(
op
.
type
,
'shape'
)
shape_node0
=
helper
.
make_node
(
'Shape'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
[
shape_name0
])
starts_name
=
self
.
get_name
(
op
.
type
,
'slice.starts'
)
starts_node
=
self
.
make_constant_node
(
starts_name
,
onnx_pb
.
TensorProto
.
INT64
,
[
0
])
ends_name
=
self
.
get_name
(
op
.
type
,
'slice.ends'
)
ends_node
=
self
.
make_constant_node
(
ends_name
,
onnx_pb
.
TensorProto
.
INT64
,
[
2
])
shape_name1
=
self
.
get_name
(
op
.
type
,
'shape'
)
shape_node1
=
helper
.
make_node
(
'Slice'
,
inputs
=
[
shape_name0
,
starts_name
,
ends_name
],
outputs
=
[
shape_name1
])
shape_name2
=
self
.
get_name
(
op
.
type
,
"shape.cast"
)
shape_node2
=
helper
.
make_node
(
'Cast'
,
inputs
=
op
.
input
(
'OutSize'
),
outputs
=
[
shape_name2
],
to
=
onnx_pb
.
TensorProto
.
INT64
)
shape_name3
=
self
.
get_name
(
op
.
type
,
"shape.concat"
)
shape_node3
=
helper
.
make_node
(
'Concat'
,
inputs
=
[
shape_name1
,
shape_name2
],
outputs
=
[
shape_name3
],
axis
=
0
)
result_node
=
helper
.
make_node
(
'Resize'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
roi_name
,
empty_name
,
shape_name3
],
outputs
=
op
.
output
(
'Out'
),
mode
=
'linear'
,
coordinate_transformation_mode
=
coordinate_transformation_mode
)
return
[
roi_node
,
empty_node
,
shape_node0
,
starts_node
,
ends_node
,
shape_node1
,
shape_node2
,
shape_node3
,
result_node
]
elif
'Scale'
in
input_names
and
len
(
op
.
input
(
'Scale'
))
>
0
:
node
=
helper
.
make_node
(
'Resize'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
op
.
input
(
'Scale'
)[
0
]],
outputs
=
op
.
output
(
'Out'
),
mode
=
'linear'
,
coordinate_transformation_mode
=
coordinate_transformation_mode
)
else
:
out_shape
=
[
op
.
attr
(
'out_h'
),
op
.
attr
(
'out_w'
)]
scale
=
op
.
attr
(
'scale'
)
if
out_shape
.
count
(
-
1
)
>
0
:
scale_name
=
self
.
get_name
(
op
.
type
,
'scale'
)
scale_node
=
self
.
make_constant_node
(
scale_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
scale
,
scale
])
roi_name
=
self
.
get_name
(
op
.
type
,
'roi'
)
roi_node
=
self
.
make_constant_node
(
roi_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
])
node
=
helper
.
make_node
(
'Resize'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
roi_name
,
scale_name
],
outputs
=
op
.
output
(
'Out'
),
mode
=
'nearest'
,
coordinate_transformation_mode
=
coordinate_transformation_mode
)
return
[
scale_node
,
roi_node
,
node
]
else
:
raise
Exception
(
"Unexpected situation happend"
)
return
node
def
nearest_interp
(
self
,
op
,
block
):
input_names
=
op
.
input_names
coordinate_transformation_mode
=
'half_pixel'
...
...
@@ -479,6 +600,23 @@ class PaddleOpMapper(object):
elem_type
=
self
.
paddle_onnx_dtype_map
[
var
.
dtype
])
return
tensor_info
def
unsqueeze2
(
self
,
op
,
block
):
node
=
helper
.
make_node
(
'Unsqueeze'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
op
.
output
(
'Out'
),
axes
=
op
.
attr
(
'axes'
))
return
node
def
arg_max
(
self
,
op
,
block
):
node
=
helper
.
make_node
(
'ArgMax'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
op
.
output
(
'Out'
),
axis
=
op
.
attr
(
'axis'
),
keepdims
=
0
)
return
node
def
convert_weights
(
self
,
program
):
var_names
=
program
.
global_block
().
vars
nodes
=
list
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录