Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
f6d7d9a3
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f6d7d9a3
编写于
4月 02, 2020
作者:
W
wangguanzhong
提交者:
GitHub
4月 02, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine mask eval (#430)
上级
7d5380fd
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
109 addition
and
10 deletion
+109
-10
ppdet/utils/coco_eval.py
ppdet/utils/coco_eval.py
+29
-1
ppdet/utils/eval_utils.py
ppdet/utils/eval_utils.py
+5
-1
ppdet/utils/post_process.py
ppdet/utils/post_process.py
+62
-1
tools/eval.py
tools/eval.py
+4
-4
tools/train.py
tools/train.py
+9
-3
未找到文件。
ppdet/utils/coco_eval.py
浏览文件 @
f6d7d9a3
...
...
@@ -105,7 +105,35 @@ def mask_eval(results, anno_file, outfile, resolution, thresh_binarize=0.5):
coco_gt
=
COCO
(
anno_file
)
clsid2catid
=
{
i
+
1
:
v
for
i
,
v
in
enumerate
(
coco_gt
.
getCatIds
())}
segm_results
=
mask2out
(
results
,
clsid2catid
,
resolution
,
thresh_binarize
)
segm_results
=
[]
for
t
in
results
:
im_ids
=
np
.
array
(
t
[
'im_id'
][
0
])
bboxes
=
t
[
'bbox'
][
0
]
lengths
=
t
[
'bbox'
][
1
][
0
]
masks
=
t
[
'mask'
]
if
bboxes
.
shape
==
(
1
,
1
)
or
bboxes
is
None
:
continue
if
len
(
bboxes
.
tolist
())
==
0
:
continue
s
=
0
for
i
in
range
(
len
(
lengths
)):
num
=
lengths
[
i
]
im_id
=
int
(
im_ids
[
i
][
0
])
clsid_scores
=
bboxes
[
s
:
s
+
num
][:,
0
:
2
]
mask
=
masks
[
s
:
s
+
num
]
for
j
in
range
(
num
):
clsid
,
score
=
clsid_scores
[
j
].
tolist
()
catid
=
int
(
clsid2catid
[
clsid
])
segm
=
mask
[
j
]
segm
[
'counts'
]
=
segm
[
'counts'
].
decode
(
'utf8'
)
coco_res
=
{
'image_id'
:
im_id
,
'category_id'
:
int
(
catid
),
'segmentation'
:
segm
,
'score'
:
score
}
segm_results
.
append
(
coco_res
)
if
len
(
segm_results
)
==
0
:
logger
.
warning
(
"The number of valid mask detected is zero.
\n
\
Please use reasonable model and check input data."
)
...
...
ppdet/utils/eval_utils.py
浏览文件 @
f6d7d9a3
...
...
@@ -103,7 +103,8 @@ def eval_run(exe,
cfg
=
None
,
sub_prog
=
None
,
sub_keys
=
None
,
sub_values
=
None
):
sub_values
=
None
,
resolution
=
None
):
"""
Run evaluation program, return program outputs.
"""
...
...
@@ -152,6 +153,9 @@ def eval_run(exe,
if
multi_scale_test
:
res
=
clean_res
(
res
,
[
'im_info'
,
'bbox'
,
'im_id'
,
'im_shape'
,
'mask'
])
if
'mask'
in
res
:
from
ppdet.utils.post_process
import
mask_encode
res
[
'mask'
]
=
mask_encode
(
res
,
resolution
)
results
.
append
(
res
)
if
iter_id
%
100
==
0
:
logger
.
info
(
'Test iter {}'
.
format
(
iter_id
))
...
...
ppdet/utils/post_process.py
浏览文件 @
f6d7d9a3
...
...
@@ -18,7 +18,7 @@ from __future__ import print_function
import
logging
import
numpy
as
np
import
cv2
import
paddle.fluid
as
fluid
__all__
=
[
'nms'
]
...
...
@@ -210,3 +210,64 @@ def mstest_mask_post_process(result, cfg):
mask_pred
=
np
.
mean
(
mask_list
,
axis
=
0
)
return
{
'mask'
:
(
mask_pred
,
[[
len
(
mask_pred
)]])}
def
mask_encode
(
results
,
resolution
,
thresh_binarize
=
0.5
):
import
pycocotools.mask
as
mask_util
from
ppdet.utils.coco_eval
import
expand_boxes
scale
=
(
resolution
+
2.0
)
/
resolution
bboxes
=
results
[
'bbox'
][
0
]
masks
=
results
[
'mask'
][
0
]
lengths
=
results
[
'mask'
][
1
][
0
]
im_shapes
=
results
[
'im_shape'
][
0
]
segms
=
[]
if
bboxes
.
shape
==
(
1
,
1
)
or
bboxes
is
None
:
return
segms
if
len
(
bboxes
.
tolist
())
==
0
:
return
segms
s
=
0
# for each sample
for
i
in
range
(
len
(
lengths
)):
num
=
lengths
[
i
]
im_shape
=
im_shapes
[
i
]
bbox
=
bboxes
[
s
:
s
+
num
][:,
2
:]
clsid_scores
=
bboxes
[
s
:
s
+
num
][:,
0
:
2
]
mask
=
masks
[
s
:
s
+
num
]
s
+=
num
im_h
=
int
(
im_shape
[
0
])
im_w
=
int
(
im_shape
[
1
])
expand_bbox
=
expand_boxes
(
bbox
,
scale
)
expand_bbox
=
expand_bbox
.
astype
(
np
.
int32
)
padded_mask
=
np
.
zeros
(
(
resolution
+
2
,
resolution
+
2
),
dtype
=
np
.
float32
)
for
j
in
range
(
num
):
xmin
,
ymin
,
xmax
,
ymax
=
expand_bbox
[
j
].
tolist
()
clsid
,
score
=
clsid_scores
[
j
].
tolist
()
clsid
=
int
(
clsid
)
padded_mask
[
1
:
-
1
,
1
:
-
1
]
=
mask
[
j
,
clsid
,
:,
:]
w
=
xmax
-
xmin
+
1
h
=
ymax
-
ymin
+
1
w
=
np
.
maximum
(
w
,
1
)
h
=
np
.
maximum
(
h
,
1
)
resized_mask
=
cv2
.
resize
(
padded_mask
,
(
w
,
h
))
resized_mask
=
np
.
array
(
resized_mask
>
thresh_binarize
,
dtype
=
np
.
uint8
)
im_mask
=
np
.
zeros
((
im_h
,
im_w
),
dtype
=
np
.
uint8
)
x0
=
min
(
max
(
xmin
,
0
),
im_w
)
x1
=
min
(
max
(
xmax
+
1
,
0
),
im_w
)
y0
=
min
(
max
(
ymin
,
0
),
im_h
)
y1
=
min
(
max
(
ymax
+
1
,
0
),
im_h
)
im_mask
[
y0
:
y1
,
x0
:
x1
]
=
resized_mask
[(
y0
-
ymin
):(
y1
-
ymin
),
(
x0
-
xmin
):(
x1
-
xmin
)]
segm
=
mask_util
.
encode
(
np
.
array
(
im_mask
[:,
:,
np
.
newaxis
],
order
=
'F'
))[
0
]
segms
.
append
(
segm
)
return
segms
tools/eval.py
浏览文件 @
f6d7d9a3
...
...
@@ -152,14 +152,14 @@ def main():
if
'weights'
in
cfg
:
checkpoint
.
load_params
(
exe
,
startup_prog
,
cfg
.
weights
)
resolution
=
None
if
'Mask'
in
cfg
.
architecture
:
resolution
=
model
.
mask_head
.
resolution
results
=
eval_run
(
exe
,
compile_program
,
loader
,
keys
,
values
,
cls
,
cfg
,
sub_eval_prog
,
sub_keys
,
sub_values
)
sub_eval_prog
,
sub_keys
,
sub_values
,
resolution
)
#print(cfg['EvalReader']['dataset'].__dict__)
# evaluation
resolution
=
None
if
'mask'
in
results
[
0
]:
resolution
=
model
.
mask_head
.
resolution
# if map_type not set, use default 11point, only use in VOC eval
map_type
=
cfg
.
map_type
if
'map_type'
in
cfg
else
'11point'
eval_results
(
...
...
tools/train.py
浏览文件 @
f6d7d9a3
...
...
@@ -262,11 +262,17 @@ def main():
if
FLAGS
.
eval
:
# evaluation
results
=
eval_run
(
exe
,
compiled_eval_prog
,
eval_loader
,
eval_keys
,
eval_values
,
eval_cls
)
resolution
=
None
if
'
mask'
in
results
[
0
]
:
if
'
Mask'
in
cfg
.
architecture
:
resolution
=
model
.
mask_head
.
resolution
results
=
eval_run
(
exe
,
compiled_eval_prog
,
eval_loader
,
eval_keys
,
eval_values
,
eval_cls
,
resolution
=
resolution
)
box_ap_stats
=
eval_results
(
results
,
cfg
.
metric
,
cfg
.
num_classes
,
resolution
,
is_bbox_normalized
,
FLAGS
.
output_eval
,
map_type
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录