python - 如何训练或合并多个 .svm 并使用 dlib 检测多个类

标签 python c++ image-processing deep-learning dlib

我想做一个非常简单的例子:使用 dlib 训练来检测“猫”和“狗”(两个类)并提供框坐标。

到目前为止,我发现的示例是只训练一个类并生成一个 .svm 文件:http://dlib.net/train_object_detector.cpp.html

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

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. 我需要生成一个 .dat 文件,例如此处的人脸标志检测 http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 .那么,如何立即训练和序列化或之后合并 .svm 文件?

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

谢谢。

最佳答案

我可以告诉您如何在 C++ 中执行此操作。我希望您应该能够弄清楚如何在 Python 中完成它。

您无需拥有单个 .dat 文件即可执行此操作。您可以单独训练检测器并保存到单独的文件中。这允许您添加新检测器、替换现有检测器等而无需重新训练。 在您需要创建检测器 vector 之后。即:

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);

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

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

在我的例子中,一次运行所有检测器 (5) 的执行速度比顺序运行它们快 2.5-3 倍。但这将取决于每个检测器的检测窗口的相似程度。

关于python - 如何训练或合并多个 .svm 并使用 dlib 检测多个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44465354/

相关文章:

Python 多处理,ValueError : I/O operation on closed file

python - 在 macOS 上将 TLS 1.0 升级到 TLS 1.2

python - 对各个像素的 RGB 值迭代函数

python - MATLAB 的 'improfile' 函数是否有等效的 Python 函数?

python - 使用 pdfminer 通过 Python 通过 URL 解析 PDF

python - 循环访问 Unicode 数据字典

c++ - 尝试使用文本文件初始化多个结构变量

image - 仅保留图像的红/绿/蓝部分

C++继承和模板不编译

c# - 从哪里开始使用 C# 或任何语言中的神经网络进行手写文本识别