使用 MTCNN 进行人脸识别

时间:2021-05-05 06:39:34

标签: python python-3.x attributeerror face-recognition face-detection

我在尝试运行的代码中遇到以下错误。 AttributeError: 模块“facedetector_m”没有属性 FaceDetectorClass

from facenet_pytorch import MTCNN
import facedetector_m
import os
import torch
from torchvision import models
import torch.nn as nn
import argparse
import sys

sys.argv=['']
ap = argparse.ArgumentParser()
ap.add_argument("-b", "--blur", type=bool, default=True, choices=[True,False])
args = vars(ap.parse_args())
del sys

model = models.resnet18(pretrained=True)
num_ftrs = model.fc.in_features
model.fc = nn.Sequential(nn.Linear(num_ftrs, 2), torch.nn.Sigmoid())

model.load_state_dict(torch.load('C:/Users/mayan/Downloads/Face_Detection_LiveStreaming/model-resnet18-2.pth'))
model.eval()

mtcnn = MTCNN()
fcd = facedetector_m.FaceDetectorClass(mtcnn, classifier=model)

if args["blur"] == True:
    fcd.run(blur_setting=True)
if args["blur"] == False:
    fcd.run(blur_setting=False)

1 个答案:

答案 0 :(得分:0)

你为什么不使用 deepface?它将 mtcnn 包装为面部检测器。

#!pip install deepface
from deepface import DeepFace
DeepFace.verify("img1.jpg", "img2.jpg", model_name = 'Facenet', detector_backend = 'mtcnn')