Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zpc421126
face_recognition
提交
245160c2
F
face_recognition
项目概览
zpc421126
/
face_recognition
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
face_recognition
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
245160c2
编写于
6月 26, 2017
作者:
A
Adam Geitgey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
All support for parallel processing in the CLI
上级
0e68c523
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
3 deletion
+43
-3
README.md
README.md
+12
-0
face_recognition/cli.py
face_recognition/cli.py
+31
-3
未找到文件。
README.md
浏览文件 @
245160c2
...
...
@@ -140,6 +140,18 @@ Barack Obama
unknown_person
```
Face recognition can also be done in parallel if you have a computer with
multiple CPU cores. For example if your system has 4 CPU cores, you can
process about 4 times as many images in the same amount of time by using
all your CPU cores in parallel.
If you are using Python 3.4 or newer, pass in a
`--cpus <number_of_cpu_cores_to_use>`
parameter:
```
bash
$
face_recognition
-cpus
4 ./pictures_of_people_i_know/ ./unknown_pictures/
```
You can also pass in
`--cpus -1`
to use all CPU cores in your system.
#### Python Module
...
...
face_recognition/cli.py
浏览文件 @
245160c2
...
...
@@ -6,7 +6,9 @@ import re
import
scipy.misc
import
warnings
import
face_recognition.api
as
face_recognition
import
multiprocessing
import
itertools
import
sys
def
scan_known_people
(
known_people_folder
):
known_names
=
[]
...
...
@@ -54,14 +56,40 @@ def image_files_in_folder(folder):
return
[
os
.
path
.
join
(
folder
,
f
)
for
f
in
os
.
listdir
(
folder
)
if
re
.
match
(
r
'.*\.(jpg|jpeg|png)'
,
f
,
flags
=
re
.
I
)]
def
process_images_in_process_pool
(
images_to_check
,
known_names
,
known_face_encodings
,
number_of_cpus
):
if
number_of_cpus
==
-
1
:
processes
=
None
else
:
processes
=
number_of_cpus
# macOS will crash due to a bug in libdispatch if you don't use 'forkserver'
context
=
multiprocessing
if
"forkserver"
in
multiprocessing
.
get_all_start_methods
():
context
=
multiprocessing
.
get_context
(
"forkserver"
)
pool
=
context
.
Pool
(
processes
=
processes
)
function_parameters
=
zip
(
images_to_check
,
itertools
.
repeat
(
known_names
),
itertools
.
repeat
(
known_face_encodings
))
pool
.
starmap
(
test_image
,
function_parameters
)
@
click
.
command
()
@
click
.
argument
(
'known_people_folder'
)
@
click
.
argument
(
'image_to_check'
)
def
main
(
known_people_folder
,
image_to_check
):
@
click
.
option
(
'--cpus'
,
default
=
1
,
help
=
'number of CPU cores to use in parallel (can speed up processing lots of images). -1 means "use all in system"'
)
def
main
(
known_people_folder
,
image_to_check
,
cpus
):
known_names
,
known_face_encodings
=
scan_known_people
(
known_people_folder
)
# Multi-core processing only supported on Python 3.4 or greater
if
(
sys
.
version_info
<
(
3
,
4
))
and
cpus
!=
1
:
click
.
echo
(
"WARNING: Multi-processing support requires Python 3.4 or greater. Falling back to single-threaded processing!"
)
cpus
=
1
if
os
.
path
.
isdir
(
image_to_check
):
[
test_image
(
image_file
,
known_names
,
known_face_encodings
)
for
image_file
in
image_files_in_folder
(
image_to_check
)]
if
cpus
==
1
:
[
test_image
(
image_file
,
known_names
,
known_face_encodings
)
for
image_file
in
image_files_in_folder
(
image_to_check
)]
else
:
process_images_in_process_pool
(
image_files_in_folder
(
image_to_check
),
known_names
,
known_face_encodings
,
cpus
)
else
:
test_image
(
image_to_check
,
known_names
,
known_face_encodings
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录