Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
84e25e9f
P
PaddleX
项目概览
PaddlePaddle
/
PaddleX
通知
138
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
43
列表
看板
标记
里程碑
合并请求
5
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleX
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
43
Issue
43
列表
看板
标记
里程碑
合并请求
5
合并请求
5
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
84e25e9f
编写于
7月 08, 2020
作者:
F
FlyingQianMM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rewrite postprocess for rcnn predict
上级
5b145d45
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
78 addition
and
38 deletion
+78
-38
paddlex/cv/models/faster_rcnn.py
paddlex/cv/models/faster_rcnn.py
+15
-12
paddlex/cv/models/mask_rcnn.py
paddlex/cv/models/mask_rcnn.py
+19
-15
paddlex/deploy.py
paddlex/deploy.py
+44
-11
未找到文件。
paddlex/cv/models/faster_rcnn.py
浏览文件 @
84e25e9f
...
...
@@ -409,14 +409,7 @@ class FasterRCNN(BaseAPI):
return
im
,
im_resize_info
,
im_shape
@
staticmethod
def
_postprocess
(
results
,
test_outputs_keys
,
batch_size
,
num_classes
,
labels
):
res
=
{
k
:
(
np
.
array
(
v
),
v
.
recursive_sequence_lengths
())
for
k
,
v
in
zip
(
list
(
test_outputs_keys
),
results
)
}
res
[
'im_id'
]
=
(
np
.
array
(
[[
i
]
for
i
in
range
(
batch_size
)]).
astype
(
'int32'
),
[])
def
_postprocess
(
res
,
batch_size
,
num_classes
,
labels
):
clsid2catid
=
dict
({
i
:
i
for
i
in
range
(
num_classes
)})
xywh_results
=
bbox2out
([
res
],
clsid2catid
)
preds
=
[[]
for
i
in
range
(
batch_size
)]
...
...
@@ -463,8 +456,13 @@ class FasterRCNN(BaseAPI):
return_numpy
=
False
,
use_program_cache
=
True
)
preds
=
FasterRCNN
.
_postprocess
(
result
,
list
(
self
.
test_outputs
.
keys
()),
res
=
{
k
:
(
np
.
array
(
v
),
v
.
recursive_sequence_lengths
())
for
k
,
v
in
zip
(
list
(
test_outputs_keys
),
results
)
}
res
[
'im_id'
]
=
(
np
.
array
(
[[
i
]
for
i
in
range
(
batch_size
)]).
astype
(
'int32'
),
[])
preds
=
FasterRCNN
.
_postprocess
(
res
,
len
(
images
),
self
.
num_classes
,
self
.
labels
)
...
...
@@ -507,8 +505,13 @@ class FasterRCNN(BaseAPI):
return_numpy
=
False
,
use_program_cache
=
True
)
preds
=
FasterRCNN
.
_postprocess
(
result
,
list
(
self
.
test_outputs
.
keys
()),
res
=
{
k
:
(
np
.
array
(
v
),
v
.
recursive_sequence_lengths
())
for
k
,
v
in
zip
(
list
(
test_outputs_keys
),
results
)
}
res
[
'im_id'
]
=
(
np
.
array
(
[[
i
]
for
i
in
range
(
batch_size
)]).
astype
(
'int32'
),
[])
preds
=
FasterRCNN
.
_postprocess
(
res
,
len
(
img_file_list
),
self
.
num_classes
,
self
.
labels
)
...
...
paddlex/cv/models/mask_rcnn.py
浏览文件 @
84e25e9f
...
...
@@ -338,15 +338,8 @@ class MaskRCNN(FasterRCNN):
return
metrics
@
staticmethod
def
_postprocess
(
results
,
im_shape
,
test_outputs_keys
,
batch_size
,
num_classes
,
mask_head_resolution
,
labels
):
res
=
{
k
:
(
np
.
array
(
v
),
v
.
recursive_sequence_lengths
())
for
k
,
v
in
zip
(
list
(
test_outputs_keys
),
results
)
}
res
[
'im_id'
]
=
(
np
.
array
(
[[
i
]
for
i
in
range
(
batch_size
)]).
astype
(
'int32'
),
[])
res
[
'im_shape'
]
=
(
np
.
array
(
im_shape
),
[])
def
_postprocess
(
res
,
batch_size
,
num_classes
,
mask_head_resolution
,
labels
):
clsid2catid
=
dict
({
i
:
i
for
i
in
range
(
num_classes
)})
xywh_results
=
bbox2out
([
res
],
clsid2catid
)
segm_results
=
mask2out
([
res
],
clsid2catid
,
mask_head_resolution
)
...
...
@@ -398,8 +391,14 @@ class MaskRCNN(FasterRCNN):
return_numpy
=
False
,
use_program_cache
=
True
)
preds
=
MaskRCNN
.
_postprocess
(
result
,
im_shape
,
list
(
self
.
test_outputs
.
keys
()),
res
=
{
k
:
(
np
.
array
(
v
),
v
.
recursive_sequence_lengths
())
for
k
,
v
in
zip
(
list
(
test_outputs_keys
),
results
)
}
res
[
'im_id'
]
=
(
np
.
array
(
[[
i
]
for
i
in
range
(
batch_size
)]).
astype
(
'int32'
),
[])
res
[
'im_shape'
]
=
(
np
.
array
(
im_shape
),
[])
preds
=
MaskRCNN
.
_postprocess
(
res
,
len
(
images
),
self
.
num_classes
,
self
.
mask_head_resolution
,
self
.
labels
)
...
...
@@ -442,9 +441,14 @@ class MaskRCNN(FasterRCNN):
return_numpy
=
False
,
use_program_cache
=
True
)
preds
=
MaskRCNN
.
_postprocess
(
result
,
im_shape
,
list
(
self
.
test_outputs
.
keys
()),
len
(
img_file_list
),
self
.
num_classes
,
res
=
{
k
:
(
np
.
array
(
v
),
v
.
recursive_sequence_lengths
())
for
k
,
v
in
zip
(
list
(
test_outputs_keys
),
results
)
}
res
[
'im_id'
]
=
(
np
.
array
(
[[
i
]
for
i
in
range
(
batch_size
)]).
astype
(
'int32'
),
[])
res
[
'im_shape'
]
=
(
np
.
array
(
im_shape
),
[])
preds
=
MaskRCNN
.
_postprocess
(
res
,
len
(
images
),
self
.
num_classes
,
self
.
mask_head_resolution
,
self
.
labels
)
return
preds
paddlex/deploy.py
浏览文件 @
84e25e9f
...
...
@@ -155,23 +155,42 @@ class Predictor:
res
[
'im_info'
]
=
im_info
return
res
def
postprocess
(
self
,
results
,
topk
=
1
,
batch_size
=
1
,
im_shape
=
None
):
def
postprocess
(
self
,
results
,
topk
=
1
,
batch_size
=
1
,
im_shape
=
None
,
im_info
=
None
):
def
offset_to_lengths
(
lod
):
offset
=
lod
[
0
]
lengths
=
[
offset
[
i
+
1
]
-
offset
[
i
]
for
i
in
range
(
len
(
offset
)
-
1
)
]
return
[
lengths
]
if
self
.
model_type
==
"classifier"
:
true_topk
=
min
(
self
.
num_classes
,
topk
)
preds
=
BaseClassifier
.
_postprocess
(
results
,
true_topk
,
preds
=
BaseClassifier
.
_postprocess
(
[
results
[
0
][
0
]]
,
true_topk
,
self
.
labels
)
elif
self
.
model_type
==
"detector"
:
res
=
{
'bbox'
:
(
results
[
0
][
0
],
offset_to_lengths
(
results
[
0
][
1
])),
}
res
[
'im_id'
]
=
(
np
.
array
(
[[
i
]
for
i
in
range
(
batch_size
)]).
astype
(
'int32'
),
[[]])
if
self
.
model_name
==
"YOLOv3"
:
preds
=
YOLOv3
.
_postprocess
(
res
ults
,
[
'bbox'
],
batch_size
,
self
.
num_classes
,
self
.
labels
)
preds
=
YOLOv3
.
_postprocess
(
res
,
batch_size
,
self
.
num_classes
,
self
.
labels
)
elif
self
.
model_name
==
"FasterRCNN"
:
preds
=
FasterRCNN
.
_postprocess
(
res
ults
,
[
'bbox'
]
,
batch_size
,
preds
=
FasterRCNN
.
_postprocess
(
res
,
batch_size
,
self
.
num_classes
,
self
.
labels
)
elif
self
.
model_name
==
"MaskRCNN"
:
res
[
'mask'
]
=
(
results
[
1
][
0
],
offset_to_lengths
(
results
[
1
][
1
]))
res
[
'im_shape'
]
=
(
im_shape
,
[])
preds
=
MaskRCNN
.
_postprocess
(
res
ults
,
[
'bbox'
,
'mask'
]
,
batch_size
,
self
.
num_classes
,
res
,
batch_size
,
self
.
num_classes
,
self
.
mask_head_resolution
,
self
.
labels
)
elif
self
.
model_type
==
"segmenter"
:
res
=
[
results
[
0
][
0
],
results
[
1
][
0
]]
preds
=
DeepLabv3p
.
_postprocess
(
res
,
im_info
)
return
preds
def
raw_predict
(
self
,
inputs
):
...
...
@@ -191,7 +210,9 @@ class Predictor:
output_results
=
list
()
for
name
in
output_names
:
output_tensor
=
self
.
predictor
.
get_output_tensor
(
name
)
output_results
.
append
(
output_tensor
.
copy_to_cpu
())
output_tensor_lod
=
output_tensor
.
lod
()
output_results
.
append
(
[
output_tensor
.
copy_to_cpu
(),
output_tensor_lod
])
return
output_results
def
predict
(
self
,
image
,
topk
=
1
):
...
...
@@ -207,8 +228,14 @@ class Predictor:
model_pred
=
self
.
raw_predict
(
preprocessed_input
)
im_shape
=
None
if
'im_shape'
not
in
preprocessed_input
else
preprocessed_input
[
'im_shape'
]
im_info
=
None
if
'im_info'
not
in
preprocessed_input
else
preprocessed_input
[
'im_info'
]
results
=
self
.
postprocess
(
model_pred
,
topk
=
topk
,
batch_size
=
1
,
im_shape
=
im_shape
)
model_pred
,
topk
=
topk
,
batch_size
=
1
,
im_shape
=
im_shape
,
im_info
=
im_info
)
return
results
[
0
]
...
...
@@ -223,9 +250,15 @@ class Predictor:
"""
preprocessed_input
=
self
.
preprocess
(
image_list
)
model_pred
=
self
.
raw_predict
(
preprocessed_input
)
im_shape
=
None
if
'im_shape'
in
preprocessed_input
else
preprocessed_input
[
im_shape
=
None
if
'im_shape'
not
in
preprocessed_input
else
preprocessed_input
[
'im_shape'
]
im_info
=
None
if
'im_info'
not
in
preprocessed_input
else
preprocessed_input
[
'im_info'
]
results
=
self
.
postprocess
(
model_pred
,
topk
=
topk
,
batch_size
=
1
,
im_shape
=
im_shape
)
model_pred
,
topk
=
topk
,
batch_size
=
len
(
image_list
),
im_shape
=
im_shape
,
im_info
=
im_info
)
return
results
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录