如何解决如何解决在 JupiterLab 中运行 MTCNN 的问题
函数detect_faces() 在JupiterLab 中失败:
image = Image.open(filename)
imageRGB = image.convert('RGB')
pixels = asarray(imageRGB)
detector = MTCNN()
results = detector.detect_faces(pixels)
mtcnn 0.1.0 版
错误:
AbortedError:操作收到异常:状态:2,消息:
无法为 softmax 前向传播创建描述符
原始文件,在文件 tensorflow/core/kernels/mkl/mkl_softmax_op.cc:306
[[节点模型/softmax/Softmax(定义于
/home/rikkatti/anaconda3/envs/poi/lib/python3.9/site-packages/mtcnn/mtcnn.py:342)
]] [操作:__inference_predict_function_828]
函数调用栈:predict_function
解决方法
使用 cv2 以这种方式尝试
from mtcnn import MTCNN
import os
import cv2
detector = MTCNN()
dest_dir=r'C:\Temp\people\storage\cropped' # specify where to save the images
filename=r'C:\Temp\people\storage\34.png' # specify the file name full path
try:
img=cv2.imread(filename) # filename must be full path to the image
shape=img.shape # will cause an exception if image was not read properly
data=detector.detect_faces(img)
if data ==[]:
print ('no faces were detected for file ',filename)
else:
for i,faces in enumerate(data):
box= faces['box']
if box != []:
box[0]= 0 if box[0]<0 else box[0]
box[1]= 0 if box[1]<0 else box[1]
cropped_img=img[box[1]: box[1]+box[3],box[0]: box[0]+ box[2]]
fname=os.path.split(filename)[1]
index=fname.rfind('.')
fileid=fname[:index]
fext=fname[index:]
fname=fileid + '-' +str(i) + fext
save_path=os.path.join(dest_dir,fname )
cv2.imwrite(save_path,cropped_img)
except:
print(' an error occurred')
这将检测图像中的所有面部并将它们作为裁剪图像存储在 dest_dir 中。用多张脸的图像对其进行了测试,效果很好
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。