Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
c28c889a
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
1 年多 前同步成功
通知
283
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看板
未验证
提交
c28c889a
编写于
12月 29, 2022
作者:
jm_12138
提交者:
GitHub
12月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update pyramidbox_lite_mobile_mask (#2179)
上级
283be69c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
79 addition
and
61 deletion
+79
-61
modules/image/face_detection/pyramidbox_lite_mobile_mask/README.md
...mage/face_detection/pyramidbox_lite_mobile_mask/README.md
+10
-1
modules/image/face_detection/pyramidbox_lite_mobile_mask/README_en.md
...e/face_detection/pyramidbox_lite_mobile_mask/README_en.md
+9
-1
modules/image/face_detection/pyramidbox_lite_mobile_mask/data_feed.py
...e/face_detection/pyramidbox_lite_mobile_mask/data_feed.py
+11
-13
modules/image/face_detection/pyramidbox_lite_mobile_mask/module.py
...mage/face_detection/pyramidbox_lite_mobile_mask/module.py
+31
-6
modules/image/face_detection/pyramidbox_lite_mobile_mask/processor.py
...e/face_detection/pyramidbox_lite_mobile_mask/processor.py
+6
-5
modules/image/face_detection/pyramidbox_lite_mobile_mask/test.py
.../image/face_detection/pyramidbox_lite_mobile_mask/test.py
+12
-35
未找到文件。
modules/image/face_detection/pyramidbox_lite_mobile_mask/README.md
浏览文件 @
c28c889a
...
@@ -179,6 +179,11 @@
...
@@ -179,6 +179,11 @@
# 打印预测结果
# 打印预测结果
print(r.json()["results"])
print(r.json()["results"])
```
```
-
### gradio app 支持
从 PaddleHub 2.3.1 开始支持使用链接 http://127.0.0.1:8866/gradio/pyramidbox_lite_mobile_mask 在浏览器中访问 pyramidbox_lite_mobile_mask 的 Gradio APP。
## 五、Paddle Lite部署
## 五、Paddle Lite部署
-
### 通过python执行以下代码,保存模型
-
### 通过python执行以下代码,保存模型
-
```python
-
```python
...
@@ -209,6 +214,10 @@
...
@@ -209,6 +214,10 @@
修复无法导出模型的问题
修复无法导出模型的问题
*
1.5.0
添加 Gradio APP 的支持
-
```shell
-
```shell
$ hub install pyramidbox_lite_mobile_mask==1.
4
.0
$ hub install pyramidbox_lite_mobile_mask==1.
5
.0
```
```
modules/image/face_detection/pyramidbox_lite_mobile_mask/README_en.md
浏览文件 @
c28c889a
...
@@ -154,6 +154,10 @@
...
@@ -154,6 +154,10 @@
# print prediction results
# print prediction results
print(r.json()["results"])
print(r.json()["results"])
```
```
-
### Gradio APP support
Starting with PaddleHub 2.3.1, the Gradio APP for pyramidbox_lite_mobile_mask is supported to be accessed in the browser using the link http://127.0.0.1:8866/gradio/pyramidbox_lite_mobile_mask.
## V.Paddle Lite Deployment
## V.Paddle Lite Deployment
-
### Save model demo
-
### Save model demo
-
```python
-
```python
...
@@ -185,6 +189,10 @@
...
@@ -185,6 +189,10 @@
Fix a bug of save_inference_model
Fix a bug of save_inference_model
*
1.5.0
Add Gradio APP support.
-
```shell
-
```shell
$ hub install pyramidbox_lite_mobile_mask==1.
4
.0
$ hub install pyramidbox_lite_mobile_mask==1.
5
.0
```
```
modules/image/face_detection/pyramidbox_lite_mobile_mask/data_feed.py
浏览文件 @
c28c889a
# coding=utf-8
# coding=utf-8
import
os
import
math
import
math
import
os
import
time
import
time
from
collections
import
OrderedDict
from
collections
import
OrderedDict
...
@@ -144,12 +144,11 @@ def reader(face_detector, shrink, confs_threshold, images, paths, use_gpu, use_m
...
@@ -144,12 +144,11 @@ def reader(face_detector, shrink, confs_threshold, images, paths, use_gpu, use_m
scale_res
=
list
()
scale_res
=
list
()
detect_faces
=
list
()
detect_faces
=
list
()
for
scale
in
multi_scales
:
for
scale
in
multi_scales
:
_detect_res
=
face_detector
.
face_detection
(
_detect_res
=
face_detector
.
face_detection
(
images
=
[
element
[
'org_im'
]],
images
=
[
element
[
'org_im'
]],
use_gpu
=
use_gpu
,
use_gpu
=
use_gpu
,
visualization
=
False
,
visualization
=
False
,
shrink
=
scale
,
shrink
=
scale
,
confs_threshold
=
confs_threshold
)
confs_threshold
=
confs_threshold
)
_s
=
list
()
_s
=
list
()
for
_face
in
_detect_res
[
0
][
'data'
]:
for
_face
in
_detect_res
[
0
][
'data'
]:
...
@@ -167,12 +166,11 @@ def reader(face_detector, shrink, confs_threshold, images, paths, use_gpu, use_m
...
@@ -167,12 +166,11 @@ def reader(face_detector, shrink, confs_threshold, images, paths, use_gpu, use_m
face
=
{
'left'
:
data
[
0
],
'top'
:
data
[
1
],
'right'
:
data
[
2
],
'bottom'
:
data
[
3
],
'confidence'
:
data
[
4
]}
face
=
{
'left'
:
data
[
0
],
'top'
:
data
[
1
],
'right'
:
data
[
2
],
'bottom'
:
data
[
3
],
'confidence'
:
data
[
4
]}
detect_faces
.
append
(
face
)
detect_faces
.
append
(
face
)
else
:
else
:
_detect_res
=
face_detector
.
face_detection
(
_detect_res
=
face_detector
.
face_detection
(
images
=
[
element
[
'org_im'
]],
images
=
[
element
[
'org_im'
]],
use_gpu
=
use_gpu
,
use_gpu
=
use_gpu
,
visualization
=
False
,
visualization
=
False
,
shrink
=
shrink
,
shrink
=
shrink
,
confs_threshold
=
confs_threshold
)
confs_threshold
=
confs_threshold
)
detect_faces
=
_detect_res
[
0
][
'data'
]
detect_faces
=
_detect_res
[
0
][
'data'
]
element
[
'preprocessed'
]
=
list
()
element
[
'preprocessed'
]
=
list
()
...
...
modules/image/face_detection/pyramidbox_lite_mobile_mask/module.py
浏览文件 @
c28c889a
...
@@ -7,14 +7,13 @@ import ast
...
@@ -7,14 +7,13 @@ import ast
import
os
import
os
import
numpy
as
np
import
numpy
as
np
import
paddle
from
paddle.inference
import
Config
from
paddle.inference
import
Config
from
paddle.inference
import
create_predictor
from
paddle.inference
import
create_predictor
import
paddlehub
as
hub
from
.data_feed
import
reader
from
.data_feed
import
reader
from
.processor
import
base64_to_cv2
from
.processor
import
base64_to_cv2
from
.processor
import
postprocess
from
.processor
import
postprocess
import
paddlehub
as
hub
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.module
import
runnable
from
paddlehub.module.module
import
runnable
from
paddlehub.module.module
import
serving
from
paddlehub.module.module
import
serving
...
@@ -27,8 +26,9 @@ from paddlehub.module.module import serving
...
@@ -27,8 +26,9 @@ from paddlehub.module.module import serving
author_email
=
""
,
author_email
=
""
,
summary
=
summary
=
"Pyramidbox-Lite-Mobile-Mask is a high-performance face detection model used to detect whether people wear masks."
,
"Pyramidbox-Lite-Mobile-Mask is a high-performance face detection model used to detect whether people wear masks."
,
version
=
"1.
4
.0"
)
version
=
"1.
5
.0"
)
class
PyramidBoxLiteMobileMask
:
class
PyramidBoxLiteMobileMask
:
def
__init__
(
self
,
face_detector_module
=
None
):
def
__init__
(
self
,
face_detector_module
=
None
):
"""
"""
Args:
Args:
...
@@ -46,8 +46,8 @@ class PyramidBoxLiteMobileMask:
...
@@ -46,8 +46,8 @@ class PyramidBoxLiteMobileMask:
"""
"""
predictor config setting
predictor config setting
"""
"""
model
=
self
.
default_pretrained_model_path
+
'.pdmodel'
model
=
self
.
default_pretrained_model_path
+
'.pdmodel'
params
=
self
.
default_pretrained_model_path
+
'.pdiparams'
params
=
self
.
default_pretrained_model_path
+
'.pdiparams'
cpu_config
=
Config
(
model
,
params
)
cpu_config
=
Config
(
model
,
params
)
cpu_config
.
disable_glog_info
()
cpu_config
.
disable_glog_info
()
cpu_config
.
disable_gpu
()
cpu_config
.
disable_gpu
()
...
@@ -244,3 +244,28 @@ class PyramidBoxLiteMobileMask:
...
@@ -244,3 +244,28 @@ class PyramidBoxLiteMobileMask:
type
=
ast
.
literal_eval
,
type
=
ast
.
literal_eval
,
default
=
0.6
,
default
=
0.6
,
help
=
"confidence threshold."
)
help
=
"confidence threshold."
)
def
create_gradio_app
(
self
):
import
gradio
as
gr
import
tempfile
import
os
from
PIL
import
Image
def
inference
(
image
,
shrink
,
confs_threshold
):
with
tempfile
.
TemporaryDirectory
()
as
temp_dir
:
self
.
face_detection
(
paths
=
[
image
],
use_gpu
=
False
,
visualization
=
True
,
output_dir
=
temp_dir
,
shrink
=
shrink
,
confs_threshold
=
confs_threshold
)
return
Image
.
open
(
os
.
path
.
join
(
temp_dir
,
os
.
listdir
(
temp_dir
)[
0
]))
interface
=
gr
.
Interface
(
inference
,
[
gr
.
inputs
.
Image
(
type
=
"filepath"
),
gr
.
Slider
(
0.0
,
1.0
,
0.5
,
step
=
0.01
),
gr
.
Slider
(
0.0
,
1.0
,
0.6
,
step
=
0.01
)
],
gr
.
outputs
.
Image
(
type
=
"ndarray"
),
title
=
'pyramidbox_lite_mobile_mask'
)
return
interface
modules/image/face_detection/pyramidbox_lite_mobile_mask/processor.py
浏览文件 @
c28c889a
...
@@ -3,13 +3,14 @@ from __future__ import absolute_import
...
@@ -3,13 +3,14 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
division
from
__future__
import
print_function
from
__future__
import
print_function
import
base64
import
os
import
os
import
time
import
time
import
base64
import
cv2
import
cv2
import
numpy
as
np
import
numpy
as
np
from
PIL
import
Image
,
ImageDraw
from
PIL
import
Image
from
PIL
import
ImageDraw
__all__
=
[
'base64_to_cv2'
,
'postprocess'
]
__all__
=
[
'base64_to_cv2'
,
'postprocess'
]
...
@@ -86,9 +87,9 @@ def draw_bounding_box_on_image(save_im_path, output_data):
...
@@ -86,9 +87,9 @@ def draw_bounding_box_on_image(save_im_path, output_data):
box_fill
=
(
255
)
box_fill
=
(
255
)
text_fill
=
(
0
)
text_fill
=
(
0
)
draw
.
rectangle
(
draw
.
rectangle
(
xy
=
(
bbox
[
'left'
],
bbox
[
'top'
]
-
(
textsize_height
+
5
),
bbox
[
'left'
]
+
textsize_width
+
10
,
xy
=
(
bbox
[
'left'
],
bbox
[
'top'
]
-
(
textsize_height
+
5
),
bbox
[
'left'
]
+
textsize_width
+
10
,
bbox
[
'top'
]
-
3
),
bbox
[
'top'
]
-
3
),
fill
=
box_fill
)
fill
=
box_fill
)
draw
.
text
(
xy
=
(
bbox
[
'left'
],
bbox
[
'top'
]
-
15
),
text
=
text
,
fill
=
text_fill
)
draw
.
text
(
xy
=
(
bbox
[
'left'
],
bbox
[
'top'
]
-
15
),
text
=
text
,
fill
=
text_fill
)
image
.
save
(
save_im_path
)
image
.
save
(
save_im_path
)
...
...
modules/image/face_detection/pyramidbox_lite_mobile_mask/test.py
浏览文件 @
c28c889a
...
@@ -4,13 +4,14 @@ import unittest
...
@@ -4,13 +4,14 @@ import unittest
import
cv2
import
cv2
import
requests
import
requests
import
paddlehub
as
hub
import
paddlehub
as
hub
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'0'
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'0'
class
TestHubModule
(
unittest
.
TestCase
):
class
TestHubModule
(
unittest
.
TestCase
):
@
classmethod
@
classmethod
def
setUpClass
(
cls
)
->
None
:
def
setUpClass
(
cls
)
->
None
:
img_url
=
'https://ai-studio-static-online.cdn.bcebos.com/7799a8ccc5f6471b9d56fb6eff94f82a08b70ca2c7594d3f99877e366c0a2619'
img_url
=
'https://ai-studio-static-online.cdn.bcebos.com/7799a8ccc5f6471b9d56fb6eff94f82a08b70ca2c7594d3f99877e366c0a2619'
...
@@ -29,11 +30,7 @@ class TestHubModule(unittest.TestCase):
...
@@ -29,11 +30,7 @@ class TestHubModule(unittest.TestCase):
shutil
.
rmtree
(
'detection_result'
)
shutil
.
rmtree
(
'detection_result'
)
def
test_face_detection1
(
self
):
def
test_face_detection1
(
self
):
results
=
self
.
module
.
face_detection
(
results
=
self
.
module
.
face_detection
(
paths
=
[
'tests/test.jpg'
],
use_gpu
=
False
,
visualization
=
False
)
paths
=
[
'tests/test.jpg'
],
use_gpu
=
False
,
visualization
=
False
)
bbox
=
results
[
0
][
'data'
][
0
]
bbox
=
results
[
0
][
'data'
][
0
]
label
=
bbox
[
'label'
]
label
=
bbox
[
'label'
]
...
@@ -42,7 +39,7 @@ class TestHubModule(unittest.TestCase):
...
@@ -42,7 +39,7 @@ class TestHubModule(unittest.TestCase):
right
=
bbox
[
'right'
]
right
=
bbox
[
'right'
]
top
=
bbox
[
'top'
]
top
=
bbox
[
'top'
]
bottom
=
bbox
[
'bottom'
]
bottom
=
bbox
[
'bottom'
]
self
.
assertEqual
(
label
,
'NO MASK'
)
self
.
assertEqual
(
label
,
'NO MASK'
)
self
.
assertTrue
(
confidence
>
0.5
)
self
.
assertTrue
(
confidence
>
0.5
)
self
.
assertTrue
(
1000
<
left
<
4000
)
self
.
assertTrue
(
1000
<
left
<
4000
)
...
@@ -51,11 +48,7 @@ class TestHubModule(unittest.TestCase):
...
@@ -51,11 +48,7 @@ class TestHubModule(unittest.TestCase):
self
.
assertTrue
(
0
<
bottom
<
2000
)
self
.
assertTrue
(
0
<
bottom
<
2000
)
def
test_face_detection2
(
self
):
def
test_face_detection2
(
self
):
results
=
self
.
module
.
face_detection
(
results
=
self
.
module
.
face_detection
(
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
False
,
visualization
=
False
)
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
False
,
visualization
=
False
)
bbox
=
results
[
0
][
'data'
][
0
]
bbox
=
results
[
0
][
'data'
][
0
]
label
=
bbox
[
'label'
]
label
=
bbox
[
'label'
]
...
@@ -64,7 +57,7 @@ class TestHubModule(unittest.TestCase):
...
@@ -64,7 +57,7 @@ class TestHubModule(unittest.TestCase):
right
=
bbox
[
'right'
]
right
=
bbox
[
'right'
]
top
=
bbox
[
'top'
]
top
=
bbox
[
'top'
]
bottom
=
bbox
[
'bottom'
]
bottom
=
bbox
[
'bottom'
]
self
.
assertEqual
(
label
,
'NO MASK'
)
self
.
assertEqual
(
label
,
'NO MASK'
)
self
.
assertTrue
(
confidence
>
0.5
)
self
.
assertTrue
(
confidence
>
0.5
)
self
.
assertTrue
(
1000
<
left
<
4000
)
self
.
assertTrue
(
1000
<
left
<
4000
)
...
@@ -73,11 +66,7 @@ class TestHubModule(unittest.TestCase):
...
@@ -73,11 +66,7 @@ class TestHubModule(unittest.TestCase):
self
.
assertTrue
(
0
<
bottom
<
2000
)
self
.
assertTrue
(
0
<
bottom
<
2000
)
def
test_face_detection3
(
self
):
def
test_face_detection3
(
self
):
results
=
self
.
module
.
face_detection
(
results
=
self
.
module
.
face_detection
(
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
False
,
visualization
=
True
)
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
False
,
visualization
=
True
)
bbox
=
results
[
0
][
'data'
][
0
]
bbox
=
results
[
0
][
'data'
][
0
]
label
=
bbox
[
'label'
]
label
=
bbox
[
'label'
]
...
@@ -86,7 +75,7 @@ class TestHubModule(unittest.TestCase):
...
@@ -86,7 +75,7 @@ class TestHubModule(unittest.TestCase):
right
=
bbox
[
'right'
]
right
=
bbox
[
'right'
]
top
=
bbox
[
'top'
]
top
=
bbox
[
'top'
]
bottom
=
bbox
[
'bottom'
]
bottom
=
bbox
[
'bottom'
]
self
.
assertEqual
(
label
,
'NO MASK'
)
self
.
assertEqual
(
label
,
'NO MASK'
)
self
.
assertTrue
(
confidence
>
0.5
)
self
.
assertTrue
(
confidence
>
0.5
)
self
.
assertTrue
(
1000
<
left
<
4000
)
self
.
assertTrue
(
1000
<
left
<
4000
)
...
@@ -95,11 +84,7 @@ class TestHubModule(unittest.TestCase):
...
@@ -95,11 +84,7 @@ class TestHubModule(unittest.TestCase):
self
.
assertTrue
(
0
<
bottom
<
2000
)
self
.
assertTrue
(
0
<
bottom
<
2000
)
def
test_face_detection4
(
self
):
def
test_face_detection4
(
self
):
results
=
self
.
module
.
face_detection
(
results
=
self
.
module
.
face_detection
(
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
True
,
visualization
=
False
)
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
True
,
visualization
=
False
)
bbox
=
results
[
0
][
'data'
][
0
]
bbox
=
results
[
0
][
'data'
][
0
]
label
=
bbox
[
'label'
]
label
=
bbox
[
'label'
]
...
@@ -108,7 +93,7 @@ class TestHubModule(unittest.TestCase):
...
@@ -108,7 +93,7 @@ class TestHubModule(unittest.TestCase):
right
=
bbox
[
'right'
]
right
=
bbox
[
'right'
]
top
=
bbox
[
'top'
]
top
=
bbox
[
'top'
]
bottom
=
bbox
[
'bottom'
]
bottom
=
bbox
[
'bottom'
]
self
.
assertEqual
(
label
,
'NO MASK'
)
self
.
assertEqual
(
label
,
'NO MASK'
)
self
.
assertTrue
(
confidence
>
0.5
)
self
.
assertTrue
(
confidence
>
0.5
)
self
.
assertTrue
(
1000
<
left
<
4000
)
self
.
assertTrue
(
1000
<
left
<
4000
)
...
@@ -117,18 +102,10 @@ class TestHubModule(unittest.TestCase):
...
@@ -117,18 +102,10 @@ class TestHubModule(unittest.TestCase):
self
.
assertTrue
(
0
<
bottom
<
2000
)
self
.
assertTrue
(
0
<
bottom
<
2000
)
def
test_face_detection5
(
self
):
def
test_face_detection5
(
self
):
self
.
assertRaises
(
self
.
assertRaises
(
AssertionError
,
self
.
module
.
face_detection
,
paths
=
[
'no.jpg'
])
AssertionError
,
self
.
module
.
face_detection
,
paths
=
[
'no.jpg'
]
)
def
test_face_detection6
(
self
):
def
test_face_detection6
(
self
):
self
.
assertRaises
(
self
.
assertRaises
(
AttributeError
,
self
.
module
.
face_detection
,
images
=
[
'test.jpg'
])
AttributeError
,
self
.
module
.
face_detection
,
images
=
[
'test.jpg'
]
)
def
test_save_inference_model
(
self
):
def
test_save_inference_model
(
self
):
self
.
module
.
save_inference_model
(
'./inference/model'
)
self
.
module
.
save_inference_model
(
'./inference/model'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录