Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
668f8c48
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看板
提交
668f8c48
编写于
3月 23, 2022
作者:
W
wjj19950828
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support swintransformer
上级
a834dd82
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
20 deletion
+44
-20
x2paddle/op_mapper/onnx2paddle/onnx_custom_layer/nms.py
x2paddle/op_mapper/onnx2paddle/onnx_custom_layer/nms.py
+2
-1
x2paddle/op_mapper/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/onnx2paddle/opset9/opset.py
+42
-19
未找到文件。
x2paddle/op_mapper/onnx2paddle/onnx_custom_layer/nms.py
浏览文件 @
668f8c48
...
@@ -106,7 +106,8 @@ class NMS(object):
...
@@ -106,7 +106,8 @@ class NMS(object):
if
bboxes
.
shape
[
0
]
==
1
:
if
bboxes
.
shape
[
0
]
==
1
:
batch
=
paddle
.
zeros_like
(
clas
,
dtype
=
"int64"
)
batch
=
paddle
.
zeros_like
(
clas
,
dtype
=
"int64"
)
else
:
else
:
bboxes_count
=
bboxes
.
shape
[
1
]
bboxes_count
=
paddle
.
shape
(
bboxes
)[
1
]
bboxes_count
=
paddle
.
cast
(
bboxes_count
,
dtype
=
"int64"
)
batch
=
paddle
.
divide
(
index
,
bboxes_count
)
batch
=
paddle
.
divide
(
index
,
bboxes_count
)
index
=
paddle
.
mod
(
index
,
bboxes_count
)
index
=
paddle
.
mod
(
index
,
bboxes_count
)
res
=
paddle
.
concat
([
batch
,
clas
,
index
],
axis
=
1
)
res
=
paddle
.
concat
([
batch
,
clas
,
index
],
axis
=
1
)
...
...
x2paddle/op_mapper/onnx2paddle/opset9/opset.py
浏览文件 @
668f8c48
...
@@ -620,15 +620,23 @@ class OpSet9():
...
@@ -620,15 +620,23 @@ class OpSet9():
pads
)
# NCHW
pads
)
# NCHW
if
assume_pad
:
if
assume_pad
:
paddle_op
=
'paddle.nn.Pad2D'
paddle_op
=
'paddle.nn.Pad2D'
# x1_begin,x2_begin,x3_begin,x4_begin,x1_end,x2_end,x3_end,x4_end->x1_begin,x1_end,x2_begin,x2_end,x3_begin,x3_end,x4_begin,x4_end
paddings
=
np
.
array
(
pads
).
reshape
(
paddings
=
np
.
array
(
pads
).
reshape
(
(
2
,
-
1
)).
transpose
().
astype
(
"int32"
)
(
2
,
-
1
)).
transpose
().
astype
(
"int32"
)
paddings
=
np
.
flip
(
paddings
,
axis
=
0
).
flatten
().
tolist
()
if
mode
==
'constant'
:
if
sum
(
paddings
[:
4
])
==
0
:
paddings
=
paddings
.
flatten
().
tolist
()
paddings
=
paddings
[
4
:]
layer_attrs
[
'padding'
]
=
paddings
layer_attrs
[
'padding'
]
=
paddings
else
:
else
:
layer_attrs
[
"pad"
]
=
paddings
paddings
=
np
.
flip
(
paddings
,
axis
=
0
).
flatten
().
tolist
()
paddle_op
=
"custom_layer:PadAllDim4WithOneInput"
if
sum
(
paddings
[:
4
])
==
0
:
paddings
=
paddings
[
4
:]
layer_attrs
[
'padding'
]
=
paddings
else
:
layer_attrs
[
"pad"
]
=
paddings
paddle_op
=
"custom_layer:PadAllDim4WithOneInput"
else
:
paddle_op
=
'paddle.nn.functional.pad'
layer_attrs
[
"pad"
]
=
np
.
array
(
pads
).
tolist
()
else
:
else
:
pad_data_temp
=
pads
[
0
::
2
]
pad_data_temp
=
pads
[
0
::
2
]
pad_data_all
=
[]
pad_data_all
=
[]
...
@@ -1464,11 +1472,18 @@ class OpSet9():
...
@@ -1464,11 +1472,18 @@ class OpSet9():
outputs_list
.
append
(
"{}_p{}"
.
format
(
node
.
layer_name
,
i
))
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
(
if
len
(
split
)
>
1
:
'paddle.split'
,
self
.
paddle_graph
.
add_layer
(
inputs
=
{
"x"
:
val_x
.
name
},
'paddle.split'
,
outputs
=
outputs_list
,
inputs
=
{
"x"
:
val_x
.
name
},
**
layer_attrs
)
outputs
=
outputs_list
,
**
layer_attrs
)
else
:
self
.
paddle_graph
.
add_layer
(
"paddle.cast"
,
inputs
=
{
"x"
:
val_x
.
name
},
outputs
=
outputs_list
,
dtype
=
string
(
val_x
.
dtype
))
@
print_mapping_info
@
print_mapping_info
def
Reshape
(
self
,
node
):
def
Reshape
(
self
,
node
):
...
@@ -2698,28 +2713,36 @@ class OpSet9():
...
@@ -2698,28 +2713,36 @@ class OpSet9():
layer_outputs
=
[
nn_op_name
,
output_name
]
layer_outputs
=
[
nn_op_name
,
output_name
]
boxes
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
boxes
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
scores
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
scores
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
num_classes
=
scores
.
out_shapes
[
0
][
1
]
inputs_len
=
len
(
node
.
layer
.
input
)
inputs_len
=
len
(
node
.
layer
.
input
)
layer_attrs
=
dict
()
layer_attrs
=
dict
()
layer_attrs
[
"keep_top_k"
]
=
-
1
layer_attrs
[
"nms_threshold"
]
=
0.0
layer_attrs
[
"score_threshold"
]
=
0.0
if
inputs_len
>
2
:
if
inputs_len
>
2
:
max_output_boxes_per_class
=
self
.
graph
.
get_input_node
(
max_output_boxes_per_class
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
node
,
idx
=
2
,
copy
=
True
)
layer_attrs
[
"keep_top_k"
]
=
_const_weight_or_none
(
max_output_boxes_per_class
=
_const_weight_or_none
(
max_output_boxes_per_class
).
tolist
()[
0
]
*
num_classes
max_output_boxes_per_class
)
else
:
if
len
(
scores
.
out_shapes
[
0
])
!=
0
:
layer_attrs
[
"keep_top_k"
]
=
0
num_classes
=
scores
.
out_shapes
[
0
][
1
]
else
:
num_classes
=
1
if
max_output_boxes_per_class
is
not
None
:
max_output_boxes_per_class
=
max_output_boxes_per_class
.
tolist
()
if
isinstance
(
max_output_boxes_per_class
,
int
):
layer_attrs
[
"keep_top_k"
]
=
max_output_boxes_per_class
*
num_classes
else
:
layer_attrs
[
"keep_top_k"
]
=
max_output_boxes_per_class
[
0
]
*
num_classes
if
inputs_len
>
3
:
if
inputs_len
>
3
:
iou_threshold
=
self
.
graph
.
get_input_node
(
node
,
idx
=
3
,
copy
=
True
)
iou_threshold
=
self
.
graph
.
get_input_node
(
node
,
idx
=
3
,
copy
=
True
)
layer_attrs
[
"nms_threshold"
]
=
_const_weight_or_none
(
layer_attrs
[
"nms_threshold"
]
=
_const_weight_or_none
(
iou_threshold
).
tolist
()[
0
]
iou_threshold
).
tolist
()[
0
]
else
:
layer_attrs
[
"nms_threshold"
]
=
0.0
if
inputs_len
>
4
:
if
inputs_len
>
4
:
score_threshold
=
self
.
graph
.
get_input_node
(
node
,
idx
=
4
,
copy
=
True
)
score_threshold
=
self
.
graph
.
get_input_node
(
node
,
idx
=
4
,
copy
=
True
)
layer_attrs
[
"score_threshold"
]
=
_const_weight_or_none
(
layer_attrs
[
"score_threshold"
]
=
_const_weight_or_none
(
score_threshold
).
tolist
()[
0
]
score_threshold
).
tolist
()[
0
]
else
:
layer_attrs
[
"score_threshold"
]
=
0.0
self
.
paddle_graph
.
add_layer
(
self
.
paddle_graph
.
add_layer
(
"custom_layer:NMS"
,
"custom_layer:NMS"
,
inputs
=
{
"bboxes"
:
boxes
.
name
,
inputs
=
{
"bboxes"
:
boxes
.
name
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录