如何解决如何使用DeepFace.detectFace实际检测图像中的人脸?
我正在尝试识别和计算包含图片的文件夹的每张图片中人脸的数量,我正在使用Deepface完成这项工作。我在网络上仅找到一个对函数DeepFace.detectFace()
的引用,据说可以识别人脸,但是我在实现该框架时遇到了一些问题,除此功能之外,我没有找到该功能的任何其他引用:Face Alignment for Face Recognition in Python within OpenCV
输入文件仅是“ jpg”和“ jpeg”文件。
我的代码如下:
from deepface import DeepFace
import os
import os.path
import numpy as np
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
imgs = []
path = os.path.join(BASE_DIR,'images')
valid_images = [".jpg",".gif",".png",".tga",".jpeg"]
# image = Image.open(os.path.join(path,file))
for file in os.listdir(path):
print(file)
ext = os.path.splitext(file)[1]
if ext.lower() not in valid_images:
continue
print(ext)
image_face = DeepFace.detectFace(file)
print(image_face)
然后出现以下错误:
2020-08-17 22:33:34.148103: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-08-17 22:33:34.148135: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
/home/user/.local/share/virtualenvs/image_cleaning-iUI7F59N/lib/python3.7/site-packages/pandas/compat/__init__.py:120: UserWarning: Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.
warnings.warn(msg)
150_save_2020-08-17-21:44:28_9245.png
.png
Traceback (most recent call last):
File "face_detection.py",line 18,in <module>
image_face = DeepFace.detectFace(file)
File "/home/user/.local/share/virtualenvs/image_cleaning-iUI7F59N/lib/python3.7/site-packages/deepface/DeepFace.py",line 513,in detectFace
img = functions.detectFace(img_path)[0] #detectFace returns (1,224,3)
File "/home/user/.local/share/virtualenvs/image_cleaning-iUI7F59N/lib/python3.7/site-packages/deepface/commons/functions.py",line 200,in detectFace
raise ValueError("Confirm that ",img," exists")
ValueError: ('Confirm that ','150_save_2020-08-17-21:44:28_9245.png',' exists')
解决方法
您要输入文件名。您应该提供图像数组。
$ awk '{sub("AAAAAA","x"(++x)); y=0; while(sub("BBBBBB","y"(++y)));}1' file
x1 this is some content.
This is x2 some more content y1. y2 y3
This is yet x3 some more y1 y2 y3 content.
输出:
,将确切的图像路径传递给detectFace函数效果很好,而不是通过opencv读取它。
#!pip install deepface
from deepface import DeepFace
img = DeepFace.detectFace("img1.jpg")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。