如何使用dlib训练或合并多个.svm并检测多个类 [英] How to train or merge multiple .svm and detect multiple classes using dlib

查看:1699
本文介绍了如何使用dlib训练或合并多个.svm并检测多个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个非常简单的例子:使用dlib训练检测cat和dog(两个类)并提供盒子坐标。

I would like to do a very simple example: train using dlib to detect "cat" and "dog" (two classes) and provide box coordinate.

所以我发现的例子是只训练一个类并生成一个.svm文件: http:// dlib .net / train_object_detector.cpp.html

So far the example I found is to only train with one class and produce one .svm file: http://dlib.net/train_object_detector.cpp.html

我不擅长C ++(但我可以学习)而且我更喜欢用Python做事。经过几天的研究(我也是深度学习的新手),我想我必须更改这些行:

I am not good at C++ (but I can learn) and I prefer to do things in Python. After several days of research (I'm new in Deep Learning as well), I figured I have to change these lines:

object_detector<image_scanner_type> detector = trainer.train(images, object_locations, ignore);
serialize("object_detector.svm") << detector;

因此我应该在 http://dlib.net/dlib/image_processing/object_detector_abstract.h.html

explicit object_detector (
  const std::vector<object_detector>& detectors
);

问题:


  1. 我需要像这里的Face地标检测一样生成一个.dat文件 http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 。那么我如何一次训练和序列化或者将.svm文件组合起来呢?

  1. I need to produce a .dat file like the Face landmarks detection here http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2. So how do I train and serialize at once or combine .svm files afteward?

然后我需要运行检测以检测.dat中的所有.svm文件。我可以举个例子来说明如何用C ++或Python做这个吗?

Then I need to run a detection to detect all .svm inside the .dat file. Can I get an example how to do this with C++ or Python?

谢谢。

推荐答案

我可以告诉你如何在C ++中这样做。我希望你能够弄清楚如何用Python做到这一点。

I can tell you how to do so it in C++. Than I hope you should be able to figure out how to you can do it in Python.

你不需要单个.dat文件就可以了。您可以单独训练探测器并保存到单独的文件中。这允许您添加新的探测器,替换现有的等,而无需重新训练。
需要创建探测器矢量后。即:

You don't need to have single .dat file to do so. You can train detectors separately and save to separate files. This allows you add new detectors, replace existing etc. without retraining. After you need to create vector of detectors. i.e.:

std::vector<object_detector> detectors(3);
dlib::deserialize(detectors[0], "object_detector.svm");
dlib::deserialize(detectors[1], "object_detector_2.svm");
dlib::deserialize(detectors[2], "object_detector_3.svm");

然后你运行如下检测:

std::vector<dlib::rect_detection> detections;
dlib::evaluate_detectors(detectors, image, detections);

然后您可以访问检测到的对象:

Then you can access detected objects this:

for (auto& det : detections) {
    det.rect;          // found rectangle
    det.weight_index;  // detector index in vector (to indentify object class)
}

在我的情况下运行所有检测器(5)一次执行比顺序运行快2.5-3倍。但这取决于每个探测器的检测窗口的相似程度。

In my case running all detectors (5) at once executes about 2.5-3 times faster than running them sequentially. But it will depend on how similar detection windows are for each of detector.

这篇关于如何使用dlib训练或合并多个.svm并检测多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆