dlib train_object_detector 大量 RAM 使用

dlib train_object_detector immense amounts of RAM usage

我正在使用 dlib 的 train_object_detector 进行人脸检测,我在尝试训练模型的文件夹中有大约 6k 张图像。

此外,我正在使用 dlib 的示例 python 代码 (train_object_detector.py) 来实现此目的。

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

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

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

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

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

这是我正在使用的代码(远程):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()
'''

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

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