我是深度学习的新手。 我正在尝试在我的本地机器中使用deepface库。我使用
pip install deepface
来安装库,尝试了python 3.7.13、3.8.13和3.9.13,它们都是使用conda虚拟环境创建的。
然而,当运行下面的代码片段时,我在本地机器上运行时遇到了同样的错误。我需要 GPU 来运行库吗?如果是,我该如何设置?因为从在线指南/文章中,都没有提到需要安装/设置GPU。
我的本地电脑上有一个 GeForce MX450。
代码
import cv2
from deepface import DeepFace
import numpy as np
def analyse_face():
imagepath = "happy_face_woman.png"
image = cv2.imread(imagepath)
face_analysis = DeepFace.analyze(image)
print(face_analysis)
print(analyse_face())
错误:
ResourceExhaustedError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_14196\3829791526.py in <module>
12 print(face_analysis)
13
---> 14 analyse_face()
~\AppData\Local\Temp\ipykernel_14196\3829791526.py in analyse_face()
9 imagepath = "happy_face_woman.png"
10 image = cv2.imread(imagepath)
---> 11 face_analysis = DeepFace.analyze(image)
12 print(face_analysis)
13
c:\Users\user_name\anaconda3\envs\deepFacepy37\lib\site-packages\deepface\DeepFace.py in analyze(img_path, actions, models, enforce_detection, detector_backend, prog_bar)
352
353 if 'age' in actions and 'age' not in built_models:
--> 354 models['age'] = build_model('Age')
355
356 if 'gender' in actions and 'gender' not in built_models:
c:\Users\user_name\anaconda3\envs\deepFacepy37\lib\site-packages\deepface\DeepFace.py in build_model(model_name)
61 model = models.get(model_name)
62 if model:
---> 63 model = model()
...
-> 1922 seed=self.make_legacy_seed())
1923
1924 def truncated_normal(self, shape, mean=0., stddev=1., dtype=None):
ResourceExhaustedError: failed to allocate memory [Op:AddV2]
不同的错误输出
ResourceExhaustedError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_14196\3829791526.py in <module>
12 print(face_analysis)
13
---> 14 analyse_face()
~\AppData\Local\Temp\ipykernel_14196\3829791526.py in analyse_face()
9 imagepath = "happy_face_woman.png"
10 image = cv2.imread(imagepath)
---> 11 face_analysis = DeepFace.analyze(image)
12 print(face_analysis)
13
c:\Users\user_name\anaconda3\envs\deepFacepy37\lib\site-packages\deepface\DeepFace.py in analyze(img_path, actions, models, enforce_detection, detector_backend, prog_bar)
352
353 if 'age' in actions and 'age' not in built_models:
--> 354 models['age'] = build_model('Age')
355
356 if 'gender' in actions and 'gender' not in built_models:
c:\Users\user_name\anaconda3\envs\deepFacepy37\lib\site-packages\deepface\DeepFace.py in build_model(model_name)
61 model = models.get(model_name)
62 if model:
---> 63 model = model()
...
-> 1922 seed=self.make_legacy_seed())
1923
1924 def truncated_normal(self, shape, mean=0., stddev=1., dtype=None):
ResourceExhaustedError: OOM when allocating tensor with shape[7,7,512,4096] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc [Op:RandomUniform]
附加信息 我已经运行了命令来检查我的 GPU 使用情况,详细信息如下:
!nvidia-smi
为什么不禁用 GPU?
import os
os.environ["CUDA_VISIBLE_DEVICES"]=""