Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
07f287d7
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
07f287d7
编写于
3月 02, 2020
作者:
C
Channingss
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support show detection result, support get video resolution automatically
上级
3a992a82
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
59 deletion
+64
-59
demo/mask_detection/python/README.md
demo/mask_detection/python/README.md
+2
-2
demo/mask_detection/python/infer.py
demo/mask_detection/python/infer.py
+62
-57
未找到文件。
demo/mask_detection/python/README.md
浏览文件 @
07f287d7
...
@@ -53,8 +53,8 @@ python infer.py --models_dir=/path/to/models --img_paths=/path/to/images --video
...
@@ -53,8 +53,8 @@ python infer.py --models_dir=/path/to/models --img_paths=/path/to/images --video
| models_dir | Yes|上述导出的模型路径 |
| models_dir | Yes|上述导出的模型路径 |
| img_paths |img_paths/video_path 二选一|需要预测的图片目录 |
| img_paths |img_paths/video_path 二选一|需要预测的图片目录 |
| video_path |img_paths/video_path 二选一|需要预测的视频目录|
| video_path |img_paths/video_path 二选一|需要预测的视频目录|
|
video_size |No|预测视频分辨率大小(w,h)
|
|
use_camera |No|是否打开摄像头进行预测,默认为False
|
|
use_camera |No|是否打开摄像头进行预测
|
|
open_imshow |No|是否进行检测结果实时绘图,默认为False
|
| use_gpu |No|是否GPU,默认为False|
| use_gpu |No|是否GPU,默认为False|
说明:
说明:
...
...
demo/mask_detection/python/infer.py
浏览文件 @
07f287d7
...
@@ -33,30 +33,27 @@ import argparse
...
@@ -33,30 +33,27 @@ import argparse
def
parse_args
():
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
'mask detection.'
)
parser
=
argparse
.
ArgumentParser
(
'mask detection.'
)
parser
.
add_argument
(
'--models_dir'
,
parser
.
add_argument
(
type
=
str
,
'--models_dir'
,
type
=
str
,
default
=
''
,
help
=
'path of models.'
)
default
=
''
,
parser
.
add_argument
(
help
=
'path of models.'
)
'--img_paths'
,
type
=
str
,
default
=
''
,
help
=
'path of images'
)
parser
.
add_argument
(
'--img_paths'
,
parser
.
add_argument
(
type
=
str
,
'--video_path'
,
type
=
str
,
default
=
''
,
help
=
'path of video.'
)
default
=
''
,
parser
.
add_argument
(
help
=
'path of images'
)
'--use_camera'
,
parser
.
add_argument
(
'--video_path'
,
type
=
bool
,
type
=
str
,
default
=
False
,
default
=
''
,
help
=
'switch detect video or camera, default:video.'
)
help
=
'path of video.'
)
parser
.
add_argument
(
parser
.
add_argument
(
'--video_size'
,
'--open_imshow'
,
type
=
tuple
,
type
=
bool
,
default
=
(
1920
,
1080
),
default
=
False
,
help
=
'size of video.'
)
help
=
'visualize results in real time.'
)
parser
.
add_argument
(
'--use_camera'
,
parser
.
add_argument
(
type
=
bool
,
'--use_gpu'
,
default
=
False
,
type
=
bool
,
help
=
'switch detect video or camera, default:video.'
)
default
=
False
,
parser
.
add_argument
(
'--use_gpu'
,
help
=
'switch cpu/gpu, default:cpu.'
)
type
=
bool
,
default
=
False
,
help
=
'switch cpu/gpu, default:cpu.'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
return
args
return
args
...
@@ -108,10 +105,11 @@ class MaskClassifier:
...
@@ -108,10 +105,11 @@ class MaskClassifier:
h
,
w
=
self
.
EVAL_SIZE
[
1
],
self
.
EVAL_SIZE
[
0
]
h
,
w
=
self
.
EVAL_SIZE
[
1
],
self
.
EVAL_SIZE
[
0
]
inputs
=
[]
inputs
=
[]
for
face
in
faces
:
for
face
in
faces
:
im
=
cv2
.
resize
(
face
.
rect_data
,
(
128
,
128
),
im
=
cv2
.
resize
(
fx
=
0
,
face
.
rect_data
,
(
128
,
128
),
fy
=
0
,
fx
=
0
,
interpolation
=
cv2
.
INTER_CUBIC
)
fy
=
0
,
interpolation
=
cv2
.
INTER_CUBIC
)
# HWC -> CHW
# HWC -> CHW
im
=
im
.
swapaxes
(
1
,
2
)
im
=
im
.
swapaxes
(
1
,
2
)
im
=
im
.
swapaxes
(
0
,
1
)
im
=
im
.
swapaxes
(
0
,
1
)
...
@@ -151,10 +149,8 @@ class FaceDetector:
...
@@ -151,10 +149,8 @@ class FaceDetector:
def
Preprocess
(
self
,
image
,
shrink
):
def
Preprocess
(
self
,
image
,
shrink
):
h
,
w
=
int
(
image
.
shape
[
1
]
*
shrink
),
int
(
image
.
shape
[
0
]
*
shrink
)
h
,
w
=
int
(
image
.
shape
[
1
]
*
shrink
),
int
(
image
.
shape
[
0
]
*
shrink
)
im
=
cv2
.
resize
(
image
,
(
h
,
w
),
im
=
cv2
.
resize
(
fx
=
0
,
image
,
(
h
,
w
),
fx
=
0
,
fy
=
0
,
interpolation
=
cv2
.
INTER_CUBIC
)
fy
=
0
,
interpolation
=
cv2
.
INTER_CUBIC
)
# HWC -> CHW
# HWC -> CHW
im
=
im
.
swapaxes
(
1
,
2
)
im
=
im
.
swapaxes
(
1
,
2
)
im
=
im
.
swapaxes
(
0
,
1
)
im
=
im
.
swapaxes
(
0
,
1
)
...
@@ -194,16 +190,18 @@ class FaceDetector:
...
@@ -194,16 +190,18 @@ class FaceDetector:
def
predict_images
(
args
):
def
predict_images
(
args
):
detector
=
FaceDetector
(
model_dir
=
args
.
models_dir
+
'/pyramidbox_lite/'
,
detector
=
FaceDetector
(
mean
=
[
104.0
,
177.0
,
123.0
],
model_dir
=
args
.
models_dir
+
'/pyramidbox_lite/'
,
scale
=
[
0.007843
,
0.007843
,
0.007843
],
mean
=
[
104.0
,
177.0
,
123.0
],
use_gpu
=
args
.
use_gpu
,
scale
=
[
0.007843
,
0.007843
,
0.007843
],
threshold
=
0.7
)
use_gpu
=
args
.
use_gpu
,
threshold
=
0.7
)
classifier
=
MaskClassifier
(
model_dir
=
args
.
models_dir
+
'/mask_detector/'
,
mean
=
[
0.5
,
0.5
,
0.5
],
classifier
=
MaskClassifier
(
scale
=
[
1.0
,
1.0
,
1.0
],
model_dir
=
args
.
models_dir
+
'/mask_detector/'
,
use_gpu
=
args
.
use_gpu
)
mean
=
[
0.5
,
0.5
,
0.5
],
scale
=
[
1.0
,
1.0
,
1.0
],
use_gpu
=
args
.
use_gpu
)
names
=
[]
names
=
[]
image_paths
=
[]
image_paths
=
[]
for
name
in
os
.
listdir
(
args
.
img_paths
):
for
name
in
os
.
listdir
(
args
.
img_paths
):
...
@@ -229,26 +227,29 @@ def predict_video(args, im_shape=(1920, 1080), use_camera=False):
...
@@ -229,26 +227,29 @@ def predict_video(args, im_shape=(1920, 1080), use_camera=False):
capture
=
cv2
.
VideoCapture
(
0
)
capture
=
cv2
.
VideoCapture
(
0
)
else
:
else
:
capture
=
cv2
.
VideoCapture
(
args
.
video_path
)
capture
=
cv2
.
VideoCapture
(
args
.
video_path
)
detector
=
FaceDetector
(
detector
=
FaceDetector
(
model_dir
=
args
.
models_dir
+
'/pyramidbox_lite/'
,
model_dir
=
args
.
models_dir
+
'/pyramidbox_lite/'
,
mean
=
[
104.0
,
177.0
,
123.0
],
mean
=
[
104.0
,
177.0
,
123.0
],
scale
=
[
0.007843
,
0.007843
,
0.007843
],
scale
=
[
0.007843
,
0.007843
,
0.007843
],
use_gpu
=
args
.
use_gpu
,
use_gpu
=
args
.
use_gpu
,
threshold
=
0.7
)
threshold
=
0.7
)
classifier
=
MaskClassifier
(
model_dir
=
args
.
models_dir
+
'/mask_detector/'
,
classifier
=
MaskClassifier
(
mean
=
[
0.5
,
0.5
,
0.5
],
model_dir
=
args
.
models_dir
+
'/mask_detector/'
,
scale
=
[
1.0
,
1.0
,
1.0
],
mean
=
[
0.5
,
0.5
,
0.5
],
use_gpu
=
args
.
use_gpu
)
scale
=
[
1.0
,
1.0
,
1.0
],
use_gpu
=
args
.
use_gpu
)
path
=
'./result'
path
=
'./result'
isExists
=
os
.
path
.
exists
(
path
)
isExists
=
os
.
path
.
exists
(
path
)
if
not
isExists
:
if
not
isExists
:
os
.
makedirs
(
path
)
os
.
makedirs
(
path
)
fps
=
30
fps
=
30
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
writer
=
cv2
.
VideoWriter
(
os
.
path
.
join
(
path
,
'result.mp4'
),
fourcc
,
fps
,
writer
=
cv2
.
VideoWriter
(
args
.
video_size
)
os
.
path
.
join
(
path
,
'result.mp4'
),
fourcc
,
fps
,
(
width
,
height
)
)
import
time
import
time
start_time
=
time
.
time
()
start_time
=
time
.
time
()
index
=
0
index
=
0
...
@@ -263,8 +264,12 @@ def predict_video(args, im_shape=(1920, 1080), use_camera=False):
...
@@ -263,8 +264,12 @@ def predict_video(args, im_shape=(1920, 1080), use_camera=False):
end_pre
=
time
.
time
()
end_pre
=
time
.
time
()
im
=
VisualizeResult
(
frame
,
det_out
)
im
=
VisualizeResult
(
frame
,
det_out
)
writer
.
write
(
im
)
writer
.
write
(
im
)
if
args
.
open_imshow
:
cv2
.
imshow
(
'Mask Detection'
,
im
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
end_time
=
time
.
time
()
end_time
=
time
.
time
()
print
(
"
include read ti
me:"
,
(
end_time
-
start_time
)
/
index
)
print
(
"
Average prediction time per fra
me:"
,
(
end_time
-
start_time
)
/
index
)
writer
.
release
()
writer
.
release
()
...
@@ -273,5 +278,5 @@ if __name__ == "__main__":
...
@@ -273,5 +278,5 @@ if __name__ == "__main__":
print
(
args
.
models_dir
)
print
(
args
.
models_dir
)
if
args
.
img_paths
!=
''
:
if
args
.
img_paths
!=
''
:
predict_images
(
args
)
predict_images
(
args
)
elif
args
.
video_path
!=
''
:
elif
args
.
video_path
!=
''
or
args
.
use_camera
:
predict_video
(
args
)
predict_video
(
args
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录