模块'dlib'没有属性'get_frontal_face_detector'错误

1 投票
6 回答
11340 浏览
提问于 2025-06-18 04:07

我正在尝试在Anaconda上使用Face_Recognition这个包,我已经安装了dlib和face_recognition这两个库。

但是当我在代码中导入face_recognition时,出现了这个错误信息。

import dlib
import face_recognition



---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-32-cc760b0b6613> in <module>()
      1 import dlib
----> 2 import face_recognition

~\Anaconda3\lib\site-packages\face_recognition\__init__.py in <module>()
      5 __version__ = '1.2.3'
      6 
----> 7 from .api import load_image_file, face_locations, batch_face_locations, face_landmarks, face_encodings, compare_faces, face_distance

~\Anaconda3\lib\site-packages\face_recognition\api.py in <module>()
     15 ImageFile.LOAD_TRUNCATED_IMAGES = True
     16 
---> 17 face_detector = dlib.get_frontal_face_detector()
     18 
     19 predictor_68_point_model = face_recognition_models.pose_predictor_model_location()

AttributeError: module 'dlib' has no attribute 'get_frontal_face_detector'

相关问题:

  • 暂无相关问题
暂无标签

6 个回答

0

打开 Anaconda 提示符

第一步:

conda update conda

第二步:

conda update anaconda

第三步:

conda install -c conda-forge dlib
0

一种可能性是,你的文件名或者函数名用了'dlib'这个词。

0

我跟着这个帖子做了,效果很好。点击 [这里] (https://stackoverflow.com/a/49538054/14945612)!我在2021年7月检查过。问题可能出在C++编译器(Visual Studio)和Cmake的安装上。确保在你想要安装dlib的虚拟环境的site_packages文件夹中打开命令提示符。安装完成后,试着输入

import dlib

dlib.version

如果这样能成功,那问题可能是你输入错了。你可以从 [这里] (http://dlib.net/python/index.html#dlib.get_frontal_face_detector) 确认一下你调用的函数是否存在!

0

试试以下解决办法:

  1. 重新安装 dlib 这个包(先用 pip3 uninstall dlib 卸载,然后用 pip3 install dlib 安装)
  2. 从源代码安装 dlib(这个方法对我有效。链接在这里: http://dlib.net/compile.html
0

可以看看这个教程:http://www.programmersought.com/article/7562877819/

当你运行代码时,如果出现错误:detector = dlib.get_frontal_face_detector(),提示说模块 'Dlib' 没有 'get_frontal_face_detector' 这个属性,或者无法打开 'get_frontal_face_detector',这通常是因为你没有下载人脸数据库 shape_predictor_68_face_landmarks。你需要下载这个文件,解压缩后,把它放到你代码所在的文件夹里。人脸库下载链接:http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2

撰写回答