首页 > 解决方案 > MemoryError:当 Pycharm 几乎没有显示任何内存使用时分配错误

问题描述

所以我在 Pycharm 环境中关注https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/上的教程。当我运行编码面文件时,会出现此错误。

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岁,如果这很重要。

标签: pythonpickleface-recognitiondlibcv2

解决方案


刚刚意识到问题是我的代码配置为使用 gpu 运行。我的错...将默认检测方法从“cnn”更改为“hog”。


推荐阅读