Error at the begining of Training Stage 1

asked 2017-05-28 07:36:37 -0600

sebastienTurr gravatar image

Hi guys, i am totally new in our OpenCv community, i am from France so excuse my english if its start to turn crazy ahaha.

I started this week end to build a Haar cascade, i work on a window 10, my serv is a Debian machine (4G Ram, slow machine). i downloaded 1920 images in my neg file, i did the bg.txt (here "bgdef.txt") i created samples with my Pos image (1920 too) (only one pos image that i copied into Neg images with :

opencv_createsamples -img voiture5050.jpg -bg bgdef.txt -info info/info.lst -pngoutput info -maxxangle 0.5 -maxyangle -0.5 -maxzangle 0.5 -num 1920

also my positives.vec with :

opencv_createsamples -info info/info.lst -num 1920 -w 20 -h 20 -vec positives.vec

opencv_traincascade -data data -vec positives.vec -bg bgdef.txt -numPos 1920 -numNeg 1900 -numStages 10 -w 20 -h 20

when i start my training with : opencv_traincascade -data data -vec positives.vec -bg bgdef.txt -numPos 1920 -numNeg 1900 -numStages 10 -w 20 -h 20 then its start training... Stage 0 complete in 37 min... then Bam Stage 1 it's stop with the message :

===== TRAINING 1-stage ===== BEGIN POS current samplOpenCV Error: Bad argument (Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file. ) in get, file /build/opencv-FWWjHr/opencv-2.4.9.1+dfsg/apps/traincascade/imagestorage.cpp, line 162 terminate called after throwing an instance of 'cv::Exception' what(): /build/opencv-FWWjHr/opencv-2.4.9.1+dfsg/apps/traincascade/imagestorage.cpp:162: error: (-5) Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file. in function get

Abandonrent samples: 1911

i did the same thing as Sentex on Youtube : https://www.youtube.com/watch?v=eay7C...

i am here to learn so tell me what's wrong, i already love that kind of work :) And a serious BRAVO to OpenCv

sebastien

edit retag flag offensive close merge delete

Comments

See here (about traincascade paremeters, samples, and other...) and here for your issue.

Basically, if you have 1920 positive samples, you have to put 1920 * 0.8 (less positive samples).

Also, training a cascade of classifier using only one positive image (then artificially warped and combined with background image with opencv_createsamples) is generally not advised. It is better to use as many as possible of real positive images in different conditions with the same aspect ratio.

Eduardo gravatar imageEduardo ( 2017-05-28 15:56:19 -0600 )edit

What is your advice for the multiple positive images ? i have to crop a maximum and keep the square ratio ? the same size ? time is not a problem for me, i can run training for days:) so what is your advice for the size of neg and positive images ?

sebastienTurr gravatar imagesebastienTurr ( 2017-05-28 16:36:54 -0600 )edit

Size of the negatives do not matter, just take large negative images. For positive images, you will have to crop the object you want to detect and try to keep the same aspect ratio (you can take a bounding box slightly larger than the object to keep the same aspect ratio). Later, with opencv_createsamples, you can resize all your positive images to the same size (20x20 or 24x24 should be fine I guess).

You should first train with LBP features as it is quicker compared to HAAR features. Cascade of classifiers training is often a long try and retry process to have good results.

Eduardo gravatar imageEduardo ( 2017-05-29 12:02:15 -0600 )edit

wow 20x20 or 24x24 its a very small size for an image !!! ;) i used 50x50 on my first fail test ! ahah Do i have to create new samples with small positives images to put on large negatives? or the opencv training need to train neg against only small positives with the objet i want to use as "positive object" in ? Are you an expert of that ? I am going to crop all my images but i need to know if there is clues or advices before starting this looooong process !

sebastienTurr gravatar imagesebastienTurr ( 2017-05-29 15:29:01 -0600 )edit

ow god ... 1 images transformed to 1900 samples? Do you actually want your model to do something useful? Then skip this approach immediatly :D

StevenPuttemans gravatar imageStevenPuttemans ( 2017-05-31 04:43:30 -0600 )edit
1

yeah cause i wanted to try training very fast but i am here to learn my friend ;) have you got advices for me ? like i have to crop every positives images ? is there a minimum number ? just to try the training on my debian serv.

sebastienTurr gravatar imagesebastienTurr ( 2017-05-31 12:34:59 -0600 )edit

Advices, read OpenCV 3 Blueprints, Chapter 5. it contains all my experiences on the interface collected in the last 4 years. Yes you have to manually annotate each positive image. Number of samples depends on your case, but I have been succesful with around 100 positives and 100 negatives with an easy to separate task.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-06-01 02:40:11 -0600 )edit

You liked this book ? i am starting it

sebastienTurr gravatar imagesebastienTurr ( 2017-06-06 14:33:48 -0600 )edit

I wrote it :D So yes I liked it.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-06-07 04:18:21 -0600 )edit

ahahah ! nice job bro !!! Do you accept to receive my questions in the futur if i am lost in training process ?

sebastienTurr gravatar imagesebastienTurr ( 2017-06-07 14:51:22 -0600 )edit