OpenCV 2.3.1:如何判断haartraining是否卡住或仍在工作(在TINY示例中)

时间:2012-01-02 04:24:57

标签: opencv

我第一次使用opencv_haartraining,在Mac OS X Lion上使用OpenCV 2.3.1。

我正在努力训练一个非常快速的例子。我只使用了23个正面例子和45个负面例子。然而,opencv_haartraining已使用我的2010 Macbook Air的一个核心100%至少30小时!

以下是相关文件:

vec文件是按照本教程http://note.sonots.com/SciSoftware/haartraining.html生成的,使用该作者的程序mergevec来合并createsamples单独生成的vec文件。

opencv_haartraining的输出是:

Data dir name: /Users/jon/Tabletop/haartraining_test_1/results
Vec file name: /Users/jon/Tabletop/haartraining_test_1/vec_positive_samples/vec_positive_samples.vec
BG  file name: /var/folders/85/96xv8qxx5ssc7ndg50s5lp480000gn/T/tmpZ2bASi.txt, is a vecfile: no
Num pos: 115
Num neg: 45
Num stages: 20
Num splits: 2 (tree as weak classifier)
Mem: 200 MB
Symmetric: TRUE
Min hit rate: 0.995000
Max false alarm rate: 0.500000
Weight trimming: 0.950000
Equal weights: FALSE
Mode: BASIC
Width: 20
Height: 20
Applied boosting algorithm: GAB
Error (valid only for Discrete and Real AdaBoost): misclass
Max number of splits in tree cascade: 0
Min number of positive samples per cluster: 500
Required leaf false alarm rate: 9.53674e-07

Tree Classifier
Stage
+---+
|  0|
+---+


Number of features used : 41910

Parent node: NULL

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 1
BACKGROUND PROCESSING TIME: 0.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-| 0.910420| 1.000000| 0.044444| 0.012500|
+----+----+-+---------+---------+---------+---------+
Stage training time: 2.00
Number of used features: 2

Parent node: NULL
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+
|  0|
+---+

   0


Parent node: 0

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 0.283019
BACKGROUND PROCESSING TIME: 0.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-|-0.965048| 1.000000| 1.000000| 0.018750|
+----+----+-+---------+---------+---------+---------+
|   2|100%|+|-0.903213| 1.000000| 0.288889| 0.025000|
+----+----+-+---------+---------+---------+---------+
Stage training time: 3.00
Number of used features: 4

Parent node: 0
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+---+
|  0|  1|
+---+---+

   0---1


Parent node: 1

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 0.338346
BACKGROUND PROCESSING TIME: 0.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-|-0.961620| 1.000000| 1.000000| 0.043750|
+----+----+-+---------+---------+---------+---------+
|   2|100%|+|-0.660077| 1.000000| 0.622222| 0.043750|
+----+----+-+---------+---------+---------+---------+
|   3| 88%|-| 0.142538| 1.000000| 0.044444| 0.012500|
+----+----+-+---------+---------+---------+---------+
Stage training time: 4.00
Number of used features: 6

Parent node: 1
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+---+---+
|  0|  1|  2|
+---+---+---+

   0---1---2


Parent node: 2

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 0.145631
BACKGROUND PROCESSING TIME: 0.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-|-0.975839| 1.000000| 0.777778| 0.025000|
+----+----+-+---------+---------+---------+---------+
|   2|100%|+|-0.904803| 1.000000| 0.244444| 0.037500|
+----+----+-+---------+---------+---------+---------+
Stage training time: 3.00
Number of used features: 4

Parent node: 2
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+---+---+---+
|  0|  1|  2|  3|
+---+---+---+---+

   0---1---2---3


Parent node: 3

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 0.0293926
BACKGROUND PROCESSING TIME: 0.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-|-0.981092| 1.000000| 1.000000| 0.031250|
+----+----+-+---------+---------+---------+---------+
|   2| 91%|+|-0.820519| 1.000000| 0.333333| 0.031250|
+----+----+-+---------+---------+---------+---------+
Stage training time: 3.00
Number of used features: 4

Parent node: 3
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+---+---+---+---+
|  0|  1|  2|  3|  4|
+---+---+---+---+---+

   0---1---2---3---4


Parent node: 4

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 0.0244965
BACKGROUND PROCESSING TIME: 0.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-|-0.964250| 1.000000| 1.000000| 0.025000|
+----+----+-+---------+---------+---------+---------+
|   2|100%|+|-1.801320| 1.000000| 1.000000| 0.025000|
+----+----+-+---------+---------+---------+---------+
|   3| 88%|-|-0.938272| 1.000000| 0.177778| 0.006250|
+----+----+-+---------+---------+---------+---------+
Stage training time: 4.00
Number of used features: 6

Parent node: 4
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+---+---+---+---+---+
|  0|  1|  2|  3|  4|  5|
+---+---+---+---+---+---+

   0---1---2---3---4---5


Parent node: 5

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 0.0100245
BACKGROUND PROCESSING TIME: 0.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-|-0.975839| 1.000000| 1.000000| 0.037500|
+----+----+-+---------+---------+---------+---------+
|   2|100%|+|-0.109149| 1.000000| 0.133333| 0.037500|
+----+----+-+---------+---------+---------+---------+
Stage training time: 3.00
Number of used features: 4

Parent node: 5
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+---+---+---+---+---+---+
|  0|  1|  2|  3|  4|  5|  6|
+---+---+---+---+---+---+---+

   0---1---2---3---4---5---6


Parent node: 6

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 0.00587774
BACKGROUND PROCESSING TIME: 0.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-|-0.870814| 1.000000| 0.800000| 0.050000|
+----+----+-+---------+---------+---------+---------+
|   2|100%|+|-0.437010| 1.000000| 0.200000| 0.050000|
+----+----+-+---------+---------+---------+---------+
Stage training time: 3.00
Number of used features: 4

Parent node: 6
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+---+---+---+---+---+---+---+
|  0|  1|  2|  3|  4|  5|  6|  7|
+---+---+---+---+---+---+---+---+

   0---1---2---3---4---5---6---7


Parent node: 7

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 0.00269655
BACKGROUND PROCESSING TIME: 0.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-|-0.825750| 1.000000| 1.000000| 0.087500|
+----+----+-+---------+---------+---------+---------+
|   2| 89%|+|-1.098274| 1.000000| 0.911111| 0.093750|
+----+----+-+---------+---------+---------+---------+
|   3| 99%|-|-0.387003| 1.000000| 0.222222| 0.050000|
+----+----+-+---------+---------+---------+---------+
Stage training time: 5.00
Number of used features: 6

Parent node: 7
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+---+---+---+---+---+---+---+---+
|  0|  1|  2|  3|  4|  5|  6|  7|  8|
+---+---+---+---+---+---+---+---+---+

   0---1---2---3---4---5---6---7---8


Parent node: 8

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 0.000656714
BACKGROUND PROCESSING TIME: 0.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-|-0.780975| 1.000000| 1.000000| 0.125000|
+----+----+-+---------+---------+---------+---------+
|   2|100%|+|-1.143491| 1.000000| 0.866667| 0.125000|
+----+----+-+---------+---------+---------+---------+
|   3|100%|-|-1.267461| 1.000000| 0.355556| 0.037500|
+----+----+-+---------+---------+---------+---------+
Stage training time: 5.00
Number of used features: 6

Parent node: 8
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+---+---+---+---+---+---+---+---+---+
|  0|  1|  2|  3|  4|  5|  6|  7|  8|  9|
+---+---+---+---+---+---+---+---+---+---+

   0---1---2---3---4---5---6---7---8---9


Parent node: 9

*** 1 cluster ***
POS: 115 115 1.000000
NEG: 45 0.000245695
BACKGROUND PROCESSING TIME: 1.00
Precalculation time: 0.00
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
|   1|100%|-|-0.982759| 1.000000| 1.000000| 0.006250|
+----+----+-+---------+---------+---------+---------+
|   2|100%|+| 0.017238| 1.000000| 0.000000| 0.000000|
+----+----+-+---------+---------+---------+---------+
Stage training time: 2.00
Number of used features: 4

Parent node: 9
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+---+---+---+---+---+---+---+---+---+---+---+
|  0|  1|  2|  3|  4|  5|  6|  7|  8|  9| 10|
+---+---+---+---+---+---+---+---+---+---+---+

   0---1---2---3---4---5---6---7---8---9--10


Parent node: 10

*** 1 cluster ***
POS: 115 115 1.000000

所有这些输出都是在运行的前5分钟产生的。产生这个输出之后,它继续以100%的一个核心运行30个小时(到目前为止),没有进一步的输出。

我的问题是:如何判断haartraining是否在此特定情况下崩溃,更一般地说,是否有人知道如何修改cvhaartraining.cpp以便定期输出其状态?万分感谢!

(相关问题,两者都没有答案:

5 个答案:

答案 0 :(得分:4)

通过查看haartraining/cvhaartraining.cpp,您在取消之前看起来就是您的流程:

negcount = icvGetHaarTrainingDataFromBG( training_data, poscount, nneg,
    (CvIntHaarClassifier*) tcc, &false_alarm, bg_vecfile ? bgfilename : NULL );

您可以深入查看icvGetHaarTrainingDataFromBG调用的函数,添加printf语句,然后重新编译。我一直在训练我的训练(我正在使用opencv_traincascade),并希望看到事情陷入困境。我可以尝试将printf语句添加到traincascade/traincascade.cpp中,看看为什么我的话会挂起。

最高

答案 1 :(得分:4)

在OpenCV Yahoo技术小组上也有类似的线程,其中包含michael_p_horton的代码,用于提供一些额外的反馈,以确定代码是否进入无限循环:tech.groups.yahoo.com/group/OpenCV/message/45080

总结上面提到的话题,有两个地方可以讨论haartraining。

第一个很容易通过检查输出来捕获 - 你需要HR(命中率)增加而FA(虚警)减少。如果没有发生这种情况,训练就会进入无限循环。

然而,根据maxenglander的回答,您遇到的问题是icvGetHaarTrainingDataFromBG中的无限循环。要检查这一点,您需要深入研究cvhaartraining.cpp代码并添加一些调试输出。

要引用Yahoo组的答案,您需要以下列方式修改icvGetHaarTrainingDataFromBG实现(查找cascade-eval()行,然后添加CV_VERBOSE代码):

icvGetAuxImages( &img, &sum, &tilted, &sqsum, normfactor );
if( cascade->eval( cascade, sumdata, tilteddata, *normfactor ) != 0.0F )
    break;

/* Display progress on negative image selection */
#ifdef CV_VERBOSE
if( thread_consumed_count % 1000 == 0 )
{
    fprintf( stderr, "%3d%%, %d negatives of %d required, %d images
    tested\r", (int) ( 100.0 * (i - first) / count ), (i-first), count,
    thread_consumed_count );
    fflush( stderr );
}
#endif /* CV_VERBOSE */
  

如果这开始显示“0%,0负972”等消息   所需的10000000张图片“你已经进入了无限循环。

最后一点 - 使用OpenCV 2.4,相关代码位于icvGetHaarTrainingData函数中。

答案 2 :(得分:2)

查看haartraining的描述,您会找到

的默认值
-minpos <min_number_of_positive_samples_per_cluster = 500>

由于您只有115个正样本,这可能是您的问题......也许您没有指定此参数,这导致培训永远不会结束。尝试将其设置为75

haartraining <your params> -minpos 75

只是我的想法,没有经过验证。请让我知道你的发现

答案 3 :(得分:1)

问题在于你的positive.txt和positive.vec文件。(不是否定的)

确保positive.txt / positive.dat文件包含115个正样本

即。 Num pos:115

注意:

npos!=正面图片数量

npos =所有正片中的样本数

如果单个图像中有多个对象,则其positive.txt描述文件必须包含多个条目。

如果你在这里发布positive.txt和createsamples.exe输出会很有帮助。

答案 4 :(得分:1)

根据我的经验,我得出结论:

如果它在表头或像这样的表中冻结

*** 1 cluster ***
POS: 11342 11342 1.000000
NEG: 1102 1
BACKGROUND PROCESSING TIME: 0.03
Precalculation time: 1.92
+----+----+-+---------+---------+---------+---------+
|  N |%SMP|F|  ST.THR |    HR   |    FA   | EXP. ERR|
+----+----+-+---------+---------+---------+---------+
它还在运行 但如果它冻结在像这样的“集群”文本中

*** 1 cluster ***
POS: 11342 11342 1.000000

它可能会挂起

它挂起的来源可能是你的正面图像是不同的或你的负面图像有类似的功能所以很难对它们进行分类

在训练前预先处理您的正面图像