Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
a229530b
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
696
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看板
未验证
提交
a229530b
编写于
11月 05, 2021
作者:
Z
zhiboniu
提交者:
GitHub
11月 05, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add deploy keypoint infer save results (#4480)
上级
8a87d99e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
54 addition
and
8 deletion
+54
-8
deploy/python/det_keypoint_unite_infer.py
deploy/python/det_keypoint_unite_infer.py
+42
-7
deploy/python/det_keypoint_unite_utils.py
deploy/python/det_keypoint_unite_utils.py
+11
-1
deploy/python/visualize.py
deploy/python/visualize.py
+1
-0
未找到文件。
deploy/python/det_keypoint_unite_infer.py
浏览文件 @
a229530b
...
...
@@ -13,7 +13,7 @@
# limitations under the License.
import
os
import
json
import
cv2
import
math
import
numpy
as
np
...
...
@@ -80,7 +80,7 @@ def predict_with_given_det(image, det_res, keypoint_detector,
keypoint_res
=
{}
keypoint_res
[
'keypoint'
]
=
[
np
.
vstack
(
keypoint_vector
)
,
np
.
vstack
(
score_vector
)
np
.
vstack
(
keypoint_vector
)
.
tolist
(),
np
.
vstack
(
score_vector
).
tolist
(
)
]
if
len
(
keypoint_vector
)
>
0
else
[[],
[]]
keypoint_res
[
'bbox'
]
=
rect_vector
return
keypoint_res
...
...
@@ -89,8 +89,10 @@ def predict_with_given_det(image, det_res, keypoint_detector,
def
topdown_unite_predict
(
detector
,
topdown_keypoint_detector
,
image_list
,
keypoint_batch_size
=
1
):
keypoint_batch_size
=
1
,
save_res
=
False
):
det_timer
=
detector
.
get_timer
()
store_res
=
[]
for
i
,
img_file
in
enumerate
(
image_list
):
# Decode image in advance in det + pose prediction
det_timer
.
preprocess_time_s
.
start
()
...
...
@@ -114,6 +116,11 @@ def topdown_unite_predict(detector,
image
,
results
,
topdown_keypoint_detector
,
keypoint_batch_size
,
FLAGS
.
det_threshold
,
FLAGS
.
keypoint_threshold
,
FLAGS
.
run_benchmark
)
if
save_res
:
store_res
.
append
([
i
,
keypoint_res
[
'bbox'
],
[
keypoint_res
[
'keypoint'
][
0
],
keypoint_res
[
'keypoint'
][
1
]]
])
if
FLAGS
.
run_benchmark
:
cm
,
gm
,
gu
=
get_current_memory_mb
()
topdown_keypoint_detector
.
cpu_mem
+=
cm
...
...
@@ -127,12 +134,23 @@ def topdown_unite_predict(detector,
keypoint_res
,
visual_thread
=
FLAGS
.
keypoint_threshold
,
save_dir
=
FLAGS
.
output_dir
)
if
save_res
:
"""
1) store_res: a list of image_data
2) image_data: [imageid, rects, [keypoints, scores]]
3) rects: list of rect [xmin, ymin, xmax, ymax]
4) keypoints: 17(joint numbers)*[x, y, conf], total 51 data in list
5) scores: mean of all joint conf
"""
with
open
(
"det_keypoint_unite_image_results.json"
,
'w'
)
as
wf
:
json
.
dump
(
store_res
,
wf
,
indent
=
4
)
def
topdown_unite_predict_video
(
detector
,
topdown_keypoint_detector
,
camera_id
,
keypoint_batch_size
=
1
):
keypoint_batch_size
=
1
,
save_res
=
False
):
video_name
=
'output.mp4'
if
camera_id
!=
-
1
:
capture
=
cv2
.
VideoCapture
(
camera_id
)
...
...
@@ -150,9 +168,10 @@ def topdown_unite_predict_video(detector,
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
os
.
makedirs
(
FLAGS
.
output_dir
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
)
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
index
=
0
store_res
=
[]
while
(
1
):
ret
,
frame
=
capture
.
read
()
if
not
ret
:
...
...
@@ -172,6 +191,11 @@ def topdown_unite_predict_video(detector,
keypoint_res
,
visual_thread
=
FLAGS
.
keypoint_threshold
,
returnimg
=
True
)
if
save_res
:
store_res
.
append
([
index
,
keypoint_res
[
'bbox'
],
[
keypoint_res
[
'keypoint'
][
0
],
keypoint_res
[
'keypoint'
][
1
]]
])
writer
.
write
(
im
)
if
camera_id
!=
-
1
:
...
...
@@ -179,6 +203,16 @@ def topdown_unite_predict_video(detector,
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
writer
.
release
()
if
save_res
:
"""
1) store_res: a list of frame_data
2) frame_data: [frameid, rects, [keypoints, scores]]
3) rects: list of rect [xmin, ymin, xmax, ymax]
4) keypoints: 17(joint numbers)*[x, y, conf], total 51 data in list
5) scores: mean of all joint conf
"""
with
open
(
"det_keypoint_unite_video_results.json"
,
'w'
)
as
wf
:
json
.
dump
(
store_res
,
wf
,
indent
=
4
)
def
main
():
...
...
@@ -216,12 +250,13 @@ def main():
# predict from video file or camera video stream
if
FLAGS
.
video_file
is
not
None
or
FLAGS
.
camera_id
!=
-
1
:
topdown_unite_predict_video
(
detector
,
topdown_keypoint_detector
,
FLAGS
.
camera_id
,
FLAGS
.
keypoint_batch_size
)
FLAGS
.
camera_id
,
FLAGS
.
keypoint_batch_size
,
FLAGS
.
save_res
)
else
:
# predict from image
img_list
=
get_test_images
(
FLAGS
.
image_dir
,
FLAGS
.
image_file
)
topdown_unite_predict
(
detector
,
topdown_keypoint_detector
,
img_list
,
FLAGS
.
keypoint_batch_size
)
FLAGS
.
keypoint_batch_size
,
FLAGS
.
save_res
)
if
not
FLAGS
.
run_benchmark
:
detector
.
det_times
.
info
(
average
=
True
)
topdown_keypoint_detector
.
det_times
.
info
(
average
=
True
)
...
...
deploy/python/det_keypoint_unite_utils.py
浏览文件 @
a229530b
...
...
@@ -115,5 +115,15 @@ def argsparser():
type
=
bool
,
default
=
True
,
help
=
'whether to use darkpose to get better keypoint position predict '
)
parser
.
add_argument
(
'--save_res'
,
type
=
bool
,
default
=
False
,
help
=
(
"whether to save predict results to json file"
"1) store_res: a list of image_data"
"2) image_data: [imageid, rects, [keypoints, scores]]"
"3) rects: list of rect [xmin, ymin, xmax, ymax]"
"4) keypoints: 17(joint numbers)*[x, y, conf], total 51 data in list"
"5) scores: mean of all joint conf"
))
return
parser
deploy/python/visualize.py
浏览文件 @
a229530b
...
...
@@ -240,6 +240,7 @@ def draw_pose(imgfile,
raise
e
skeletons
,
scores
=
results
[
'keypoint'
]
skeletons
=
np
.
array
(
skeletons
)
kpt_nums
=
17
if
len
(
skeletons
)
>
0
:
kpt_nums
=
skeletons
.
shape
[
1
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录