Machine Perception Primitive:
An implementation of a GentleBoost classifier for image patch classification.
More...
#include <GentleBoostClassifier.h>
Public Member Functions | |
GentleBoostClassifier () | |
Constructor. | |
virtual | ~GentleBoostClassifier () |
Destructor. | |
virtual IplImage * | getProbabilityMap (PatchList *patches) |
Evaluate every pixel in an image for its probability that an object is located there. | |
void | searchPatches (const std::vector< ImagePatch * > &patches, const CvMat *labels, CvMat *&featureSum, CvMat *&posterior, CvMat *&predictions, std::vector< CvMat * > &featureOutputs, double &perf, CvMat *&weights) |
Apply the GentleBoostClasssifier to a classify collection of image patches. | |
virtual void | setTrainingSet (const std::vector< ImagePatch * > &trainingPatches, const CvMat *trainingLabels) |
Set ImagePatch data and labels used for training the classifier. | |
virtual void | setTestingSet (const std::vector< ImagePatch * > &testingPatches, const CvMat *testingLabels) |
Set ImagePatch data and labels used for evaluating the classifier. | |
virtual void | addFeature (Feature *nextFeature) |
Add a feature to the classifier. | |
void | getPerformanceMeasures (Feature *candidate, double &chiSq) |
Compute perfomance measures for this classifier, depending on the Feature* passed in. This is primarily used for finding the best feature to add to the classifier, using addFeature(). | |
int | getNumFeaturesUsed () |
How many of its total features is the classifier currently using? To improve speed or avoid generalization errors, it may be useful to only use the first few features of the classifier. | |
int | getNumFeaturesTotal () |
How many total available, trained features does the classifier have? | |
void | setNumFeaturesUsed (int num) |
Number of trained and available features to use. To improve speed or avoid generalization errors, it may be useful to only use the first few features of the classifier. | |
FeatureRegressor * | getFeatureAndTuningCurveNumber (int num) |
Examine the features used by this GentleBoostClassifier. | |
cv::Size | getBasePatchSize () |
Size of patches used for training. All features added must have a size equal to getBasePatchSize(). | |
Friends | |
std::ostream & | operator<< (std::ostream &ofs, GentleBoostClassifier *feat) |
Write to a file. | |
std::istream & | operator>> (std::istream &ifs, GentleBoostClassifier *&feat) |
Read from a file. |
Machine Perception Primitive:
An implementation of a GentleBoost classifier for image patch classification.
The GentleBoost approach is described in Fasel's "Learning Real-Time Object Detectors: Probabilistic Generative Approaches", 2006 (see Related Publications).
GentleBoostClassifier is only suitable for whole patch classification. It is not meant to be used to search for objects in scenes. For that application, see GentleBoostCascadedClassifier.
void GentleBoostClassifier::addFeature | ( | Feature * | nextFeature ) | [virtual] |
Add a feature to the classifier.
This will create a FeatureRegressor and compute its tuning curve based on the current weighting of the training examples, and then reweight the training examples according to the GentleBoost algorithm.
nextFeature | The feature to add. |
Reimplemented in GentleBoostCascadedClassifier.
cv::Size GentleBoostClassifier::getBasePatchSize | ( | ) |
Size of patches used for training. All features added must have a size equal to getBasePatchSize().
getBasePatchSize() is set implicitly by the first feature added.
FeatureRegressor * GentleBoostClassifier::getFeatureAndTuningCurveNumber | ( | int | num ) |
Examine the features used by this GentleBoostClassifier.
num | Index of the feature to query, numbered 0 to getNumFeaturesTotal()-1. |
int GentleBoostClassifier::getNumFeaturesTotal | ( | ) |
How many total available, trained features does the classifier have?
int GentleBoostClassifier::getNumFeaturesUsed | ( | ) |
How many of its total features is the classifier currently using? To improve speed or avoid generalization errors, it may be useful to only use the first few features of the classifier.
void GentleBoostClassifier::getPerformanceMeasures | ( | Feature * | candidate, |
double & | chiSq | ||
) |
Compute perfomance measures for this classifier, depending on the Feature* passed in. This is primarily used for finding the best feature to add to the classifier, using addFeature().
getPerformanceMeasures has three modes depending on the candidate feature:
candidate | Can be NULL, one of the features in the classifier, or a candidate feature to add to the classifier. |
chiSq | The computed error measure. |
IplImage * GentleBoostClassifier::getProbabilityMap | ( | PatchList * | patches ) | [virtual] |
Evaluate every pixel in an image for its probability that an object is located there.
Since GentleBoostClassifier is not a cascade, this process is somewhat slow. Also, GentleBoostClassifier has no notion of "rejection," so it cannot "find" patches containing the object. It can only give a patch-by-patch estimate of the likelihood that that patch is the object.
patches | A PatchList that has had setImage() called, and also resetListToScale(). Only the current search scale is evaluated. |
void GentleBoostClassifier::searchPatches | ( | const std::vector< ImagePatch * > & | patches, |
const CvMat * | labels, | ||
CvMat *& | featureSum, | ||
CvMat *& | posterior, | ||
CvMat *& | predictions, | ||
std::vector< CvMat * > & | featureOutputs, | ||
double & | perf, | ||
CvMat *& | weights | ||
) |
Apply the GentleBoostClasssifier to a classify collection of image patches.
This classification requires a lot of scratch memory, which you can provide. The behavior of this function depends on which provided pointers are NULL. For example, perf and weights are only computed if labels is not NULL, whereas featureSum, posterior, and predictions are always computed. If any matrices that are required are NULL or incorrectly sized, they will be (re)allocated, and the caller of the function is responsible for managing that memory.
patches | A list of patches to classify. |
labels | Optional labels for the patches, to evaluate classifier performance. |
featureSum | The accumulated feature output that is used to predict the label of the patch. |
posterior | The probability estimate that the patch was generated by the trained class. |
predictions | Binary (+1/-1) classification labels applied by the classifier. |
featureOutputs | The output of each individual FeatureRegressor applied to each patch. |
perf | Chi-Squared error in predicting labels (only set if labels are provided). |
weights | Weights based on boosting that can be used for training the next feature. |
void GentleBoostClassifier::setNumFeaturesUsed | ( | int | num ) |
Number of trained and available features to use. To improve speed or avoid generalization errors, it may be useful to only use the first few features of the classifier.
num | Number of features to use. Should be less than or equal to getNumFeaturesTotal(). |
virtual void GentleBoostClassifier::setTestingSet | ( | const std::vector< ImagePatch * > & | testingPatches, |
const CvMat * | testingLabels | ||
) | [virtual] |
Set ImagePatch data and labels used for evaluating the classifier.
testingPatches | A collection of positive and negative examples that the classifier's discrimination will be evaluated on. |
testingLabels | Binary (+1/-1) indicating the label of each patch. This should be a matrix of type CV_64FC1 with size numPatches x 1. |
virtual void GentleBoostClassifier::setTrainingSet | ( | const std::vector< ImagePatch * > & | trainingPatches, |
const CvMat * | trainingLabels | ||
) | [virtual] |
Set ImagePatch data and labels used for training the classifier.
trainingPatches | A collection of positive and negative examples that the classifier should learn to discriminate. |
trainingLabels | Binary (+1/-1) indicating the label of each patch. This should be a matrix of type CV_64FC1 with size numPatches x 1. |