我正在使用dlib的 train_object_detector 进行人脸检测,我在一个文件夹中有大约6k个图像,我正在尝试训练我的模型。
另外,我正在使用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()
'''
答案 0 :(得分:1)
这种情况正在发生,因为您有大图像和/或小边框的组合。默认情况下,dlib.train_simple_object_detector使用大小为6400像素的检测窗口。如果图像包含远小于此的目标框,则对这些图像进行上采样以使对象足够大。
所有这些设置都是选项对象中的字段。