Ask Your Question
0

What are Stages in traincascade.exe?

asked 2015-11-24 07:05:32 -0600

Bhavik gravatar image

We are using 125 positive test images and 250 negative images. How many stages we should put to train the classifier? What if we give 1 stage only?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2015-11-24 07:24:56 -0600

updated 2015-11-24 07:29:18 -0600

To completely understand stages you should first read the Viola and Jones paper which discusses the principle of cascade classifiers which is a combination of weak classifiers to obtain a strong classifier. However compared to the official implementation, OpenCV has a slight addition, which are stages.

Basically

  • From the complete pool of possible features the most discriminative feature between pos and neg training set is determined.
  • That feature is used to train (in the default setting) a binary decision tree.
  • However a single tree might not do good enough to reach a weak classifier (from the paper, a weak classifier is a classifier that does a bit better then random guessing, so higher accuracy then 50%).
  • Therefore OpenCV combines stumps until the stumps combined reach the stage of a weak classifier existing out of multiple stump decision trees. Then it continues to the next stage.

Now how to define how much stages you need? Start by adding for example 25 stages, and see how the returned acceptanceRatio is small enough. I usually suggest until it goes below 10^-5. After that you are overfitting the actual model from my experience. I implemented an overload function that allows adding a acceptanceRatioBreakValue. Take a look here.

Addition: if you want a complete wrapup of the traincascade parameters and useful settings, you can get the just released book OpenCV 3 Blueprints which has a complete chapter discussing the interface.

edit flag offensive delete link more
1

answered 2015-11-25 00:56:18 -0600

belgraviton gravatar image

updated 2015-11-25 05:47:17 -0600

Matlab Cascade Classifier is a wrapper over OpenCV one. There is a good tutorial for Matlab classifier.

Total hit and false alarm rates calculated using hit (stageHR) and false alarm (stageFAR) rates for each stage:

totalHR = stageHR^NumStages;    
totalFAR = stageFAR^NumStages.

Thus values of hit and false alarm rates for each stage depend on number of stages.

Number of stages influences the amount of training data: number of positive samples to use at each stage can be estimated using the following formula (see link):

number of positive samples = floor(totalPositiveSamples / (1 + (NumStages- 1) * (1 - stageHR)))

Following information is useful for choosing a number of stages:

  • "Stages with a lower false positive rate are more complex because they contain a greater number of weak learners."
  • "Stages with a higher false positive rate contain fewer weak learners."
  • "Generally, it is better to have a greater number of simple stages because at each stage the overall false positive rate decreases exponentially. For example, if the false positive rate at each stage is 50%, then the overall false positive rate of a cascade classifier with two stages is 25%. With three stages, it becomes 12.5%, and so on."
edit flag offensive delete link more

Comments

-1 Sorry but please explain to me how posting a link of a wrapper, which is not officially supported would help to solve this problem ...

StevenPuttemans gravatar imageStevenPuttemans ( 2015-11-25 02:18:12 -0600 )edit

@StevenPuttemans in fact the link has a pretty good high-level and easy-to-understand description of Cascade Classifiers. Though I agree it should be pointed more clearly that it's just a link to get a grasp of the theory

LorenaGdL gravatar imageLorenaGdL ( 2015-11-25 02:59:19 -0600 )edit

@LorenaGdL I agree, but just copy pasting links without a deeper explanation is not what we want to aim for here :D So I rather have him updating the answer with specific guidelines from that cite and refer to it, rather then just posting a link. Also, it still contains HOG features, which are removed in OpenCV.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-11-25 03:13:39 -0600 )edit

Yes. I agree. Link only answer is not a good answer. I made my answer a bit larger :)

belgraviton gravatar imagebelgraviton ( 2015-11-25 05:49:05 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-11-24 07:05:32 -0600

Seen: 3,061 times

Last updated: Nov 25 '15