我使用dlib的train_object_detector进行面部检测,我在一个文件夹中有大约6k张图像,我正试图用它来训练我的模型。在
另外,我使用dlib的示例python代码(train_对象_探测器.py)为此目的。在
但问题是,程序的内存使用是疯狂的。对于大约300个图像,它需要大约15GB的内存,而现在我的6k图像,我被卡住了。在
对于6k图像,在训练过程中,它需要100GB以上的RAM,最终程序会自行死亡。在
一直都是这样吗?还是我做错了什么?有这么多的内存使用是正常的吗?在
它几乎完全没有修改,与dlib中的示例代码基本相同。在
注意:图像大小在10-100 KB之间。在
以下是我使用的代码(remote):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_检测器使用6400像素大小的检测窗口。如果图像包含比这个小得多的目标框,那么这些图像将被上采样以使对象足够大。在
所有这些设置都是选项对象中的字段。在
相关问题 更多 >
编程相关推荐