Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
3fc2622d
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看板
未验证
提交
3fc2622d
编写于
10月 29, 2020
作者:
G
Guanghua Yu
提交者:
GitHub
10月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add multiclass_nms,anchor_generator,prior_box in dygraph (#1627)
上级
eed296b0
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
602 addition
and
32 deletion
+602
-32
ppdet/modeling/layers.py
ppdet/modeling/layers.py
+2
-2
ppdet/modeling/ops.py
ppdet/modeling/ops.py
+418
-22
ppdet/modeling/tests/test_ops.py
ppdet/modeling/tests/test_ops.py
+182
-8
未找到文件。
ppdet/modeling/layers.py
浏览文件 @
3fc2622d
...
@@ -45,7 +45,7 @@ class AnchorGeneratorRPN(object):
...
@@ -45,7 +45,7 @@ class AnchorGeneratorRPN(object):
stride
=
self
.
stride
if
(
stride
=
self
.
stride
if
(
level
is
None
or
self
.
anchor_start_size
is
None
)
else
(
level
is
None
or
self
.
anchor_start_size
is
None
)
else
(
self
.
stride
[
0
]
*
(
2.
**
level
),
self
.
stride
[
1
]
*
(
2.
**
level
))
self
.
stride
[
0
]
*
(
2.
**
level
),
self
.
stride
[
1
]
*
(
2.
**
level
))
anchor
,
var
=
fluid
.
layer
s
.
anchor_generator
(
anchor
,
var
=
op
s
.
anchor_generator
(
input
=
input
,
input
=
input
,
anchor_sizes
=
anchor_sizes
,
anchor_sizes
=
anchor_sizes
,
aspect_ratios
=
self
.
aspect_ratios
,
aspect_ratios
=
self
.
aspect_ratios
,
...
@@ -367,7 +367,7 @@ class DecodeClipNms(object):
...
@@ -367,7 +367,7 @@ class DecodeClipNms(object):
@
register
@
register
@
serializable
@
serializable
class
MultiClassNMS
(
object
):
class
MultiClassNMS
(
object
):
__op__
=
fluid
.
layer
s
.
multiclass_nms
__op__
=
op
s
.
multiclass_nms
__append_doc__
=
True
__append_doc__
=
True
def
__init__
(
self
,
def
__init__
(
self
,
...
...
ppdet/modeling/ops.py
浏览文件 @
3fc2622d
此差异已折叠。
点击以展开。
ppdet/modeling/tests/test_ops.py
浏览文件 @
3fc2622d
...
@@ -383,7 +383,7 @@ class TestIoUSimilarity(LayerTest):
...
@@ -383,7 +383,7 @@ class TestIoUSimilarity(LayerTest):
self
.
assertTrue
(
np
.
array_equal
(
iou_np
,
iou_dy_np
))
self
.
assertTrue
(
np
.
array_equal
(
iou_np
,
iou_dy_np
))
class
TestYOLO
_
Box
(
LayerTest
):
class
TestYOLOBox
(
LayerTest
):
def
test_yolo_box
(
self
):
def
test_yolo_box
(
self
):
# x shape [N C H W], C=K * (5 + class_num), class_num=10, K=2
# x shape [N C H W], C=K * (5 + class_num), class_num=10, K=2
...
@@ -414,11 +414,6 @@ class TestYOLO_Box(LayerTest):
...
@@ -414,11 +414,6 @@ class TestYOLO_Box(LayerTest):
feed
=
{
feed
=
{
'x'
:
np_x
,
'x'
:
np_x
,
'origin_shape'
:
np_origin_shape
,
'origin_shape'
:
np_origin_shape
,
'anchors'
:
[
10
,
13
,
30
,
13
],
'class_num'
:
10
,
'conf_thresh'
:
0.01
,
'downsample_ratio'
:
32
,
'scale_x_y'
:
1.0
,
},
},
fetch_list
=
[
boxes
,
scores
],
fetch_list
=
[
boxes
,
scores
],
with_lod
=
False
)
with_lod
=
False
)
...
@@ -439,8 +434,8 @@ class TestYOLO_Box(LayerTest):
...
@@ -439,8 +434,8 @@ class TestYOLO_Box(LayerTest):
boxes_dy_np
=
boxes_dy
.
numpy
()
boxes_dy_np
=
boxes_dy
.
numpy
()
scores_dy_np
=
scores_dy
.
numpy
()
scores_dy_np
=
scores_dy
.
numpy
()
self
.
assertTrue
(
np
.
array_equal
(
boxes_np
,
boxes_dy_np
))
self
.
assertTrue
(
np
.
array_equal
(
boxes_np
,
boxes_dy_np
))
self
.
assertTrue
(
np
.
array_equal
(
scores_np
,
scores_dy_np
))
self
.
assertTrue
(
np
.
array_equal
(
scores_np
,
scores_dy_np
))
def
test_yolo_box_error
(
self
):
def
test_yolo_box_error
(
self
):
paddle
.
enable_static
()
paddle
.
enable_static
()
...
@@ -463,6 +458,185 @@ class TestYOLO_Box(LayerTest):
...
@@ -463,6 +458,185 @@ class TestYOLO_Box(LayerTest):
scale_x_y
=
1.2
)
scale_x_y
=
1.2
)
class
TestPriorBox
(
LayerTest
):
def
test_prior_box
(
self
):
input_np
=
np
.
random
.
rand
(
2
,
10
,
32
,
32
).
astype
(
'float32'
)
image_np
=
np
.
random
.
rand
(
2
,
10
,
40
,
40
).
astype
(
'float32'
)
min_sizes
=
[
2
,
4
]
with
self
.
static_graph
():
input
=
paddle
.
static
.
data
(
name
=
'input'
,
shape
=
[
2
,
10
,
32
,
32
],
dtype
=
'float32'
)
image
=
paddle
.
static
.
data
(
name
=
'image'
,
shape
=
[
2
,
10
,
40
,
40
],
dtype
=
'float32'
)
box
,
var
=
ops
.
prior_box
(
input
=
input
,
image
=
image
,
min_sizes
=
min_sizes
,
clip
=
True
,
flip
=
True
)
box_np
,
var_np
=
self
.
get_static_graph_result
(
feed
=
{
'input'
:
input_np
,
'image'
:
image_np
,
},
fetch_list
=
[
box
,
var
],
with_lod
=
False
)
with
self
.
dynamic_graph
():
inputs_dy
=
base
.
to_variable
(
input_np
)
image_dy
=
base
.
to_variable
(
image_np
)
box_dy
,
var_dy
=
ops
.
prior_box
(
input
=
inputs_dy
,
image
=
image_dy
,
min_sizes
=
min_sizes
,
clip
=
True
,
flip
=
True
)
box_dy_np
=
box_dy
.
numpy
()
var_dy_np
=
var_dy
.
numpy
()
self
.
assertTrue
(
np
.
array_equal
(
box_np
,
box_dy_np
))
self
.
assertTrue
(
np
.
array_equal
(
var_np
,
var_dy_np
))
def
test_prior_box_error
(
self
):
program
=
Program
()
paddle
.
enable_static
()
with
program_guard
(
program
):
input
=
paddle
.
static
.
data
(
name
=
'input'
,
shape
=
[
2
,
10
,
32
,
32
],
dtype
=
'int32'
)
image
=
paddle
.
static
.
data
(
name
=
'image'
,
shape
=
[
2
,
10
,
40
,
40
],
dtype
=
'int32'
)
self
.
assertRaises
(
TypeError
,
ops
.
prior_box
,
input
=
input
,
image
=
image
,
min_sizes
=
[
2
,
4
],
clip
=
True
,
flip
=
True
)
class
TestAnchorGenerator
(
LayerTest
):
def
test_anchor_generator
(
self
):
b
,
c
,
h
,
w
=
2
,
48
,
16
,
16
input_np
=
np
.
random
.
rand
(
2
,
48
,
16
,
16
).
astype
(
'float32'
)
paddle
.
enable_static
()
with
self
.
static_graph
():
input
=
paddle
.
static
.
data
(
name
=
'input'
,
shape
=
[
b
,
c
,
h
,
w
],
dtype
=
'float32'
)
anchor
,
var
=
ops
.
anchor_generator
(
input
=
input
,
anchor_sizes
=
[
64
,
128
,
256
,
512
],
aspect_ratios
=
[
0.5
,
1.0
,
2.0
],
variance
=
[
0.1
,
0.1
,
0.2
,
0.2
],
stride
=
[
16.0
,
16.0
],
offset
=
0.5
)
anchor_np
,
var_np
=
self
.
get_static_graph_result
(
feed
=
{
'input'
:
input_np
,
},
fetch_list
=
[
anchor
,
var
],
with_lod
=
False
)
with
self
.
dynamic_graph
():
inputs_dy
=
base
.
to_variable
(
input_np
)
anchor_dy
,
var_dy
=
ops
.
anchor_generator
(
input
=
inputs_dy
,
anchor_sizes
=
[
64
,
128
,
256
,
512
],
aspect_ratios
=
[
0.5
,
1.0
,
2.0
],
variance
=
[
0.1
,
0.1
,
0.2
,
0.2
],
stride
=
[
16.0
,
16.0
],
offset
=
0.5
)
anchor_dy_np
=
anchor_dy
.
numpy
()
var_dy_np
=
var_dy
.
numpy
()
self
.
assertTrue
(
np
.
array_equal
(
anchor_np
,
anchor_dy_np
))
self
.
assertTrue
(
np
.
array_equal
(
var_np
,
var_dy_np
))
class
TestMulticlassNms
(
LayerTest
):
def
test_multiclass_nms
(
self
):
boxes_np
=
np
.
random
.
rand
(
81
,
4
).
astype
(
'float32'
)
scores_np
=
np
.
random
.
rand
(
81
).
astype
(
'float32'
)
rois_num_np
=
np
.
array
([
40
,
41
]).
astype
(
'int32'
)
with
self
.
static_graph
():
boxes
=
paddle
.
static
.
data
(
name
=
'bboxes'
,
shape
=
[
81
,
4
],
dtype
=
'float32'
,
lod_level
=
1
)
scores
=
paddle
.
static
.
data
(
name
=
'scores'
,
shape
=
[
81
],
dtype
=
'float32'
,
lod_level
=
1
)
rois_num
=
paddle
.
static
.
data
(
name
=
'rois_num'
,
shape
=
[
40
,
41
],
dtype
=
'int32'
)
output
=
ops
.
multiclass_nms
(
bboxes
=
boxes
,
scores
=
scores
,
background_label
=
0
,
score_threshold
=
0.5
,
nms_top_k
=
400
,
nms_threshold
=
0.3
,
keep_top_k
=
200
,
normalized
=
False
,
return_index
=
True
,
rois_num
=
rois_num
)
out_np
,
index_np
,
nms_rois_num_np
=
self
.
get_static_graph_result
(
feed
=
{
'bboxes'
:
boxes_np
,
'scores'
:
scores_np
,
'rois_num'
:
rois_num_np
},
fetch_list
=
output
,
with_lod
=
False
)
with
self
.
dynamic_graph
():
boxes_dy
=
base
.
to_variable
(
boxes_np
)
scores_dy
=
base
.
to_variable
(
scores_np
)
rois_num_dy
=
base
.
to_variable
(
rois_num_np
)
out_dy
,
index_dy
,
nms_rois_num_dy
=
ops
.
multiclass_nms
(
bboxes
=
boxes_dy
,
scores
=
scores_dy
,
background_label
=
0
,
score_threshold
=
0.5
,
nms_top_k
=
400
,
nms_threshold
=
0.3
,
keep_top_k
=
200
,
normalized
=
False
,
return_index
=
True
,
rois_num
=
rois_num_dy
)
out_dy_np
=
out_dy
.
numpy
()
index_dy_np
=
index_dy
.
numpy
()
nms_rois_num_dy_np
=
nms_rois_num_dy
.
numpy
()
self
.
assertTrue
(
np
.
array_equal
(
out_np
,
out_dy_np
))
self
.
assertTrue
(
np
.
array_equal
(
index_np
,
index_dy_np
))
self
.
assertTrue
(
np
.
array_equal
(
nms_rois_num_np
,
nms_rois_num_dy_np
))
def
test_multiclass_nms_error
(
self
):
program
=
Program
()
paddle
.
enable_static
()
with
program_guard
(
program
):
boxes
=
paddle
.
static
.
data
(
name
=
'bboxes'
,
shape
=
[
81
,
4
],
dtype
=
'float32'
,
lod_level
=
1
)
scores
=
paddle
.
static
.
data
(
name
=
'scores'
,
shape
=
[
81
],
dtype
=
'float32'
,
lod_level
=
1
)
rois_num
=
paddle
.
static
.
data
(
name
=
'rois_num'
,
shape
=
[
40
,
41
],
dtype
=
'int32'
)
self
.
assertRaises
(
TypeError
,
ops
.
multiclass_nms
,
boxes
=
boxes
,
scores
=
scores
,
background_label
=
0
,
score_threshold
=
0.5
,
nms_top_k
=
400
,
nms_threshold
=
0.3
,
keep_top_k
=
200
,
normalized
=
False
,
return_index
=
True
,
rois_num
=
rois_num
)
class
TestMatrixNMS
(
LayerTest
):
class
TestMatrixNMS
(
LayerTest
):
def
test_matrix_nms
(
self
):
def
test_matrix_nms
(
self
):
N
,
M
,
C
=
7
,
1200
,
21
N
,
M
,
C
=
7
,
1200
,
21
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录