Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
ad353419
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看板
未验证
提交
ad353419
编写于
12月 14, 2020
作者:
W
wangguanzhong
提交者:
GitHub
12月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Dygraph]fix dygraph (#1883)
* fix dygraph * refine keep_ratio in ResizeOp
上级
7257a364
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
99 addition
and
112 deletion
+99
-112
configs/_base_/models/cascade_mask_rcnn_r50_fpn.yml
configs/_base_/models/cascade_mask_rcnn_r50_fpn.yml
+1
-0
configs/_base_/models/cascade_rcnn_r50_fpn.yml
configs/_base_/models/cascade_rcnn_r50_fpn.yml
+1
-0
configs/_base_/readers/faster_fpn_reader.yml
configs/_base_/readers/faster_fpn_reader.yml
+2
-2
configs/_base_/readers/faster_reader.yml
configs/_base_/readers/faster_reader.yml
+2
-2
configs/_base_/readers/mask_fpn_reader.yml
configs/_base_/readers/mask_fpn_reader.yml
+2
-2
configs/_base_/readers/mask_reader.yml
configs/_base_/readers/mask_reader.yml
+2
-2
deploy/python/infer.py
deploy/python/infer.py
+1
-1
deploy/python/preprocess.py
deploy/python/preprocess.py
+2
-2
ppdet/data/transform/batch_operator.py
ppdet/data/transform/batch_operator.py
+1
-1
ppdet/data/transform/operator.py
ppdet/data/transform/operator.py
+1
-1
ppdet/modeling/architecture/cascade_rcnn.py
ppdet/modeling/architecture/cascade_rcnn.py
+3
-6
ppdet/modeling/head/mask_head.py
ppdet/modeling/head/mask_head.py
+8
-12
ppdet/modeling/layers.py
ppdet/modeling/layers.py
+5
-8
ppdet/modeling/post_process.py
ppdet/modeling/post_process.py
+2
-8
ppdet/py_op/post_process.py
ppdet/py_op/post_process.py
+13
-12
ppdet/utils/eval_utils.py
ppdet/utils/eval_utils.py
+6
-11
tools/eval.py
tools/eval.py
+19
-18
tools/export_model.py
tools/export_model.py
+3
-1
tools/export_utils.py
tools/export_utils.py
+7
-7
tools/infer.py
tools/infer.py
+18
-16
未找到文件。
configs/_base_/models/cascade_mask_rcnn_r50_fpn.yml
浏览文件 @
ad353419
...
@@ -95,6 +95,7 @@ BBoxPostProcess:
...
@@ -95,6 +95,7 @@ BBoxPostProcess:
name
:
RCNNBox
name
:
RCNNBox
num_classes
:
81
num_classes
:
81
batch_size
:
1
batch_size
:
1
var_weight
:
3.
nms
:
nms
:
name
:
MultiClassNMS
name
:
MultiClassNMS
keep_top_k
:
100
keep_top_k
:
100
...
...
configs/_base_/models/cascade_rcnn_r50_fpn.yml
浏览文件 @
ad353419
...
@@ -92,6 +92,7 @@ BBoxPostProcess:
...
@@ -92,6 +92,7 @@ BBoxPostProcess:
name
:
RCNNBox
name
:
RCNNBox
num_classes
:
81
num_classes
:
81
batch_size
:
1
batch_size
:
1
var_weight
:
3.
nms
:
nms
:
name
:
MultiClassNMS
name
:
MultiClassNMS
keep_top_k
:
100
keep_top_k
:
100
...
...
configs/_base_/readers/faster_fpn_reader.yml
浏览文件 @
ad353419
...
@@ -21,7 +21,7 @@ EvalReader:
...
@@ -21,7 +21,7 @@ EvalReader:
sample_transforms
:
sample_transforms
:
-
DecodeOp
:
{
}
-
DecodeOp
:
{
}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]
}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]
}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
,
keep_ratio
:
True
}
-
PermuteOp
:
{
}
-
PermuteOp
:
{
}
batch_transforms
:
batch_transforms
:
-
PadBatchOp
:
{
pad_to_stride
:
32
,
pad_gt
:
false
}
-
PadBatchOp
:
{
pad_to_stride
:
32
,
pad_gt
:
false
}
...
@@ -37,7 +37,7 @@ TestReader:
...
@@ -37,7 +37,7 @@ TestReader:
sample_transforms
:
sample_transforms
:
-
DecodeOp
:
{
}
-
DecodeOp
:
{
}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]
}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]
}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
,
keep_ratio
:
True
}
-
PermuteOp
:
{
}
-
PermuteOp
:
{
}
batch_transforms
:
batch_transforms
:
-
PadBatchOp
:
{
pad_to_stride
:
32
,
pad_gt
:
false
}
-
PadBatchOp
:
{
pad_to_stride
:
32
,
pad_gt
:
false
}
...
...
configs/_base_/readers/faster_reader.yml
浏览文件 @
ad353419
...
@@ -21,7 +21,7 @@ EvalReader:
...
@@ -21,7 +21,7 @@ EvalReader:
sample_transforms
:
sample_transforms
:
-
DecodeOp
:
{
}
-
DecodeOp
:
{
}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]
}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]
}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
,
keep_ratio
:
True
}
-
PermuteOp
:
{
}
-
PermuteOp
:
{
}
batch_transforms
:
batch_transforms
:
-
PadBatchOp
:
{
pad_to_stride
:
-1
,
pad_gt
:
false
}
-
PadBatchOp
:
{
pad_to_stride
:
-1
,
pad_gt
:
false
}
...
@@ -37,7 +37,7 @@ TestReader:
...
@@ -37,7 +37,7 @@ TestReader:
sample_transforms
:
sample_transforms
:
-
DecodeOp
:
{
}
-
DecodeOp
:
{
}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]
}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]
}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
,
keep_ratio
:
True
}
-
PermuteOp
:
{
}
-
PermuteOp
:
{
}
batch_transforms
:
batch_transforms
:
-
PadBatchOp
:
{
pad_to_stride
:
-1
,
pad_gt
:
false
}
-
PadBatchOp
:
{
pad_to_stride
:
-1
,
pad_gt
:
false
}
...
...
configs/_base_/readers/mask_fpn_reader.yml
浏览文件 @
ad353419
...
@@ -21,7 +21,7 @@ EvalReader:
...
@@ -21,7 +21,7 @@ EvalReader:
sample_transforms
:
sample_transforms
:
-
DecodeOp
:
{}
-
DecodeOp
:
{}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
,
keep_ratio
:
True
}
-
PermuteOp
:
{}
-
PermuteOp
:
{}
batch_transforms
:
batch_transforms
:
-
PadBatchOp
:
{
pad_to_stride
:
32
,
pad_gt
:
false
}
-
PadBatchOp
:
{
pad_to_stride
:
32
,
pad_gt
:
false
}
...
@@ -37,7 +37,7 @@ TestReader:
...
@@ -37,7 +37,7 @@ TestReader:
sample_transforms
:
sample_transforms
:
-
DecodeOp
:
{}
-
DecodeOp
:
{}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
,
keep_ratio
:
True
}
-
PermuteOp
:
{}
-
PermuteOp
:
{}
batch_transforms
:
batch_transforms
:
-
PadBatchOp
:
{
pad_to_stride
:
32
,
pad_gt
:
false
}
-
PadBatchOp
:
{
pad_to_stride
:
32
,
pad_gt
:
false
}
...
...
configs/_base_/readers/mask_reader.yml
浏览文件 @
ad353419
...
@@ -21,7 +21,7 @@ EvalReader:
...
@@ -21,7 +21,7 @@ EvalReader:
sample_transforms
:
sample_transforms
:
-
DecodeOp
:
{}
-
DecodeOp
:
{}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
,
keep_ratio
:
True
}
-
PermuteOp
:
{}
-
PermuteOp
:
{}
batch_transforms
:
batch_transforms
:
-
PadBatchOp
:
{
pad_to_stride
:
-1.
,
pad_gt
:
false
}
-
PadBatchOp
:
{
pad_to_stride
:
-1.
,
pad_gt
:
false
}
...
@@ -37,7 +37,7 @@ TestReader:
...
@@ -37,7 +37,7 @@ TestReader:
sample_transforms
:
sample_transforms
:
-
DecodeOp
:
{}
-
DecodeOp
:
{}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]}
-
NormalizeImageOp
:
{
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]}
-
ResizeOp
:
{
interp
:
1
,
target_size
:
[
800
,
1333
]
,
keep_ratio
:
True
}
-
PermuteOp
:
{}
-
PermuteOp
:
{}
batch_transforms
:
batch_transforms
:
-
PadBatchOp
:
{
pad_to_stride
:
-1.
,
pad_gt
:
false
}
-
PadBatchOp
:
{
pad_to_stride
:
-1.
,
pad_gt
:
false
}
...
...
deploy/python/infer.py
浏览文件 @
ad353419
...
@@ -123,7 +123,7 @@ class Detector(object):
...
@@ -123,7 +123,7 @@ class Detector(object):
boxes_tensor
=
self
.
predictor
.
get_output_handle
(
output_names
[
0
])
boxes_tensor
=
self
.
predictor
.
get_output_handle
(
output_names
[
0
])
np_boxes
=
boxes_tensor
.
copy_to_cpu
()
np_boxes
=
boxes_tensor
.
copy_to_cpu
()
if
self
.
pred_config
.
mask_resolution
is
not
None
:
if
self
.
pred_config
.
mask_resolution
is
not
None
:
masks_tensor
=
self
.
predictor
.
get_output_handle
(
output_names
[
1
])
masks_tensor
=
self
.
predictor
.
get_output_handle
(
output_names
[
2
])
np_masks
=
masks_tensor
.
copy_to_cpu
()
np_masks
=
masks_tensor
.
copy_to_cpu
()
t1
=
time
.
time
()
t1
=
time
.
time
()
...
...
deploy/python/preprocess.py
浏览文件 @
ad353419
...
@@ -192,8 +192,8 @@ class PadStride(object):
...
@@ -192,8 +192,8 @@ class PadStride(object):
im_info (dict): info of processed image
im_info (dict): info of processed image
"""
"""
coarsest_stride
=
self
.
coarsest_stride
coarsest_stride
=
self
.
coarsest_stride
if
coarsest_stride
=
=
0
:
if
coarsest_stride
<
=
0
:
return
im
return
im
,
im_info
im_c
,
im_h
,
im_w
=
im
.
shape
im_c
,
im_h
,
im_w
=
im
.
shape
pad_h
=
int
(
np
.
ceil
(
float
(
im_h
)
/
coarsest_stride
)
*
coarsest_stride
)
pad_h
=
int
(
np
.
ceil
(
float
(
im_h
)
/
coarsest_stride
)
*
coarsest_stride
)
pad_w
=
int
(
np
.
ceil
(
float
(
im_w
)
/
coarsest_stride
)
*
coarsest_stride
)
pad_w
=
int
(
np
.
ceil
(
float
(
im_w
)
/
coarsest_stride
)
*
coarsest_stride
)
...
...
ppdet/data/transform/batch_operator.py
浏览文件 @
ad353419
...
@@ -158,7 +158,7 @@ class BatchRandomResizeOp(BaseOperator):
...
@@ -158,7 +158,7 @@ class BatchRandomResizeOp(BaseOperator):
def
__init__
(
self
,
def
__init__
(
self
,
target_size
,
target_size
,
keep_ratio
=
True
,
keep_ratio
,
interp
=
cv2
.
INTER_NEAREST
,
interp
=
cv2
.
INTER_NEAREST
,
random_size
=
True
,
random_size
=
True
,
random_interp
=
False
):
random_interp
=
False
):
...
...
ppdet/data/transform/operator.py
浏览文件 @
ad353419
...
@@ -577,7 +577,7 @@ class RandomFlipOp(BaseOperator):
...
@@ -577,7 +577,7 @@ class RandomFlipOp(BaseOperator):
@
register_op
@
register_op
class
ResizeOp
(
BaseOperator
):
class
ResizeOp
(
BaseOperator
):
def
__init__
(
self
,
target_size
,
keep_ratio
=
True
,
interp
=
cv2
.
INTER_LINEAR
):
def
__init__
(
self
,
target_size
,
keep_ratio
,
interp
=
cv2
.
INTER_LINEAR
):
"""
"""
Resize image to target size. if keep_ratio is True,
Resize image to target size. if keep_ratio is True,
resize the image's long side to the maximum of target_size
resize the image's long side to the maximum of target_size
...
...
ppdet/modeling/architecture/cascade_rcnn.py
浏览文件 @
ad353419
...
@@ -113,12 +113,9 @@ class CascadeRCNN(BaseArch):
...
@@ -113,12 +113,9 @@ class CascadeRCNN(BaseArch):
if
self
.
inputs
[
'mode'
]
==
'infer'
:
if
self
.
inputs
[
'mode'
]
==
'infer'
:
bbox_pred
,
bboxes
=
self
.
bbox_head
.
get_cascade_prediction
(
bbox_pred
,
bboxes
=
self
.
bbox_head
.
get_cascade_prediction
(
self
.
bbox_head_list
,
rois_list
)
self
.
bbox_head_list
,
rois_list
)
self
.
bboxes
=
self
.
bbox_post_process
(
self
.
bboxes
=
self
.
bbox_post_process
(
bbox_pred
,
bboxes
,
bbox_pred
,
self
.
inputs
[
'im_shape'
],
bboxes
,
self
.
inputs
[
'scale_factor'
])
self
.
inputs
[
'im_shape'
],
self
.
inputs
[
'scale_factor'
],
var_weight
=
3.
)
if
self
.
with_mask
:
if
self
.
with_mask
:
rois
=
rois_list
[
-
1
]
rois
=
rois_list
[
-
1
]
...
...
ppdet/modeling/head/mask_head.py
浏览文件 @
ad353419
...
@@ -161,18 +161,14 @@ class MaskHead(Layer):
...
@@ -161,18 +161,14 @@ class MaskHead(Layer):
if
bbox
.
shape
[
0
]
==
0
:
if
bbox
.
shape
[
0
]
==
0
:
mask_head_out
=
paddle
.
full
([
1
,
6
],
-
1
)
mask_head_out
=
paddle
.
full
([
1
,
6
],
-
1
)
return
mask_head_out
else
:
else
:
# TODO(guanghua): Remove fluid dependency
scale_factor_list
=
[]
scale_factor_list
=
paddle
.
fluid
.
layers
.
create_array
(
'float32'
)
for
idx
in
range
(
bbox_num
.
shape
[
0
]):
num_count
=
0
num
=
bbox_num
[
idx
]
for
idx
,
num
in
enumerate
(
bbox_num
):
scale
=
scale_factor
[
idx
,
0
]
for
n
in
range
(
num
):
ones
=
paddle
.
ones
(
num
)
paddle
.
fluid
.
layers
.
array_write
(
scale_expand
=
ones
*
scale
x
=
scale_factor
[
idx
,
0
],
scale_factor_list
.
append
(
scale_expand
)
i
=
paddle
.
to_tensor
(
num_count
),
array
=
scale_factor_list
)
num_count
+=
1
scale_factor_list
=
paddle
.
cast
(
scale_factor_list
=
paddle
.
cast
(
paddle
.
concat
(
scale_factor_list
),
'float32'
)
paddle
.
concat
(
scale_factor_list
),
'float32'
)
scale_factor_list
=
paddle
.
reshape
(
scale_factor_list
,
shape
=
[
-
1
,
1
])
scale_factor_list
=
paddle
.
reshape
(
scale_factor_list
,
shape
=
[
-
1
,
1
])
...
@@ -189,7 +185,7 @@ class MaskHead(Layer):
...
@@ -189,7 +185,7 @@ class MaskHead(Layer):
mode
=
'infer'
)
mode
=
'infer'
)
mask_logit
=
self
.
mask_fcn_logits
[
stage
](
mask_feat
)
mask_logit
=
self
.
mask_fcn_logits
[
stage
](
mask_feat
)
mask_head_out
=
F
.
sigmoid
(
mask_logit
)
mask_head_out
=
F
.
sigmoid
(
mask_logit
)
return
mask_head_out
return
mask_head_out
def
forward
(
self
,
def
forward
(
self
,
inputs
,
inputs
,
...
...
ppdet/modeling/layers.py
浏览文件 @
ad353419
...
@@ -263,7 +263,8 @@ class RCNNBox(object):
...
@@ -263,7 +263,8 @@ class RCNNBox(object):
prior_box_var
=
[
0.1
,
0.1
,
0.2
,
0.2
],
prior_box_var
=
[
0.1
,
0.1
,
0.2
,
0.2
],
code_type
=
"decode_center_size"
,
code_type
=
"decode_center_size"
,
box_normalized
=
False
,
box_normalized
=
False
,
axis
=
1
):
axis
=
1
,
var_weight
=
1.
):
super
(
RCNNBox
,
self
).
__init__
()
super
(
RCNNBox
,
self
).
__init__
()
self
.
num_classes
=
num_classes
self
.
num_classes
=
num_classes
self
.
batch_size
=
batch_size
self
.
batch_size
=
batch_size
...
@@ -271,13 +272,9 @@ class RCNNBox(object):
...
@@ -271,13 +272,9 @@ class RCNNBox(object):
self
.
code_type
=
code_type
self
.
code_type
=
code_type
self
.
box_normalized
=
box_normalized
self
.
box_normalized
=
box_normalized
self
.
axis
=
axis
self
.
axis
=
axis
self
.
var_weight
=
var_weight
def
__call__
(
self
,
def
__call__
(
self
,
bbox_head_out
,
rois
,
im_shape
,
scale_factor
):
bbox_head_out
,
rois
,
im_shape
,
scale_factor
,
var_weight
=
1.
):
bbox_pred
,
cls_prob
=
bbox_head_out
bbox_pred
,
cls_prob
=
bbox_head_out
roi
,
rois_num
=
rois
roi
,
rois_num
=
rois
origin_shape
=
im_shape
/
scale_factor
origin_shape
=
im_shape
/
scale_factor
...
@@ -296,7 +293,7 @@ class RCNNBox(object):
...
@@ -296,7 +293,7 @@ class RCNNBox(object):
origin_shape
=
paddle
.
concat
(
origin_shape_list
)
origin_shape
=
paddle
.
concat
(
origin_shape_list
)
bbox
=
roi
/
scale
bbox
=
roi
/
scale
prior_box_var
=
[
i
/
var_weight
for
i
in
self
.
prior_box_var
]
prior_box_var
=
[
i
/
self
.
var_weight
for
i
in
self
.
prior_box_var
]
bbox
=
ops
.
box_coder
(
bbox
=
ops
.
box_coder
(
prior_box
=
bbox
,
prior_box
=
bbox
,
prior_box_var
=
prior_box_var
,
prior_box_var
=
prior_box_var
,
...
...
ppdet/modeling/post_process.py
浏览文件 @
ad353419
...
@@ -16,14 +16,8 @@ class BBoxPostProcess(object):
...
@@ -16,14 +16,8 @@ class BBoxPostProcess(object):
self
.
decode
=
decode
self
.
decode
=
decode
self
.
nms
=
nms
self
.
nms
=
nms
def
__call__
(
self
,
def
__call__
(
self
,
head_out
,
rois
,
im_shape
,
scale_factor
=
None
):
head_out
,
bboxes
,
score
=
self
.
decode
(
head_out
,
rois
,
im_shape
,
scale_factor
)
rois
,
im_shape
,
scale_factor
=
None
,
var_weight
=
1.
):
bboxes
,
score
=
self
.
decode
(
head_out
,
rois
,
im_shape
,
scale_factor
,
var_weight
)
bbox_pred
,
bbox_num
,
_
=
self
.
nms
(
bboxes
,
score
)
bbox_pred
,
bbox_num
,
_
=
self
.
nms
(
bboxes
,
score
)
return
bbox_pred
,
bbox_num
return
bbox_pred
,
bbox_num
...
...
ppdet/py_op/post_process.py
浏览文件 @
ad353419
...
@@ -73,33 +73,34 @@ def bbox_post_process(bboxes,
...
@@ -73,33 +73,34 @@ def bbox_post_process(bboxes,
@
jit
@
jit
def
mask_post_process
(
bbox
,
def
mask_post_process
(
det_res
,
bbox_nums
,
masks
,
im_shape
,
im_shape
,
scale_factor
,
scale_factor
,
resolution
=
14
,
resolution
=
14
,
binary_thresh
=
0.5
):
binary_thresh
=
0.5
):
bbox
=
det_res
[
'bbox'
]
bbox_num
=
det_res
[
'bbox_num'
]
masks
=
det_res
[
'mask'
]
if
masks
.
shape
[
0
]
==
0
:
if
masks
.
shape
[
0
]
==
0
:
return
masks
return
masks
M
=
resolution
M
=
resolution
scale
=
(
M
+
2.0
)
/
M
scale
=
(
M
+
2.0
)
/
M
boxes
=
bbox
[:,
2
:]
boxes
=
bbox
[:,
2
:]
labels
=
bbox
[:,
0
]
labels
=
bbox
[:,
0
]
segms_results
=
[[]
for
_
in
range
(
len
(
bbox_num
s
))]
segms_results
=
[[]
for
_
in
range
(
len
(
bbox_num
))]
sum
=
0
sum
=
0
st_num
=
0
st_num
=
0
end_num
=
0
end_num
=
0
for
i
in
range
(
len
(
bbox_nums
)):
for
i
in
range
(
len
(
bbox_num
)):
bbox_num
=
bbox_nums
[
i
]
length
=
bbox_num
[
i
]
end_num
+=
bbox_num
end_num
+=
length
cls_segms
=
[]
cls_segms
=
[]
boxes_n
=
boxes
[
st_num
:
end_num
]
boxes_n
=
boxes
[
st_num
:
end_num
]
labels_n
=
labels
[
st_num
:
end_num
]
labels_n
=
labels
[
st_num
:
end_num
]
masks_n
=
masks
[
st_num
:
end_num
]
masks_n
=
masks
[
st_num
:
end_num
]
im_h
=
int
(
round
(
im_shape
[
i
][
0
]
/
scale_factor
[
i
]))
im_w
=
int
(
round
(
im_shape
[
i
][
1
]
/
scale_factor
[
i
]))
im_h
=
int
(
round
(
im_shape
[
i
][
0
]
/
scale_factor
[
i
,
0
]))
im_w
=
int
(
round
(
im_shape
[
i
][
1
]
/
scale_factor
[
i
,
0
]))
boxes_n
=
expand_bbox
(
boxes_n
,
scale
)
boxes_n
=
expand_bbox
(
boxes_n
,
scale
)
boxes_n
=
boxes_n
.
astype
(
np
.
int32
)
boxes_n
=
boxes_n
.
astype
(
np
.
int32
)
padded_mask
=
np
.
zeros
((
M
+
2
,
M
+
2
),
dtype
=
np
.
float32
)
padded_mask
=
np
.
zeros
((
M
+
2
,
M
+
2
),
dtype
=
np
.
float32
)
...
@@ -129,8 +130,8 @@ def mask_post_process(bbox,
...
@@ -129,8 +130,8 @@ def mask_post_process(bbox,
im_mask
[:,
:,
np
.
newaxis
],
order
=
'F'
))[
0
]
im_mask
[:,
:,
np
.
newaxis
],
order
=
'F'
))[
0
]
cls_segms
.
append
(
rle
)
cls_segms
.
append
(
rle
)
segms_results
[
i
]
=
np
.
array
(
cls_segms
)[:,
np
.
newaxis
]
segms_results
[
i
]
=
np
.
array
(
cls_segms
)[:,
np
.
newaxis
]
st_num
+=
bbox_num
st_num
+=
length
segms_results
=
np
.
vstack
([
segms_results
[
k
]
for
k
in
range
(
len
(
bbox_num
s
))])
segms_results
=
np
.
vstack
([
segms_results
[
k
]
for
k
in
range
(
len
(
bbox_num
))])
bboxes
=
np
.
hstack
([
segms_results
,
bbox
])
bboxes
=
np
.
hstack
([
segms_results
,
bbox
])
return
bboxes
[:,
:
3
]
return
bboxes
[:,
:
3
]
...
...
ppdet/utils/eval_utils.py
浏览文件 @
ad353419
...
@@ -5,7 +5,7 @@ from __future__ import print_function
...
@@ -5,7 +5,7 @@ from __future__ import print_function
import
os
import
os
import
sys
import
sys
import
json
import
json
from
ppdet.py_op.post_process
import
get_det_res
,
get_seg_res
,
mask_post_process
from
ppdet.py_op.post_process
import
get_det_res
,
get_seg_res
import
logging
import
logging
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -33,8 +33,7 @@ def json_eval_results(metric, json_directory=None, dataset=None):
...
@@ -33,8 +33,7 @@ def json_eval_results(metric, json_directory=None, dataset=None):
logger
.
info
(
"{} not exists!"
.
format
(
v_json
))
logger
.
info
(
"{} not exists!"
.
format
(
v_json
))
def
get_infer_results
(
outs_res
,
eval_type
,
catid
,
im_info
,
def
get_infer_results
(
outs_res
,
eval_type
,
catid
,
im_info
):
mask_resolution
=
None
):
"""
"""
Get result at the stage of inference.
Get result at the stage of inference.
The output format is dictionary containing bbox or mask result.
The output format is dictionary containing bbox or mask result.
...
@@ -52,8 +51,8 @@ def get_infer_results(outs_res, eval_type, catid, im_info,
...
@@ -52,8 +51,8 @@ def get_infer_results(outs_res, eval_type, catid, im_info,
box_res
=
[]
box_res
=
[]
for
i
,
outs
in
enumerate
(
outs_res
):
for
i
,
outs
in
enumerate
(
outs_res
):
im_ids
=
im_info
[
i
][
2
]
im_ids
=
im_info
[
i
][
2
]
box_res
+=
get_det_res
(
outs
[
'bbox'
]
.
numpy
()
,
box_res
+=
get_det_res
(
outs
[
'bbox'
]
,
outs
[
'bbox_num'
],
im_ids
,
outs
[
'bbox_num'
].
numpy
(),
im_ids
,
catid
)
catid
)
infer_res
[
'bbox'
]
=
box_res
infer_res
[
'bbox'
]
=
box_res
if
'mask'
in
eval_type
:
if
'mask'
in
eval_type
:
...
@@ -63,12 +62,8 @@ def get_infer_results(outs_res, eval_type, catid, im_info,
...
@@ -63,12 +62,8 @@ def get_infer_results(outs_res, eval_type, catid, im_info,
im_shape
=
im_info
[
i
][
0
]
im_shape
=
im_info
[
i
][
0
]
scale_factor
=
im_info
[
i
][
1
]
scale_factor
=
im_info
[
i
][
1
]
im_ids
=
im_info
[
i
][
2
]
im_ids
=
im_info
[
i
][
2
]
mask
=
mask_post_process
(
outs
[
'bbox'
].
numpy
(),
mask
=
outs
[
'mask'
]
outs
[
'bbox_num'
].
numpy
(),
seg_res
+=
get_seg_res
(
mask
,
outs
[
'bbox_num'
],
im_ids
,
catid
)
outs
[
'mask'
].
numpy
(),
im_shape
,
scale_factor
[
0
],
mask_resolution
)
seg_res
+=
get_seg_res
(
mask
,
outs
[
'bbox_num'
].
numpy
(),
im_ids
,
catid
)
infer_res
[
'mask'
]
=
seg_res
infer_res
[
'mask'
]
=
seg_res
return
infer_res
return
infer_res
...
...
tools/eval.py
浏览文件 @
ad353419
...
@@ -81,14 +81,22 @@ def run(FLAGS, cfg, place):
...
@@ -81,14 +81,22 @@ def run(FLAGS, cfg, place):
fields
=
cfg
[
'EvalReader'
][
'inputs_def'
][
'fields'
]
fields
=
cfg
[
'EvalReader'
][
'inputs_def'
][
'fields'
]
model
.
eval
()
model
.
eval
()
outs
=
model
(
data
=
data
,
input_def
=
fields
,
mode
=
'infer'
)
outs
=
model
(
data
=
data
,
input_def
=
fields
,
mode
=
'infer'
)
for
key
,
value
in
outs
.
items
():
outs
[
key
]
=
value
.
numpy
()
im_shape
=
data
[
fields
.
index
(
'im_shape'
)].
numpy
()
scale_factor
=
data
[
fields
.
index
(
'scale_factor'
)].
numpy
()
im_id
=
data
[
fields
.
index
(
'im_id'
)].
numpy
()
im_info
.
append
([
im_shape
,
scale_factor
,
im_id
])
if
'mask'
in
outs
and
'bbox'
in
outs
:
mask_resolution
=
model
.
mask_post_process
.
mask_resolution
from
ppdet.py_op.post_process
import
mask_post_process
outs
[
'mask'
]
=
mask_post_process
(
outs
,
im_shape
,
scale_factor
,
mask_resolution
)
outs_res
.
append
(
outs
)
outs_res
.
append
(
outs
)
im_info
.
append
([
data
[
fields
.
index
(
'im_shape'
)].
numpy
(),
data
[
fields
.
index
(
'scale_factor'
)].
numpy
(),
data
[
fields
.
index
(
'im_id'
)].
numpy
()
])
# log
# log
sample_num
+=
len
(
data
)
sample_num
+=
im_shape
.
shape
[
0
]
if
iter_id
%
100
==
0
:
if
iter_id
%
100
==
0
:
logger
.
info
(
"Eval iter: {}"
.
format
(
iter_id
))
logger
.
info
(
"Eval iter: {}"
.
format
(
iter_id
))
...
@@ -96,8 +104,10 @@ def run(FLAGS, cfg, place):
...
@@ -96,8 +104,10 @@ def run(FLAGS, cfg, place):
logger
.
info
(
'Total sample number: {}, averge FPS: {}'
.
format
(
logger
.
info
(
'Total sample number: {}, averge FPS: {}'
.
format
(
sample_num
,
sample_num
/
cost_time
))
sample_num
,
sample_num
/
cost_time
))
eval_type
=
[
'bbox'
]
eval_type
=
[]
if
getattr
(
cfg
,
'MaskHead'
,
None
):
if
'bbox'
in
outs
:
eval_type
.
append
(
'bbox'
)
if
'mask'
in
outs
:
eval_type
.
append
(
'mask'
)
eval_type
.
append
(
'mask'
)
# Metric
# Metric
# TODO: support other metric
# TODO: support other metric
...
@@ -108,16 +118,7 @@ def run(FLAGS, cfg, place):
...
@@ -108,16 +118,7 @@ def run(FLAGS, cfg, place):
clsid2catid
,
catid2name
=
get_category_info
(
anno_file
,
with_background
,
clsid2catid
,
catid2name
=
get_category_info
(
anno_file
,
with_background
,
use_default_label
)
use_default_label
)
mask_resolution
=
None
infer_res
=
get_infer_results
(
outs_res
,
eval_type
,
clsid2catid
,
im_info
)
if
'Mask'
in
cfg
.
architecture
and
cfg
[
'MaskPostProcess'
][
'mask_resolution'
]
is
not
None
:
mask_resolution
=
int
(
cfg
[
'MaskPostProcess'
][
'mask_resolution'
])
infer_res
=
get_infer_results
(
outs_res
,
eval_type
,
clsid2catid
,
im_info
,
mask_resolution
=
mask_resolution
)
eval_results
(
infer_res
,
cfg
.
metric
,
anno_file
)
eval_results
(
infer_res
,
cfg
.
metric
,
anno_file
)
...
...
tools/export_model.py
浏览文件 @
ad353419
...
@@ -61,7 +61,9 @@ def dygraph_to_static(model, save_dir, cfg):
...
@@ -61,7 +61,9 @@ def dygraph_to_static(model, save_dir, cfg):
if
image_shape
is
None
:
if
image_shape
is
None
:
image_shape
=
[
3
,
None
,
None
]
image_shape
=
[
3
,
None
,
None
]
# Save infer cfg
# Save infer cfg
dump_infer_config
(
cfg
,
os
.
path
.
join
(
save_dir
,
'infer_cfg.yml'
),
image_shape
)
dump_infer_config
(
cfg
,
os
.
path
.
join
(
save_dir
,
'infer_cfg.yml'
),
image_shape
,
model
)
input_spec
=
[{
input_spec
=
[{
"image"
:
InputSpec
(
"image"
:
InputSpec
(
...
...
tools/export_utils.py
浏览文件 @
ad353419
...
@@ -64,9 +64,11 @@ def parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape):
...
@@ -64,9 +64,11 @@ def parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape):
for
key
,
value
in
st
.
items
():
for
key
,
value
in
st
.
items
():
p
=
{
'type'
:
key
}
p
=
{
'type'
:
key
}
if
key
==
'ResizeOp'
:
if
key
==
'ResizeOp'
:
if
value
.
get
(
'keep_ratio'
,
False
):
if
value
.
get
(
'keep_ratio'
,
False
)
and
image_shape
[
1
]
is
not
None
:
max_size
=
max
(
image_shape
[
1
:])
max_size
=
max
(
image_shape
[
1
:])
image_shape
=
[
3
,
max_size
,
max_size
]
image_shape
=
[
3
,
max_size
,
max_size
]
value
[
'target_size'
]
=
image_shape
[
1
:]
p
.
update
(
value
)
p
.
update
(
value
)
preprocess_list
.
append
(
p
)
preprocess_list
.
append
(
p
)
batch_transforms
=
reader_cfg
.
get
(
'batch_transforms'
,
None
)
batch_transforms
=
reader_cfg
.
get
(
'batch_transforms'
,
None
)
...
@@ -74,7 +76,7 @@ def parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape):
...
@@ -74,7 +76,7 @@ def parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape):
methods
=
[
list
(
bt
.
keys
())[
0
]
for
bt
in
batch_transforms
]
methods
=
[
list
(
bt
.
keys
())[
0
]
for
bt
in
batch_transforms
]
for
bt
in
batch_transforms
:
for
bt
in
batch_transforms
:
for
key
,
value
in
bt
.
items
():
for
key
,
value
in
bt
.
items
():
if
key
==
'PadBatch'
:
if
key
==
'PadBatch
Op
'
:
preprocess_list
.
append
({
'type'
:
'PadStride'
})
preprocess_list
.
append
({
'type'
:
'PadStride'
})
preprocess_list
[
-
1
].
update
({
preprocess_list
[
-
1
].
update
({
'stride'
:
value
[
'pad_to_stride'
]
'stride'
:
value
[
'pad_to_stride'
]
...
@@ -84,7 +86,7 @@ def parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape):
...
@@ -84,7 +86,7 @@ def parse_reader(reader_cfg, dataset_cfg, metric, arch, image_shape):
return
with_background
,
preprocess_list
,
label_list
,
image_shape
return
with_background
,
preprocess_list
,
label_list
,
image_shape
def
dump_infer_config
(
config
,
path
,
image_shape
):
def
dump_infer_config
(
config
,
path
,
image_shape
,
model
):
arch_state
=
False
arch_state
=
False
from
ppdet.core.config.yaml_helpers
import
setup_orderdict
from
ppdet.core.config.yaml_helpers
import
setup_orderdict
setup_orderdict
()
setup_orderdict
()
...
@@ -107,10 +109,8 @@ def dump_infer_config(config, path, image_shape):
...
@@ -107,10 +109,8 @@ def dump_infer_config(config, path, image_shape):
'Architecture: {} is not supported for exporting model now'
.
format
(
'Architecture: {} is not supported for exporting model now'
.
format
(
infer_arch
))
infer_arch
))
os
.
_exit
(
0
)
os
.
_exit
(
0
)
if
'mask_post_process'
in
model
.
__dict__
:
if
'Mask'
in
config
[
'architecture'
]:
infer_cfg
[
'mask_resolution'
]
=
model
.
mask_post_process
.
mask_resolution
infer_cfg
[
'mask_resolution'
]
=
config
[
'MaskPostProcess'
][
'mask_resolution'
]
infer_cfg
[
'with_background'
],
infer_cfg
[
'Preprocess'
],
infer_cfg
[
infer_cfg
[
'with_background'
],
infer_cfg
[
'Preprocess'
],
infer_cfg
[
'label_list'
],
image_shape
=
parse_reader
(
'label_list'
],
image_shape
=
parse_reader
(
config
[
'TestReader'
],
config
[
'TestDataset'
],
config
[
'metric'
],
config
[
'TestReader'
],
config
[
'TestDataset'
],
config
[
'metric'
],
...
...
tools/infer.py
浏览文件 @
ad353419
...
@@ -153,23 +153,26 @@ def run(FLAGS, cfg, place):
...
@@ -153,23 +153,26 @@ def run(FLAGS, cfg, place):
data
=
data
,
data
=
data
,
input_def
=
cfg
.
TestReader
[
'inputs_def'
][
'fields'
],
input_def
=
cfg
.
TestReader
[
'inputs_def'
][
'fields'
],
mode
=
'infer'
)
mode
=
'infer'
)
im_info
=
[[
for
key
,
value
in
outs
.
items
():
data
[
fields
.
index
(
'im_shape'
)].
numpy
(),
outs
[
key
]
=
value
.
numpy
()
data
[
fields
.
index
(
'scale_factor'
)].
numpy
(),
im_shape
=
data
[
fields
.
index
(
'im_shape'
)].
numpy
()
data
[
fields
.
index
(
'im_id'
)].
numpy
()
scale_factor
=
data
[
fields
.
index
(
'scale_factor'
)].
numpy
()
]]
im_ids
=
data
[
fields
.
index
(
'im_id'
)].
numpy
()
im_ids
=
data
[
fields
.
index
(
'im_id'
)].
numpy
()
im_info
=
[
im_shape
,
scale_factor
,
im_ids
]
mask_resolution
=
None
if
'mask'
in
outs
and
'bbox'
in
outs
:
if
'Mask'
in
cfg
.
architecture
and
cfg
[
'MaskPostProcess'
][
mask_resolution
=
model
.
mask_post_process
.
mask_resolution
'mask_resolution'
]
is
not
None
:
from
ppdet.py_op.post_process
import
mask_post_process
mask_resolution
=
int
(
cfg
[
'MaskPostProcess'
][
'mask_resolution'
])
outs
[
'mask'
]
=
mask_post_process
(
outs
,
im_shape
,
scale_factor
,
batch_res
=
get_infer_results
(
mask_resolution
)
[
outs
],
outs
.
keys
(),
eval_type
=
[]
clsid2catid
,
if
'bbox'
in
outs
:
im_info
,
eval_type
.
append
(
'bbox'
)
mask_resolution
=
mask_resolution
)
if
'mask'
in
outs
:
eval_type
.
append
(
'mask'
)
batch_res
=
get_infer_results
([
outs
],
eval_type
,
clsid2catid
,
[
im_info
])
logger
.
info
(
'Infer iter {}'
.
format
(
iter_id
))
logger
.
info
(
'Infer iter {}'
.
format
(
iter_id
))
bbox_res
=
None
bbox_res
=
None
mask_res
=
None
mask_res
=
None
...
@@ -177,7 +180,6 @@ def run(FLAGS, cfg, place):
...
@@ -177,7 +180,6 @@ def run(FLAGS, cfg, place):
bbox_num
=
outs
[
'bbox_num'
]
bbox_num
=
outs
[
'bbox_num'
]
start
=
0
start
=
0
for
i
,
im_id
in
enumerate
(
im_ids
):
for
i
,
im_id
in
enumerate
(
im_ids
):
im_id
=
im_ids
[
i
]
image_path
=
imid2path
[
int
(
im_id
)]
image_path
=
imid2path
[
int
(
im_id
)]
image
=
Image
.
open
(
image_path
).
convert
(
'RGB'
)
image
=
Image
.
open
(
image_path
).
convert
(
'RGB'
)
end
=
start
+
bbox_num
[
i
]
end
=
start
+
bbox_num
[
i
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录