zk00006 / OpenTLD

OpenTLD is an open source library for real-time 2D tracking of a single object in video. This repository is no longer under development. For latest version see: http://www.tldvision.com/tld2.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About training the forest classifier

smtlad opened this issue · comments

Hi, all

In training the forest classifier, I don't quite the following steps like measure_forest:
if (Y[I] == 1) {
if (measure_forest(x) <= thrP)
update(x,1,1);
} else {
if (measure_forest(x) >= thrN)
update(x,0,1);
}
Why the training set is controlled by thrP or thrN? In my view, as far as we get the positive samples and negative samples in prior, just update the forest with those samples. What is the purpose of measure_forest? Any one knows? Thanks in advance.

Hello,

Y[I] is a label array that determines what's a positive and what's a negative sample. Y[I] = 1 means that the I'TH bounding box is denoted as positive, meaning that the object should be contained within this box. Similar situation for the negative.

Now, x would be an N x 1 vector (in this case, N is 10 in the current implementation), where each element of the vector is the output of 1 fern in the forest. Each element is a 13-bit binary number, where each bit is a feature. Each feature is related to the signed difference between two random locations. Therefore, for each bounding box, we will have 10 sets (ferns) of random locations. There are 13 random locations for each set (13 features per fern). Therefore, each output of a fern is placed in a location in x.

Now, measure_forest(x) determines the probability that given the bounding box, which is denoted by the aforementioned vector, that the object is contained within the bounding box. Remember, you figure out the x value from the measure_bbox_offset() function. This function will give you your feature vector x. Also, the random locations for each fern is determined by the tldGenerateFeatures.m MATLAB script.

Now, once you have this, you look at each fern output (each element of the vector), and determine the a posteriori probability that this particular fern output belongs to a positive sample. Remember, each fern will have positive and negative histograms. Once you determine the feature vector from the fern, you look up the number of positive and negative samples using this feature vector as the index (let's call them nP and nN respectively), and to determine the probability, you would do (nP / (nP + nN)). You do this for the rest of the ferns, and add up all of the probabilities over all ferns, and you average them out.

Now, the reason why if(measure_forest(x) <= thrP) is there is because during training or re-training, if x belongs to a positive bounding box BUT it does not pass the threshold of thrP, this means that we have to update the forest. If you read the paper, during the training phase, when we pass the threshold of 0.5, this should mean that the object is there, but if it isn't, you need add this positive sample to the forest.

Similarly, if you look at the thrN, if we use measure_forest(x) and it's GREATER than thrN... this means that the bounding box is classified to have the object in it, when it clearly SHOULDN'T be, so you need to update the tree again so that this negative sample is added to the forest.

Hope this helps,

  • Ray.

Thanks to Ray.

That is much clear now.
It is important to update those positive bbox into the forest if they are classified to negative(below thrP). It would correct the decision next time. And if the positive bbox is already classified correctly, there is no need to add it into the forest as it may contributes little to the classifier model. Similarly to the negative samples.

That's exactly it. There's no point in adding this training value to the forest if the feature vector is already classified as positive. Same thing for the negative samples too. You nailed it right on the head.

Glad to have helped!

Good luck,

  • Ray.

Hi!
I know this issue have not been adressed in about 9 months but I will write here anyway=)

I have a question regarding the traning phase as well.

In the code we use bootstrapping = 2 but we use the same traning samples in both bootstrapping runs.

So my question is:

  1. I'm a bit couries of how this bootstrapping process improve the classifier?

When I started to think.. The number of positive and negative examples added in the forest will not necessarily be the same between the 2 runs due the order of negative and positive examples drawn from the permutation and the thresholds you mentioned above.

One thing that the bootstrapping process does with the current thresholds of pThrs = 0.5 and nThrs = 0.0 is that it will reduce the probability for getting a positive response from the forest for a certain patch. For example:

If we only hade one node n1 and we where to perform the bootstrapping process with the following sequence of positive and negative examples added to it:

bootstrap run 1:

  1. p_ex added | pn = (nr_pex)/(nr_pex+nr_nex) = 1
  2. p_ex will not be added since pn > 0.5
  3. n_ex added | pn = 0,5 (nr_pex = 1, nr_ex = 1)
  4. n_ex added | pn = 1/3 (nr_pex = 1, nr_ex = 2)
  5. n_ex added | pn = 1/4 (nr_pex = 1, nr_ex = 3)

Bootstrap run 2:

  1. p_ex added | pn = 2/5 (nr_pex = 2, nr_ex = 3)
  2. p_ex added | pn = 3/6 (nr_pex = 3, nr_ex = 3)
  3. n_ex added | pn = 3/7 (nr_pex = 3, nr_ex = 4)
  4. n_ex added | pn = 3/8 (nr_pex = 3, nr_ex = 5)
  5. n_ex added | pn = 3/9 (nr_pex = 3, nr_ex = 6)

Final pn = 3/9.
If we where to adjust the thresholds pThrs = 1 we would have pn = 4/10 which would give a higher probability for it to give a positive response. So by changing these parameters in traning we can decide if the classifier should have a higher probability of giving a false positive then giving a positive false.

Is this how you can see the bootstrapping process in TLD?

Best regards
Fredrik