traincascade 2.4.9 produces unreadable format, haartraining 2.4.9 hangs, traincascade git crashes

asked 2014-05-11 08:38:02 -0600

MSoegtrop gravatar image

Dear OpenCV Developers,

I tried to train a haar cascade with traincascade 2.4.9. For my first test I had only 16 positive samples and 3000 negative samples. I compiled opencv 2.4.9 on Ubuntu 14.04 LTS and installed it to usr/local.

The following command

opencv_traincascade -data cascades -vec Positives/positives.vec -bg Negatives/negatives.dat -numStages 10 -w 16 -h 16 -numPos 16 -numNeg 3000

succeeds with a 3 stage filter. The problem is that the generated cascade.xml file is slightly different from all sample cascade files provided in the sample folder. The header of the generated file looks like this:

<?xml version="1.0"?>
<opencv_storage>
<cascade>
<stageType>BOOST</stageType>
<featureType>HAAR</featureType>
<height>16</height>
<width>16</width>
<stageParams>
<boostType>GAB</boostType>

I guess most of the filters provided with opencv 2.4.9 are still created with haartraining, not with traincascade, and have a quite different format. But the files in opencv-2.4.9/data/lbpcascades look similar:

<?xml version="1.0"?>
<!--
number of positive samples 3000
number of negative samples 1500
-->
<opencv_storage>
<cascade type_id="opencv-cascade-classifier">
<stageType>BOOST</stageType>
<featureType>LBP</featureType>
<height>24</height>
<width>24</width>
<stageParams>
<boostType>GAB</boostType>

Obviously the type_id in the cascade item is missing in the file generated by trainscascade 2.4.9. When I try to read this file e.g. with opencv_performance, I get the following error:

OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /data/download/OpenCV/opencv-2.4.9/modules/core/src/persistence.cpp, line 4991

I tried to fix the file and add the type_id manually, but the error is exactly the same.

Then I tried traincascade from GIT, but it crashes with the same data. Then I tried haartraining 2.4.9, but although traincascade finishes in a minute or so (on an i7-4770K), haartraining gets stuck at some point after an hour of computation.

Then I tried various filters from opencv-2.4.9/data. The haarcascade_eye_tree_eyeglasses.xml is loadable, but this is in an old format, probably created by haartraining. lbpcascade_frontalface.xml seems to be in the new format, but produces the same error when used e.g. with

opencv_performance -data XmlFormats/lbpcascade_frontalface_2.4.9.xml -w 24 -h 24 -info tests.dat -ni

I also found that the haarcascade_eye_tree_eyeglasses.xml from GIT has been created with traincascade (or at least it looks like this), but I cannot load it either with opencv_performance.

So something seems to be wrong with the training apps in opencv 2.4.9.

Does someone has a simple dummy sample for traincascade 2.4.9, which produces something which can be loaded into opencv_performance 2.4.9?

Thanks & best regards,

Michael

edit retag flag offensive close merge delete

Comments

1

opencv_performance only works with old (haar only)cascade files, produced by the (old) haar_training tool.

unfortunately, noone yet wrote a replacement tool for the newer format, which supports HOG and LBP cascades as well.

afaik, the traincascade tool only writes files in the new format (no matter what classifier used), so you can't use the output with opencv_performance

berak gravatar imageberak ( 2014-05-11 08:58:12 -0600 )edit
3

Dear Berak,

thanks, good to know. I look into enhancing the opencv_performance to work with both formats.

Best regards,

Michael

MSoegtrop gravatar imageMSoegtrop ( 2014-05-11 11:01:35 -0600 )edit

If you succeed in doing so, please make a pull request with the solution. This one has been on my todo list for ages :D

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-12 02:25:42 -0600 )edit
4

I renovated the performance app to use the C++ interface, and indeed it now loads the classifiers created by traincascade and does what I expected. I will clean it up a bit and then see if I can magae to get it into GIT. Best regards, Michael

MSoegtrop gravatar imageMSoegtrop ( 2014-05-12 13:01:11 -0600 )edit

That would be magnificent! If you don't succeed, don't hesitate to ask for help!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-13 01:38:08 -0600 )edit
1

Yes, that would be great. Yesterday I tried to evaluate my lbp cascade only to discover that the performance code was not working...and then I found this thread...awaiting your contribution...

Witek gravatar imageWitek ( 2014-05-13 03:45:24 -0600 )edit

Hi Steven,

one question: should I do the pull request on master or on 2.4.x?

The doc says no new features in 2.4, and somehow this is a new feature. On the other hand it wouldn't interfer with any other code and ha sno risk of introducing new bugs and in a way it is a bug that opencv_performance doesn't work.

Best regards,

Michael

MSoegtrop gravatar imageMSoegtrop ( 2014-05-19 14:16:10 -0600 )edit
1

I think this belongs in 2.4 because it is for current functionality testing!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-19 14:37:02 -0600 )edit

Have you guys managed to do the pull request? I would really like to give it a try. Where do I find it? Here: https://github.com/Itseez/opencv/tree/2.4 ?

Witek gravatar imageWitek ( 2014-05-27 18:19:28 -0600 )edit

@Witek, afaik it is still in the process of being evaluated. Probably The author will let you know once it is merged!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-28 02:52:31 -0600 )edit