gpt4 book ai didi

python - dlib train_object_detector 大量使用 RAM

转载 作者:行者123 更新时间:2023-11-28 18:29:03 25 4
gpt4 key购买 nike

我正在使用 dlib 的 train_object_detector 进行人脸检测,我在一个文件夹中有大约 6000 张图像,我试图用这些图像来训练我的模型。

此外,我为此目的使用了 dlib 的示例 python 代码 (train_object_detector.py)。

但问题是,该程序的 RAM 使用率非常高。对于大约 300 张图像,它需要大约 15GB RAM,而现在我的 6k 图像,我被卡住了。

对于 6k 图像,在训练时,它需要超过 100GB 的 RAM,最终程序自行终止。

一直都是这样吗?还是我做错了什么?使用这么多 RAM 是否正常?

它几乎没有任何修改,与 dlib 中的示例代码几乎相同。

注意:图片的大小在 10-100 KB 之间。

这是我正在使用的代码(远程):http://pastebin.com/WipU8qgq这是代码:

import os
import sys
import glob
import dlib
from skimage import io


if len(sys.argv) != 4:
print(
"Give the path to the faces directory as the argument to this "
"program with training and test xml files in order. For example: \n"
" ./train_object_detector_modified.py ../faces ../faces/training.xml ../faces/testing.xml")
exit()
faces_folder = sys.argv[1]
training_xml_path = sys.argv[2]
testing_xml_path = sys.argv[3]

options = dlib.simple_object_detector_training_options()
options.add_left_right_image_flips = True
options.C = 5
options.num_threads = 8
options.be_verbose = True

dlib.train_simple_object_detector(training_xml_path, "detector.svm", options)
print 'training end'

print("") # Print blank line to create gap from previous output
print("Training accuracy: {}".format(
dlib.test_simple_object_detector(training_xml_path, "detector.svm")))

print("Testing accuracy: {}".format(
dlib.test_simple_object_detector(testing_xml_path, "detector.svm")))


'''
# Now let's use the detector as you would in a normal application. First we
# will load it from disk.
detector = dlib.simple_object_detector("detector.svm")

# We can look at the HOG filter we learned. It should look like a face. Neat!
win_det = dlib.image_window()
win_det.set_image(detector)

# Now let's run the detector over the images in the faces folder and display the
# results.
print("Showing detections on the images in the faces folder...")
win = dlib.image_window()
for f in glob.glob(os.path.join(faces_folder, "*.jpg")):
print("Processing file: {}".format(f))
img = io.imread(f)
dets = detector(img)
print("Number of faces detected: {}".format(len(dets)))
for k, d in enumerate(dets):
print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
k, d.left(), d.top(), d.right(), d.bottom()))

win.clear_overlay()
win.set_image(img)
win.add_overlay(dets)
dlib.hit_enter_to_continue()
'''

最佳答案

发生这种情况是因为您有大图像和/或小边界框的组合。默认情况下,dlib.train_simple_object_detector 使用大小为 6400 像素的检测窗口。如果图像包含比这小得多的目标框,那么这些图像将被上采样以使对象足够大。

所有这些设置都是选项对象中的字段。

关于python - dlib train_object_detector 大量使用 RAM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39015782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com