Ask Your Question
12

about traincascade paremeters, samples, and other...

asked 2013-02-08 08:18:04 -0600

McBodik gravatar image

updated 2020-11-30 00:52:38 -0600

Hi all.

Firs of all I want to tell, my question contain many sub questions, answers to which already exist, but they are not complete or ambiguous.

So first - maxFalseAlarmRate - I have most problems with it. If this is max - it mean current false alarm less than required. But in source we can see if(tempLeafFARate <= requiredLeafFARate) then "Required leaf false alarm rate achieved." It's funny - I can make maxFalseAlarmRate = 0 and newer have this error? It's opencv 2.4.2 fault? And so - what mean maxFalseAlarmRate at all. How can I calculate it? Why we have false alarm if in negatives there are no object?

Next - if there are false alarm, my positives are bad? Size - if e.g. I have picture 100x200 what size in vec-file will be most appropriate? 10x20? How to calculate minHitRate? There says - samples must be unique. If samples are from one picture it bad? Why? They also will be unique in one object. If I created many samples from many objects, how can I pack them in vec-file?

About vec-file. How many samples should it contain? How many positives and negatives are optimal and how to choose the optimal number of stages? There are interesting error "Bad argument (Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.)". I found formula vec-file has to contain >= (numPose + (numStages-1) * (1 - minHitRate) * numPose) + S, where S is a count of samples from vec-file. If parametr numPos - number of samples in every stage, why I cant get num of samples in vec-file and divide it on num of stages? But in formula vec-file has to contain >= x + count of samples from vec-file. Maybe I understan something, "vec-file has to contain" and "count of samples from vec-file" this is not the same thing? numPose - is number of positive samples used in training for every classifier stage? What exactly does parameter -numPos means? And how to choose it?

When I start training I see number of stages, next e.g. Pos count : consumed 200 : 232 why consumed is more than count?

After that row there is no output info long time, after - Neg count : acceptance ratio What is acceptance ratio?

Next - precalculaton time - I cant understand what is it?

And the end is table with number, hit rate and false alarm rate. What mean this rows and hr and fa? hr and fa for what?

Also i want to know more about paremeters bt , weightTrimRate, maxDepth, maxWeakCount і mode. What tipe (bt) use? How calculate weightTrimRate, maxDepth, maxWeakCount, and what mode is better?

P.S. Why it takes so long before outputing numNeg Is it normal that createsample is working 4 days and it is just 6th step? How could it be : I've put falseAlarmRate=0 but there is condition in source code: 1>=falseAlarmRate >0 and it still starts without errors and warnings.

About performance. I built opencv with tbb. Traincascade use 26% cpu, but I don ... (more)

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
18

answered 2013-03-25 09:22:55 -0600

updated 2015-04-10 07:52:05 -0600

When going trough the forum in search of some guidance on train_cascade parameters, I finally found this unanswered question, which deserves some help. Mainly since most of the questions here are identical to some recently posted.

I will try to structure my answer, hopefully making it all clear to you!

ANSWER 1 : maxFalseAlarmRate

In the code you are suggesting, if(tempLeafFARate <= requiredLeafFARate), the leafFARate is not equal to the parameter maxFalseAlarmRate you are passing as an argument. Actually the leafFARate = (maxFalseAlarmRate ) ^ (current leaf level). So if you are at the 4th layer of the current weak classifier, this means that you have standard (0.995) ^4 which is actually 0.9801. If the false alarm rate goes below that, training will be stopped.

MaximumFalseAlarmRate gives you the rate that needs to be achieved on your negative count. You will always end up with NEG amount:number. That number parameter actually needs to get lower than maxFalseAlarmRate ^ (current stage depth) in order to reach again a break parameter to stop training.

Try not to mess both parameters up.

ANSWER 2 : Samples unique

You could actually use different views of a currect object to train this BUT than only that exact object will be detectable. If you want a detector for a general class, than you need to add as many examples, with as much variation, as you can get your hands on.

Once you got the samples, you can use the create_samples utility, to create a unique vector of positive elements for training.

ANSWER 3 : numPos parameter

Again one that actually creates a lot of mistakes. It is actually the amount of positive images that is fed to your training stage. However, since it can be that a positive image is excluded from training after a while, you need to use a lower number than the actual number of elements in the vector file.

If you want to read the complete solution and discussion, read this:

If you want to accept that it is like this, take 0.9 x numberOfElements in the vector as numPos parameter, which works in 98% of the cases, or 0.8 x numberOfElements in the vector if you don't want to risk failing.

Acceptanceratio was just explained in answer 1. The details of all the small questions around the formula can be found in the links provided.

ANSWER 4 : PRECALCULATION TIME

Is the time needed to take the samples that will be used for that stage training and calculate corresponding features from them. This is necessary in order to apply the boosting algorithm which decides what feature will be the next to use in your classifier.

Again, the parameters appearing in the table are explained in answer 1, besides from the hit rate which is the amount of positive samples that are actually classified as positives.

ANSWER 5 : THE REST

About the parameters, this is more details about the ... (more)

edit flag offensive delete link more

Comments

3

Very nice and extensive answer. +1 for that! You got now so many knowledge about the cascade classifier (I really am curious to use it myself ;) . What do you think of generating or extending the current documentation - so that everything is at one place?

Guanta gravatar imageGuanta ( 2013-03-25 15:39:03 -0600 )edit
2

Tough that would probably be a good idea, i do not have time to do so yet. Will consider putting my experience together in some documents soon. Still struggling with some elements myself now, but hope to find solutions soon.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-26 09:22:25 -0600 )edit

hi Steven

I have some similar question on maxFalseAlarmRate

maxFalseAlarmRate as you answered MaximumFalseAlarmRate gives you the rate that needs to be achieved on your negative count. You will always end up with NEG amount:number number is false object detection in those negative picture, is it number of picture where object is found, or number of object in one picture, or sum of both.

Anshul gravatar imageAnshul ( 2013-07-30 06:04:39 -0600 )edit
1

-wrong answer previously- What I meant is that number is the FalseAcceptanceRate for that stage. That is what is compared to the value you entered in order to break training or continue.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-30 06:18:52 -0600 )edit

as you said "Next - if there are false alarm, my positives are bad? Size - if e.g. I have picture 100x200 what size in vec-file will be most appropriate? 10x20? How to calculate minHitRate? There says - samples must be unique. If samples are from one picture it bad? Why? They also will be unique in one object. If I created many samples from many objects, how can I pack them in vec-file?"

(assuming false alarm as false detection of object) I have lot of false alarm when i set maxfalseAlarmRatio to 0.9 or 0.5 in case of 0.09 i cant detect my object. i have my actual phototograph of 1280x720 and object dimension ratio 1100x400 (avg). what size in vec-file will be most appropriate??

Please let me know if you got answer, meanwhile i am searching for it.

Anshul gravatar imageAnshul ( 2013-07-30 06:35:29 -0600 )edit

minHitRate is a parameter that you want to specify yourself. It is the minimal amount of positives getting correctly classified by your classifier. Next i would suggest using the range of like 20x50 where you divide your scales by 4. Samples from 1 image for negatives is bad if the complete image doesn't contain many variation. It searches for windows that differs enough from previous windows, so you need variance. If you have no variation in your positive samples, you will only detect a specific object, not an object class where variance is allowed. Look at the createsamples documentation page, it illustrates how to just bundle images together instead of using a single positive. You will always get a lot of false alarm. The trick is to make your detecter filter more out, or do ...

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-30 06:54:40 -0600 )edit

... postprocessing that can handle the filtering based on a naive bayes classifier or so. About your parameters, basically you don't get the complete working principle of adaBoost, cascade classifiers and so on. It is not my job to supply you with correct parameters, just to point stuff out. Knowing this I suggest you start reading on the net. I have read over 100s of sites on this topic, doing research on it for 12 months now and still I get to know new stuff every day. Getting good parameters is a finetuning process which can take some time.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-30 06:56:47 -0600 )edit

you took it wrong, i have 1203 all original image, i manually detected where is the object (x,y,h,w) in image and then bundled those images using opencv_createsamples , below is the command. opencv_createsamples -num 1201 -bg negative/negative.txt -vec imgs/vector.vec -info info.txt -maxxangle 0.1 -maxyangle 0.1 -maxzangle 0.1-maxidev 100 -bgcolor 255 -bgthresh 0 -w 64 -h 32

i have around 1100 image of 1280x1080 and 100 of random size, if i scale them by 4 , it would stilll be lot more so i have scaled them lot (24x24). just now i am trying to make train cascade 64x32 (to train cascade it take more than 18 hour on i3 pc)

Anshul gravatar imageAnshul ( 2013-07-30 07:10:19 -0600 )edit

You didn't get my point ... I only use createsampels to cut out and resize the images. I don't rotate, translate and rescale them using those parameters like max angle because it is the most unnatural behaviour possible. In real life processing, this isn't the case ... you need just samples with a lot of variation. The parameters are for problems where you can't collect alot of data.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-30 07:34:23 -0600 )edit

I was following http://note.sonots.com/SciSoftware/haartraining.html#n4ea83fa there is subtopic create sample from some

If I am not passing any argument to create_sample "opencv_createsamples -num 1201 -vec imgs/vector.vec -info info.txt -w 64 -h 32" then opencv take some default value

Info file name: info.txt Img file name: (NULL) Vec file name: imgs/vector.vec BG file name: (NULL) Num: 1201 BG color: 0 BG threshold: 80 Invert: FALSE Max intensity deviation: 40 Max x angle: 1.1 Max y angle: 1.1 Max z angle: 0.5 Show samples: FALSE Width: 64 Height: 32 Create training samples from images collection... Corrupt JPEG data: premature end of data segment Done. Created 1201 samples [

Anshul gravatar imageAnshul ( 2013-07-31 00:49:47 -0600 )edit

Question Tools

5 followers

Stats

Asked: 2013-02-08 08:18:04 -0600

Seen: 34,103 times

Last updated: Sep 16 '15