【问题标题】:How to solve problem running MTCNN in JupiterLab如何解决在 JupyterLab 中运行 MTCNN 的问题
【发布时间】:2021-04-17 21:49:39
【问题描述】:

JupiterLab 中的 detect_faces() 函数失败:

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

【问题讨论】:

  • 我遇到了同样的错误,你有解决办法吗?

标签: python-3.x tensorflow conda anaconda3


【解决方案1】:

用 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 中。用一张多张脸的图片进行了测试,效果很好

【讨论】:

  • 它给出了相同的输出:(
  • 你安装了tensorflow和mtcnn吗?
  • 查看修改后的答案。我测试了它,它工作正常。你必须安装 tensorflow 和 mtcnn
  • 我都安装了
  • 你运行它并检查打印输出了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-25
  • 2021-05-11
  • 2023-04-06
  • 1970-01-01
  • 2014-07-08
相关资源
最近更新 更多