简体   繁体   English

过度拟合时,OpenCV haar训练无限循环的解决方案是什么?

[英]What is the solution for OpenCV haar training infinite loop when overfitting?

I run Haar training in openCV 2.4.3. 我在openCV 2.4.3中运行Haar培训。

  1. I have 10 negative images and about 30 positive (I know that it is small amount). 我有10个负面图像和大约30个正面(我知道它是少量的)。
  2. positive samples are organized in 'vec' file and negative (background ) images are described by text file which stores the path's of the images. 正样本在'vec'文件中组织,负(背景)图像由文本文件描述,该文件存储图像的路径。
  3. With such a small amount of images a perfect solution exists (all of the background images classified as false and the real samples as true). 如此少量的图像存在完美的解决方案(所有背景图像分类为假,真实样本为真)。

When this perfect solution found, openCV enters an infinite loop inside icvGetHaarTrainingData() function. 当找到这个完美的解决方案时,openCV在icvGetHaarTrainingData()函数内进入无限循环。

It wants to find background images on which the cascade fails but there are no more such images so this function is stuck in for(;;) loop forever. 它想要找到级联失败的背景图像,但是没有更多这样的图像,所以这个函数永远停留在for(;;)循环中。

icvGetBackgroundImage() function, called in this loop, just keeps loading the same images from hard-disk which are rejected by the cascade. icvGetBackgroundImage()函数,在此循环中调用,只是从硬盘加载相同的图像,这些图像被级联拒绝。

Does someone know of a patch, or a bug fix I can apply to solve this problem? 有人知道补丁,或者我可以应用错误修复来解决这个问题吗?

One possible fix, I came up with, is to let icvGetBackgroundImage() load each file only once since if it was rejected by the cascade once it would be rejected always. 我想出的一个可能的解决方法是让icvGetBackgroundImage()只加载一次文件,因为一旦它被拒绝,它会被级联拒绝。 But this is a wrong tweak since this same function is used for generating 'vec' files in cvCreateSamples() and in this scenario we do want it to load the same file few times. 但这是一个错误的调整,因为这个相同的函数用于在cvCreateSamples()生成'vec'文件,在这种情况下,我们希望它几次加载相同的文件。

Second possible fix - use negative examples in vec file (like positive examples) instead of info path format. 第二种可能的解决方法 - 在vec文件中使用负面示例(如正面示例)而不是信息路径格式。 This is a way to overcome infinite loop by not activating the problematic callback, but the result is an openCV error that causes a crash. 这是一种通过不激活有问题的回调来克服无限循环的方法,但结果是导致崩溃的openCV错误。 It happens when negative 'vec' file reaches EOF. 当负'vec'文件达到EOF时会发生这种情况。

Meanwhile I solved those 2 bugs (infinite loop and crash) by changing directly the source code of openCV and recompiling the binaries. 同时我通过直接更改openCV的源代码并重新编译二进制文件来解决这两个错误(无限循环和崩溃)。 I will submit my changes to openCV committee soon. 我很快就会向openCV委员会提交更改。 But I can't believe that I am the only one who bumped into such problem... 但我无法相信我是唯一一个遇到这种问题的人......

Posting here The fixed code. 在这里发布固定代码。 Please note that an original openCV license is applied to it as well. 请注意,原始的openCV许可证也适用于它。 https://github.com/DanielHsH/OpenCV-HaarTraining-BugFix https://github.com/DanielHsH/OpenCV-HaarTraining-BugFix

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

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