【问题标题】:Python: how do I resolve AttributeError: 'module' object has no attribute 'face_recognition_model_v1'Python:如何解决 AttributeError:'module' 对象没有属性 'face_recognition_model_v1'
【发布时间】:2017-11-08 09:34:16
【问题描述】:

我已下载该文件并将其放置在与我运行代码的目录相同的目录中。但在这里facerec = dlib.face_recognition_model_v1(face_rec_model_path) 我仍然收到此属性错误。我已将其全部显示在哪里,但仍然有错误。
这是我的代码,我无法确定问题出在哪里?

import sys
import os
import dlib
import glob
from skimage import io

predictor_path = '/home/irum/Desktop/DLIB-recognition/shape_predictor_68_face_landmarks.dat'
face_rec_model_path = '/home/irum/Desktop/DLIB-recognition/dlib_face_recognition_resnet_model_v1.dat'
faces_folder_path = '/home/irum/Desktop/DLIB-recognition/att_faces/ERSHIAN'

# Load all the models we need: a detector to find the faces, a shape predictor
# to find face landmarks so we can precisely localize the face, and finally the

# face recognition model.
detector = dlib.get_frontal_face_detector()
sp = dlib.shape_predictor(predictor_path)
facerec = dlib.face_recognition_model_v1(face_rec_model_path)

win = dlib.image_window()

# Now process all the images
for f in glob.glob(os.path.join(faces_folder_path, "*.png")):
    print("Processing file: {}".format(f))
    img = io.imread(f)

    win.clear_overlay()
    win.set_image(img)

    # Ask the detector to find the bounding boxes of each face. The 1 in the
    # second argument indicates that we should upsample the image 1 time. This
    # will make everything bigger and allow us to detect more faces.
    dets = detector(img, 1)
    print("Number of faces detected: {}".format(len(dets)))

    # Now process each face we found.
    for k, d in enumerate(dets):
        print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
            k, d.left(), d.top(), d.right(), d.bottom()))
        # Get the landmarks/parts for the face in box d.
        shape = sp(img, d)
        # Draw the face landmarks on the screen so we can see what face is currently being processed.
        win.clear_overlay()
        win.add_overlay(d)
        win.add_overlay(shape)


        face_descriptor = facerec.compute_face_descriptor(img, shape)
        print(face_descriptor)

        dlib.hit_enter_to_continue()

【问题讨论】:

  • 错误消息告诉您dlib 没有名为face_recognition_model_v1 的属性。我不知道 dlib 是什么,所以我不能告诉你更多,但你可以检查你下载的 dlib.py 文件并在那里检查。

标签: python face-detection face-recognition dlib


【解决方案1】:

您需要安装 dlib。 跑步 pip install dlib

【讨论】:

  • 要求已经满足:dlib 在 /usr/local/lib/python2.7/dist-packages/dlib-19.2.0-py2.7-linux-x86_64.egg
  • 你试过最新的dlib吗?运行 pip install dlib==19.4.0.
【解决方案2】:

更新 dlib。运行这个命令:pip install dlib==19.4.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-19
    • 2021-01-15
    • 2015-05-16
    • 1970-01-01
    • 2022-12-20
    • 2014-04-03
    • 2016-01-18
    • 1970-01-01
    相关资源
    最近更新 更多