Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
3aad4947
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
3aad4947
编写于
6月 03, 2020
作者:
Q
qingqing01
提交者:
GitHub
6月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adapte softnms for YOLOv3 (#854) (#866)
* Adapte softnms for YOLOv3
上级
5a3a85a5
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
33 addition
and
10 deletion
+33
-10
ppdet/modeling/anchor_heads/yolo_head.py
ppdet/modeling/anchor_heads/yolo_head.py
+3
-1
ppdet/modeling/ops.py
ppdet/modeling/ops.py
+30
-9
未找到文件。
ppdet/modeling/anchor_heads/yolo_head.py
浏览文件 @
3aad4947
...
...
@@ -20,7 +20,7 @@ from paddle import fluid
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.regularizer
import
L2Decay
from
ppdet.modeling.ops
import
MultiClassNMS
from
ppdet.modeling.ops
import
MultiClassNMS
,
MultiClassSoftNMS
from
ppdet.modeling.losses.yolo_loss
import
YOLOv3Loss
from
ppdet.core.workspace
import
register
from
ppdet.modeling.ops
import
DropBlock
...
...
@@ -335,6 +335,8 @@ class YOLOv3Head(object):
yolo_boxes
=
fluid
.
layers
.
concat
(
boxes
,
axis
=
1
)
yolo_scores
=
fluid
.
layers
.
concat
(
scores
,
axis
=
2
)
if
type
(
self
.
nms
)
is
MultiClassSoftNMS
:
yolo_scores
=
fluid
.
layers
.
transpose
(
yolo_scores
,
perm
=
[
0
,
2
,
1
])
pred
=
self
.
nms
(
bboxes
=
yolo_boxes
,
scores
=
yolo_scores
)
return
{
'bbox'
:
pred
}
...
...
ppdet/modeling/ops.py
浏览文件 @
3aad4947
...
...
@@ -547,8 +547,6 @@ class MultiClassSoftNMS(object):
return
dets_final
def
_soft_nms
(
bboxes
,
scores
):
bboxes
=
np
.
array
(
bboxes
)
scores
=
np
.
array
(
scores
)
class_nums
=
scores
.
shape
[
-
1
]
softnms_thres
=
self
.
score_threshold
...
...
@@ -562,7 +560,8 @@ class MultiClassSoftNMS(object):
for
j
in
range
(
start_idx
,
class_nums
):
inds
=
np
.
where
(
scores
[:,
j
]
>=
softnms_thres
)[
0
]
scores_j
=
scores
[
inds
,
j
]
rois_j
=
bboxes
[
inds
,
j
,
:]
rois_j
=
bboxes
[
inds
,
j
,
:]
if
len
(
bboxes
.
shape
)
>
2
else
bboxes
[
inds
,
:]
dets_j
=
np
.
hstack
((
scores_j
[:,
np
.
newaxis
],
rois_j
)).
astype
(
np
.
float32
,
copy
=
False
)
cls_rank
=
np
.
argsort
(
-
dets_j
[:,
0
])
...
...
@@ -584,12 +583,34 @@ class MultiClassSoftNMS(object):
keep
=
np
.
where
(
cls_boxes
[:,
0
]
>=
image_thresh
)[
0
]
pred_result
=
pred_result
[
keep
,
:]
res
=
fluid
.
LoDTensor
()
res
.
set_lod
([[
0
,
pred_result
.
shape
[
0
]]])
if
pred_result
.
shape
[
0
]
==
0
:
pred_result
=
np
.
array
([[
1
]],
dtype
=
np
.
float32
)
res
.
set
(
pred_result
,
fluid
.
CPUPlace
())
return
pred_result
def
_batch_softnms
(
bboxes
,
scores
):
batch_offsets
=
bboxes
.
lod
()
bboxes
=
np
.
array
(
bboxes
)
scores
=
np
.
array
(
scores
)
out_offsets
=
[
0
]
pred_res
=
[]
if
len
(
batch_offsets
)
>
0
:
batch_offset
=
batch_offsets
[
0
]
for
i
in
range
(
len
(
batch_offset
)
-
1
):
s
,
e
=
batch_offset
[
i
],
batch_offset
[
i
+
1
]
pred
=
_soft_nms
(
bboxes
[
s
:
e
],
scores
[
s
:
e
])
out_offsets
.
append
(
pred
.
shape
[
0
]
+
out_offsets
[
-
1
])
pred_res
.
append
(
pred
)
else
:
assert
len
(
bboxes
.
shape
)
==
3
assert
len
(
scores
.
shape
)
==
3
for
i
in
range
(
bboxes
.
shape
[
0
]):
pred
=
_soft_nms
(
bboxes
[
i
],
scores
[
i
])
out_offsets
.
append
(
pred
.
shape
[
0
]
+
out_offsets
[
-
1
])
pred_res
.
append
(
pred
)
res
=
fluid
.
LoDTensor
()
res
.
set_lod
([
out_offsets
])
if
len
(
pred_res
)
==
0
:
pred_res
=
np
.
array
([[
1
]],
dtype
=
np
.
float32
)
res
.
set
(
np
.
vstack
(
pred_res
),
fluid
.
CPUPlace
())
return
res
pred_result
=
create_tmp_var
(
...
...
@@ -599,7 +620,7 @@ class MultiClassSoftNMS(object):
shape
=
[
-
1
,
6
],
lod_level
=
1
)
fluid
.
layers
.
py_func
(
func
=
_
soft_
nms
,
x
=
[
bboxes
,
scores
],
out
=
pred_result
)
func
=
_
batch_soft
nms
,
x
=
[
bboxes
,
scores
],
out
=
pred_result
)
return
pred_result
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录