Computer vision D-lib图像的训练

Computer vision D-lib图像的训练,computer-vision,dlib,dlib-python,Computer Vision,Dlib,Dlib Python,我正在使用D-lib库来使用视觉识别。因此,我计划使用文档中给出的选项来训练我自己的分类器。与C++相比,我使用Python作为语言平台。 因此,我使用imglab工具创建了两个.xml文件,用于培训和测试。我必须在imglab工具中标记所有主题名称吗? 我有近20000张图片。这不是很难吗? 我们有简单的方法吗? 请查找与所附场景匹配的代码 import os import sys import glob import dlib from skimage import io # In t

我正在使用D-lib库来使用视觉识别。因此,我计划使用文档中给出的选项来训练我自己的分类器。与C++相比,我使用Python作为语言平台。 因此,我使用imglab工具创建了两个.xml文件,用于培训和测试。我必须在imglab工具中标记所有主题名称吗? 我有近20000张图片。这不是很难吗? 我们有简单的方法吗? 请查找与所附场景匹配的代码

import os
import sys
import glob

import dlib
from skimage import io


# In this example we are going to train a face detector based on the small
# faces dataset in the examples/faces directory.  This means you need to supply
# the path to this faces folder as a command line argument so we will know
# where it is.

faces_folder = "/media/praveen/SSD/NIVL_Ocular/NIR_Ocular_Training"


# Now let's do the training.  The train_simple_object_detector() function has a
# bunch of options, all of which come with reasonable default values.  The next
# few lines goes over some of these options.
options = dlib.simple_object_detector_training_options()
# Since faces are left/right symmetric we can tell the trainer to train a
# symmetric detector.  This helps it get the most value out of the training
# data.
options.add_left_right_image_flips = False
# The trainer is a kind of support vector machine and therefore has the usual
# SVM C parameter.  In general, a bigger C encourages it to fit the training
# data better but might lead to overfitting.  You must find the best C value
# empirically by checking how well the trained detector works on a test set of
# images you haven't trained on.  Don't just leave the value set at 5.  Try a
# few different C values and see what works best for your data.
options.C = 5
# Tell the code how many CPU cores your computer has for the fastest training.
options.num_threads = 4
options.be_verbose = True


training_xml_path = os.path.join(faces_folder, "/media/praveen/SSD/NIVL_Ocular/praveen_ocular_dataset.xml")
testing_xml_path = os.path.join(faces_folder, "/media/praveen/SSD/NIVL_Ocular/praveen_ocular_test_dataset.xml")
# This function does the actual training.  It will save the final detector to
# detector.svm.  The input is an XML file that lists the images in the training
# dataset and also contains the positions of the face boxes.  To create your
# own XML files you can use the imglab tool which can be found in the
# tools/imglab folder.  It is a simple graphical tool for labeling objects in
# images with boxes.  To see how to use it read the tools/imglab/README.txt
# file.  But for this example, we just use the training.xml file included with
# dlib.
dlib.train_simple_object_detector(training_xml_path, "detector.svm", options)



# Now that we have a face detector we can test it.  The first statement tests
# it on the training data.  It will print(the precision, recall, and then)
# average precision.
print("")  # Print blank line to create gap from previous output
print("Training accuracy: {}".format(
    dlib.test_simple_object_detector(training_xml_path, "detector.svm")))
# However, to get an idea if it really worked without overfitting we need to
# run it on images it wasn't trained on.  The next line does this.  Happily, we
# see that the object detector works perfectly on the testing images.
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, "*.png")):
#     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()

简单地说,是的,因为您想要使用train dlib的对象检测器,它需要一个带标签的(最多一个边界框)数据集,或者您将使用一个可用的带标签的数据集

imglab的主要功能是创建边界框,它写在您的评论中:

要创建自己的XML文件,可以使用imglab工具,该工具可以 在tools/imglab文件夹中找到。这是一个简单的图形化工具 使用方框标记图像中的对象

有关原始文件,请参阅:


事实上,正如你所说,这真的很难。目标检测或识别的主要挑战之一是创建数据集。这就是为什么研究人员使用类似于机械土耳其人的网站来利用人群的力量

简单地说,是的,因为您想使用train dlib的对象检测器,它需要一个带标签(最多一个边界框)的数据集,或者您将使用一个可用的带标签的数据集

imglab的主要功能是创建边界框,它写在您的评论中:

要创建自己的XML文件,可以使用imglab工具,该工具可以 在tools/imglab文件夹中找到。这是一个简单的图形化工具 使用方框标记图像中的对象

有关原始文件,请参阅:


事实上,正如你所说,这真的很难。目标检测或识别的主要挑战之一是创建数据集。这就是为什么研究人员使用类似于机械土耳其人的网站来利用人群的力量

谢谢你的建议。您所说的带标签的数据集是什么意思?我拥有的数据集已经根据当前的主题标记了图像。我只裁剪了脸部的眼部区域,它们将成为图片中的边框。我想我弄错了。你是在试图区分每个人的视网膜吗?我的意思是你想让探测器显示“这是约翰的视网膜,这是布拉德的视网膜”,对吗?所以,这个函数不是你可以使用的方法。这个函数只能找到你想要的对象,不幸的是它是一个二进制分类器。所以,它可以说是或不是。我认为你应该使用scikit学习,我也看到你的代码中有略读,所以我想它应该很容易使用。查看他们的目录,选择一个多输出算法。谢谢你的评论。但是,D-lib有一个功能,可以在与图库比较后预测每个输入图像的分数,这就是我使用的,我不这么认为。我以前使用过它,它只能找到人脸,并给出一个信心分数,如图所示:“最后,如果你真的想,你可以让检测器告诉你每次检测的分数。如果检测更自信,分数会更高。”顺便说一句,请别误会,我只是想帮你:)谢谢你的建议。您所说的带标签的数据集是什么意思?我拥有的数据集已经根据当前的主题标记了图像。我只裁剪了脸部的眼部区域,它们将成为图片中的边框。我想我弄错了。你是在试图区分每个人的视网膜吗?我的意思是你想让探测器显示“这是约翰的视网膜,这是布拉德的视网膜”,对吗?所以,这个函数不是你可以使用的方法。这个函数只能找到你想要的对象,不幸的是它是一个二进制分类器。所以,它可以说是或不是。我认为你应该使用scikit学习,我也看到你的代码中有略读,所以我想它应该很容易使用。查看他们的目录,选择一个多输出算法。谢谢你的评论。但是,D-lib有一个功能,可以在与图库比较后预测每个输入图像的分数,这就是我使用的,我不这么认为。我以前做过,它只能找到人脸,并给出一个信心分数,如图所示:“最后,如果你真的想,你可以让探测器告诉你每次检测的分数。如果检测更自信,分数会更高。”顺便说一句,请不要误会我,我只是想帮你:)如果有帮助,请检查图像标签的版本。如果有帮助,请检查图像标签的版本。