【问题标题】:OpenCV 2.3.1: how to tell if haartraining is stuck or still working (on TINY example)OpenCV 2.3.1:如何判断 haartraining 是否卡住或仍在工作(在 TINY 示例中)
【发布时间】:2012-01-31 14:44:31
【问题描述】:

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

我正在尝试训练一个非常快速的示例。我只使用了 23 个正例和 45 个负例。然而,opencv_haartraining 已经 100% 使用了我的 2010 Macbook Air 的一个内核至少 30 小时!

以下是相关文件:

vec文件是按照本教程http://note.sonots.com/SciSoftware/haartraining.html生成的,使用作者的程序mergeveccreatesamples单独生成的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 以便定期输出其状态吗?百万!

(相关问题,均无答案:

)

【问题讨论】:

  • 看起来它挂在我身上。我使用 opencv_haartraining 约 1000 正,约 1000 负,只需要大约一天。但是不要直接杀了它,我会在我的 Linux 机器上做一些测试,然后回复你。
  • 已经杀了它,对不起(我担心我的 Macbook 电池的温度也受到影响,并在风扇上磨损)。但我会在相同或相似的数据上重新运行它,以便我们可以附加一个流程。
  • 第二次跑步的运气更好吗?
  • 还没有时间进行第二次运行,但是当我这样做时,我将开始第二次赏金。
  • OpenCV 雅虎技术组也有类似的线程,其中提供了一些额外反馈以确定代码是否进入死循环:tech.groups.yahoo.com/group/OpenCV/message/45080

标签: opencv


【解决方案1】:

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 语句,看看为什么我的跑步会挂起。

最大

【讨论】:

  • 你在这方面有什么收获吗?我的跑步也挂了。
【解决方案2】:

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

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

即位数:115

注意:

npos != 正面图像的数量

npos = 所有正图像中的样本数

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

如果您在此处发布 positive.txt 并 createsamples.exe 输出将会很有帮助。

【讨论】:

    【解决方案3】:

    查看haartraining的描述,发现默认值

    -minpos <min_number_of_positive_samples_per_cluster = 500>
    

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

    haartraining <your params> -minpos 75
    

    只是我的想法,未经验证。请告诉我你的发现

    【讨论】:

      【解决方案4】:

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

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

      *** 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
      

      它可能会挂起

      它挂起的来源可能是您的正面图像不同,或者您的负面图像具有相似的特征,因此很难对其进行分类

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

      【讨论】:

        【解决方案5】:

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

        总结上面提到的线程,haartraining 可以在两个地方大放异彩。

        第一个很容易通过检查输出来捕捉 - 您需要提高 HR(命中率)和降低 FA(误报)。如果这没有发生,则训练进入无限循环。

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

        要引用雅虎群的回答,您需要通过以下方式修改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%, 0negatives of 972 需要,已测试 10000000 张图像”,您已进入无限循环。

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

        【讨论】:

          猜你喜欢
          • 2016-10-12
          • 2015-12-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多