Train Cascade parameters calculations issue

asked 2015-09-07 10:11:42 -0600

Steven_ocv gravatar image

updated 2015-09-07 10:42:11 -0600

I am training a cascade classifier using opencv. I have 56 positive and 120 negative samples. Their dimensions are 40 * 50 pixels.

The code that I used to make the samples was:

 E:\openCV\opencv\build\x64\vc12\bin\opencv_createsamples.exe -info pos.txt -vec SAMP.vec -num 56 -w 40 -h 50

and the traning code is :

E:\openCV\opencv\build\x64\vc12\bin\opencv_traincascade.exe -data classifier -vec SAMP.vec -bg neg.txt -featureType HAAR -numStages 12 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 40 -numNeg 120 -w 40 -h 50 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

The training is showing this message:

image description

===== TRAINING 4-stage =====

BEGIN

POS count : consumed 40 : 45


and no matter how long i wait, nothing happens.

1. Is there any problem in my code?

2. Does this equation has any thing to do in my code :

vec-file has to contain >= (numPose + (numStages-1) * (1 - minHitRate) * numPose) + S ??

I still cant figure out the S, what it really means? how to calculate the S?

edit retag flag offensive close merge delete

Comments

56 positives are not enough (try with>500), it ate up 40 of them (thinking, they were not useful at all), even before starting to train anything.

also, your negatives can be any size, the larger , the better (it will try to crop out several neg examples from that)

what kind of object are you trying to train on ? (maybe, the whole idea is not feasible at all)

then, @StevenPuttemans, namesake asking for your help, i guess.

berak gravatar imageberak ( 2015-09-07 13:13:52 -0600 )edit

Thank you @StevenPuttemans. I tried to use 400 positive samples and it stopped.

I tried to get every possible shot that i can use it as a different sample, which is 400, and that is the best i could do. How to get more positive samples? IDK

I am trying to train the classifier to identify the traffic STOP sign.

I just want to know how to use the formula [vec-file has to contain >= (numPose + (numStages-1) * (1 - minHitRate) * numPose) + S].... It makes no sense to me, specially the S. ^_^

Steven_ocv gravatar imageSteven_ocv ( 2015-09-07 15:00:15 -0600 )edit
1

Okay I am not sure about the S factor, but what seems weird to me is that the negative image grabbing seems to get stuck after the 3th stage, so let us focus on that. Reasons for this can be

  • You are using an older OpenCV version, which still contains the bug where negative sample grabbing can got into an infinite loop. Solving this problem will only work by getting the latest version. Normally a warning should be raised in the latest version if there are no more negative samples.
  • Another reason an be due to the software not finding any new negative windows that still get incorrectly classified in the previous stages (which would mean that you have an optimal classifier obtained for your data) ... but this seems rather wrong.

I would go for choice one. Can you report back?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-09-08 06:16:22 -0600 )edit

A third reason could be you are running into memory allocation problems ... which I doubt, but increasing -precalcValBufSize 1024 -precalcIdxBufSize 1024 to at least -precalcValBufSize 2048 -precalcIdxBufSize 2048 would definately help out in that case.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-09-08 06:18:22 -0600 )edit
1
  1. Thank you for your reply @StevenPuttemans. I thought about your first choice earlier, I ran the program on both opencv 2.7.10 and opencv 3.0. The same thing happened.
  2. About you third suggestion, I have a 4 gigabyte RAM and a 2.6 GHz processor, so when i ran this program , the opencv_traincascade program consumes 3.7 gigabyte of the RAM. Whenever i use 2048 bufsize , the program crushes.

Another thing I want to ask you about..... Every time I ran the opencv to train a classifier ,when it finishes the training It says "OPENCV_TRAINCASCADE STOPPED WORKING", no matter what parameter i change. Do you have any idea? ^_^

Steven_ocv gravatar imageSteven_ocv ( 2015-09-08 15:32:55 -0600 )edit

Well I am not running into the same problems, so kind of baffled for the moment what is going wrong .. it might be a problem with the negative samples ... but as I said, I would never expect this behaviour. Could you open up a link with the training data and parameter used so I can try it locally here?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-09-11 04:26:25 -0600 )edit