AttributeError: module 'dlib' has no attribute 'face_recognition'
时间: 2023-12-13 07:34:34 浏览: 49
这个错误通常是由于dlib库版本不兼容导致的。您可以尝试更新dlib库或降低face_recognition库的版本以解决此问题。具体来说,您可以按照以下步骤解决此问题:
1.卸载dlib和face_recognition库:
```shell
pip uninstall dlib
pip uninstall face_recognition
```
2.安装dlib的旧版本:
```shell
pip install dlib==19.18.0
```
3.安装face_recognition的旧版本:
```shell
pip install face_recognition==1.2.3
```
如果您仍然遇到问题,您可以尝试使用conda环境或虚拟环境来安装这些库,以避免版本冲突。
相关问题
上述代码运行报错AttributeError: module 'dlib' has no attribute 'face_distance'
非常抱歉,我之前给出的代码有误。dlib库中确实没有`face_distance`函数。实际上,我们可以通过计算两个人脸特征向量之间的欧氏距离来衡量相似度。下面是修正后的代码:
```python
import dlib
import cv2
import numpy as np
def get_face_landmarks(img):
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector(gray)
for face in faces:
landmarks = predictor(gray, face)
return landmarks
def get_face_descriptor(img):
face_landmarks = get_face_landmarks(img)
face_rec_model = dlib.face_recognition_model_v1("dlib_face_recognition_resnet_model_v1.dat")
face_descriptor = face_rec_model.compute_face_descriptor(img, face_landmarks)
return face_descriptor
def compare_faces(img1, img2):
face_descriptor1 = get_face_descriptor(img1)
face_descriptor2 = get_face_descriptor(img2)
# 计算欧氏距离
euclidean_distance = np.linalg.norm(face_descriptor1 - face_descriptor2)
# 归一化处理,范围在0-1之间,相似度越高越接近0
similarity = 1 / (1 + euclidean_distance)
return similarity
# 读取两张人脸图片
img1 = cv2.imread("image1.jpg")
img2 = cv2.imread("image2.jpg")
# 比对两张图片的相似度
similarity = compare_faces(img1, img2)
print("相似度:", similarity)
```
请确保已经下载了dlib的模型文件(`shape_predictor_68_face_landmarks.dat` 和 `dlib_face_recognition_resnet_model_v1.dat`)。这段代码将比较两张人脸图片的相似度,并输出结果。相似度值越接近0表示两张图片的人脸越相似。
AttributeError: module pynvml has no attribute _nvmlGetFunctionPointer
引用\[1\]:在编写Python脚本过程中,你遇到了一个报错:AttributeError: 'module' object has no attribute 'core'。这个错误通常是由于命名冲突或者版本不兼容引起的。引用\[2\]:参照通用解决方法并没有解决你的报错,最后你发现自己新建的Python文件名字和内置的函数名冲突,修改了Python文件的名字后问题得到解决。引用\[3\]:在训练YOLO模型时,你遇到了AttributeError: module pynvml has no attribute _nvmlGetFunctionPointer的报错。后来发现这是由于numpy版本问题引起的,因为在NumPy 1.20中已经弃用了numpy.int,在NumPy 1.24中已经删除了。你可以通过重新安装numpy或者修改代码来解决这个问题。
综上所述,你遇到的AttributeError: module pynvml has no attribute _nvmlGetFunctionPointer的报错可能是由于numpy版本不兼容引起的。你可以尝试重新安装numpy或者修改代码来解决这个问题。
#### 引用[.reference_title]
- *1* *2* [【Python 脚本报错】AttributeError:‘module‘ has no attribute ‘xxx‘的解决方法](https://blog.csdn.net/qq_35091353/article/details/115609471)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [AttributeError: module numpy has no attribute int .报错解决方案](https://blog.csdn.net/weixin_46669612/article/details/129624331)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)