所以我正在关注https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/上的教程在Pycharm环境中。当我运行编码面孔文件时,出现此错误。
Traceback (most recent call last):
File "Encoding_Faces.py", line 29, in <module>
boxes = face_recognition.face_locations(rgb, model=args["detection_method"])
File "C:\Users\my name\AppData\Local\Programs\Python\Python36-
32\Webcam_Face_Detect\lib\site-packages\face_recognition\api.py", line 116,
in face_locations
return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in
_raw_face_locations(img, number_of_times_to_upsample, "cnn")]
File "C:\Users\my name\AppData\Local\Programs\Python\Python36-
32\Webcam_Face_Detect\lib\site-packages\face_recognition\api.py", line 100,
in _raw_face_locations
return cnn_face_detector(img, number_of_times_to_upsample)
MemoryError: bad allocation
但是当我看到屏幕右下角的内存使用情况时,它大约是 4096M 的 200。我把内存从750M增加了但是没有效果。奇怪的是,错误发生在第一张照片本身。我的图像每张约为 200kb,1920 x 1080。总共 17 张图像。我的电脑没有 GPU,所以我不确定这是否是问题所在。
我也检查了任务管理器,程序崩溃时内存使用率约为 50%。
我的电脑是 Hp Spectre x360 i5 第 6 代 8GB 内存。 2 岁,如果这很重要的话。
最佳答案
刚刚意识到问题是我的代码配置为使用 GPU 运行。我的错...将默认检测方法从“cnn”更改为“hog”。
关于python - 内存错误: bad allocation when Pycharm shows barely any memory use,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54837311/