Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
5178d9f8
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5178d9f8
编写于
10月 21, 2020
作者:
W
wangguanzhong
提交者:
GitHub
10月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support multiclass nms for multi-batch, test=develop (#28164)
上级
5d94a5ca
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
1 deletion
+61
-1
paddle/fluid/operators/detection/multiclass_nms_op.cc
paddle/fluid/operators/detection/multiclass_nms_op.cc
+9
-1
python/paddle/fluid/tests/unittests/test_multiclass_nms_op.py
...on/paddle/fluid/tests/unittests/test_multiclass_nms_op.py
+52
-0
未找到文件。
paddle/fluid/operators/detection/multiclass_nms_op.cc
浏览文件 @
5178d9f8
...
...
@@ -290,6 +290,7 @@ class MultiClassNMSKernel : public framework::OpKernel<T> {
}
else
{
sdata
=
scores_data
+
label
*
predict_dim
;
}
for
(
size_t
j
=
0
;
j
<
indices
.
size
();
++
j
)
{
int
idx
=
indices
[
j
];
odata
[
count
*
out_dim
]
=
label
;
// label
...
...
@@ -333,6 +334,7 @@ class MultiClassNMSKernel : public framework::OpKernel<T> {
Tensor
boxes_slice
,
scores_slice
;
int
n
=
score_size
==
3
?
batch_size
:
boxes
->
lod
().
back
().
size
()
-
1
;
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
std
::
map
<
int
,
std
::
vector
<
int
>>
indices
;
if
(
score_size
==
3
)
{
scores_slice
=
scores
->
Slice
(
i
,
i
+
1
);
scores_slice
.
Resize
({
score_dims
[
1
],
score_dims
[
2
]});
...
...
@@ -340,10 +342,14 @@ class MultiClassNMSKernel : public framework::OpKernel<T> {
boxes_slice
.
Resize
({
score_dims
[
2
],
box_dim
});
}
else
{
auto
boxes_lod
=
boxes
->
lod
().
back
();
if
(
boxes_lod
[
i
]
==
boxes_lod
[
i
+
1
])
{
all_indices
.
push_back
(
indices
);
batch_starts
.
push_back
(
batch_starts
.
back
());
continue
;
}
scores_slice
=
scores
->
Slice
(
boxes_lod
[
i
],
boxes_lod
[
i
+
1
]);
boxes_slice
=
boxes
->
Slice
(
boxes_lod
[
i
],
boxes_lod
[
i
+
1
]);
}
std
::
map
<
int
,
std
::
vector
<
int
>>
indices
;
MultiClassNMS
(
ctx
,
scores_slice
,
boxes_slice
,
score_size
,
&
indices
,
&
num_nmsed_out
);
all_indices
.
push_back
(
indices
);
...
...
@@ -375,12 +381,14 @@ class MultiClassNMSKernel : public framework::OpKernel<T> {
}
}
else
{
auto
boxes_lod
=
boxes
->
lod
().
back
();
if
(
boxes_lod
[
i
]
==
boxes_lod
[
i
+
1
])
continue
;
scores_slice
=
scores
->
Slice
(
boxes_lod
[
i
],
boxes_lod
[
i
+
1
]);
boxes_slice
=
boxes
->
Slice
(
boxes_lod
[
i
],
boxes_lod
[
i
+
1
]);
if
(
return_index
)
{
offset
=
boxes_lod
[
i
]
*
score_dims
[
1
];
}
}
int64_t
s
=
batch_starts
[
i
];
int64_t
e
=
batch_starts
[
i
+
1
];
if
(
e
>
s
)
{
...
...
python/paddle/fluid/tests/unittests/test_multiclass_nms_op.py
浏览文件 @
5178d9f8
...
...
@@ -17,6 +17,7 @@ import unittest
import
numpy
as
np
import
copy
from
op_test
import
OpTest
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid
import
Program
,
program_guard
...
...
@@ -171,6 +172,9 @@ def lod_multiclass_nms(boxes, scores, background, score_threshold,
lod
=
[]
head
=
0
for
n
in
range
(
len
(
box_lod
[
0
])):
if
box_lod
[
0
][
n
]
==
0
:
lod
.
append
(
0
)
continue
box
=
boxes
[
head
:
head
+
box_lod
[
0
][
n
]]
score
=
scores
[
head
:
head
+
box_lod
[
0
][
n
]]
offset
=
head
...
...
@@ -357,6 +361,53 @@ class TestMulticlassNMSLoDInput(OpTest):
self
.
check_output
()
class
TestMulticlassNMSNoBox
(
TestMulticlassNMSLoDInput
):
def
setUp
(
self
):
self
.
set_argument
()
M
=
1200
C
=
21
BOX_SIZE
=
4
box_lod
=
[[
0
,
1200
,
0
]]
background
=
0
nms_threshold
=
0.3
nms_top_k
=
400
keep_top_k
=
200
score_threshold
=
self
.
score_threshold
normalized
=
False
scores
=
np
.
random
.
random
((
M
,
C
)).
astype
(
'float32'
)
scores
=
np
.
apply_along_axis
(
softmax
,
1
,
scores
)
boxes
=
np
.
random
.
random
((
M
,
C
,
BOX_SIZE
)).
astype
(
'float32'
)
boxes
[:,
:,
0
]
=
boxes
[:,
:,
0
]
*
10
boxes
[:,
:,
1
]
=
boxes
[:,
:,
1
]
*
10
boxes
[:,
:,
2
]
=
boxes
[:,
:,
2
]
*
10
+
10
boxes
[:,
:,
3
]
=
boxes
[:,
:,
3
]
*
10
+
10
det_outs
,
lod
=
lod_multiclass_nms
(
boxes
,
scores
,
background
,
score_threshold
,
nms_threshold
,
nms_top_k
,
keep_top_k
,
box_lod
,
normalized
)
det_outs
=
np
.
array
(
det_outs
).
astype
(
'float32'
)
nmsed_outs
=
det_outs
[:,
:
-
1
].
astype
(
'float32'
)
if
len
(
det_outs
)
else
det_outs
self
.
op_type
=
'multiclass_nms'
self
.
inputs
=
{
'BBoxes'
:
(
boxes
,
box_lod
),
'Scores'
:
(
scores
,
box_lod
),
}
self
.
outputs
=
{
'Out'
:
(
nmsed_outs
,
[
lod
])}
self
.
attrs
=
{
'background_label'
:
0
,
'nms_threshold'
:
nms_threshold
,
'nms_top_k'
:
nms_top_k
,
'keep_top_k'
:
keep_top_k
,
'score_threshold'
:
score_threshold
,
'nms_eta'
:
1.0
,
'normalized'
:
normalized
,
}
class
TestIOU
(
unittest
.
TestCase
):
def
test_iou
(
self
):
box1
=
np
.
array
([
4.0
,
3.0
,
7.0
,
5.0
]).
astype
(
'float32'
)
...
...
@@ -521,4 +572,5 @@ class TestMulticlassNMSError(unittest.TestCase):
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录