简体   繁体   English

Dlib 的 simple_object_detector() 运行缓慢

[英]Dlib's simple_object_detector() is running slowly

I have trained a SVM model for simple_object_detector() .我已经为simple_object_detector()训练了一个SVM model 。 But while inference on a video it is becoming too slow.但是,在对视频进行推理时,它变得太慢了。

I went through a similar question: Why is dlib so slow finding an object?我遇到了一个类似的问题:为什么 dlib 找到 object 这么慢? where an answer is saying to use USE_AVX_INSTRUCTIONS flag enabled while dlib installation.答案是在安装dlib时使用启用的USE_AVX_INSTRUCTIONS标志。 But it is not the case for me.但对我来说并非如此。 As I found the flag is enabled by default.我发现默认情况下启用该标志。 I also have come through this FAQ: Why is dlib slow where the solution is to choose the Release mode in Visual Studio but I am not using Visual Studio and just running the code from terminal.我也通过了这个常见问题解答:为什么 dlib 很慢,解决方案是在Visual Studio中选择Release模式,但我没有使用Visual Studio ,只是从终端运行代码。

But interesting thing is that if I run the builtin face detector dlib.get_frontal_face_detector() it runs completely fine with no lag.但有趣的是,如果我运行内置的人脸检测器dlib.get_frontal_face_detector() ,它运行得非常好,没有延迟。 But the program only becomes slow while running simple_object_detector() trained on custom data.但是程序只会在运行基于自定义数据训练的simple_object_detector()时变慢。

Alright.好吧。 I got the solution.我得到了解决方案。 Actually I missed to provide a flag while running the detector.实际上,我在运行检测器时错过了提供标志。 Probably it is related to some optimization.可能它与一些优化有关。

First initialize the detector object:首先初始化检测器object:

detector = dlib.simple_object_detector("/path/to/your/trained/SVM/detector")

Now change the following line from this:现在更改以下行:

detections = detector(gray_image)

To this:对此:

detections = detector(gray_image, 0)

Reference: https://github.com/davisking/dlib/issues/557#issuecomment-297679025参考: https://github.com/davisking/dlib/issues/557#issuecomment-297679025

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM