Commit 702b2f03db64d64ffb0635bb11428dbbb36d37ec
1 parent
b8093d6d
Added maxStage parameter and some documentation
Showing
1 changed file
with
9 additions
and
1 deletions
openbr/plugins/classification/cascade.cpp
| ... | ... | @@ -92,6 +92,8 @@ struct Miner |
| 92 | 92 | * \br_property int numPos The number of positives to feed each stage during training |
| 93 | 93 | * \br_property int numNegs The number of negatives to feed each stage during training. A negative sample must have been classified by the previous stages in the cascade as positive to be fed to the next stage during training. |
| 94 | 94 | * \br_property float maxFAR A termination parameter. Calculated as (number of passed negatives) / (total number of checked negatives) for a given stage during training. If that number is below the given maxFAR cascade training is terminated early. This can help prevent overfitting. |
| 95 | + * \br_property bool requireAllStages If true, the cascade will train until it has the number of stages specified by numStages even if the FAR at a given is lower than maxFAR. | |
| 96 | + * \br_property int maxStage Parameter to limit the stages used at test time. If -1 (default), all numStages stages will be used. | |
| 95 | 97 | * \br_paper Paul Viola, Michael Jones |
| 96 | 98 | * Rapid Object Detection using a Boosted Cascade of Simple Features |
| 97 | 99 | * CVPR, 2001 |
| ... | ... | @@ -107,6 +109,7 @@ class CascadeClassifier : public Classifier |
| 107 | 109 | Q_PROPERTY(int numNegs READ get_numNegs WRITE set_numNegs RESET reset_numNegs STORED false) |
| 108 | 110 | Q_PROPERTY(float maxFAR READ get_maxFAR WRITE set_maxFAR RESET reset_maxFAR STORED false) |
| 109 | 111 | Q_PROPERTY(bool requireAllStages READ get_requireAllStages WRITE set_requireAllStages RESET reset_requireAllStages STORED false) |
| 112 | + Q_PROPERTY(int maxStage READ get_maxStage WRITE set_maxStage RESET reset_maxStage STORED false) | |
| 110 | 113 | |
| 111 | 114 | BR_PROPERTY(QString, stageDescription, "") |
| 112 | 115 | BR_PROPERTY(int, numStages, 20) |
| ... | ... | @@ -114,6 +117,7 @@ class CascadeClassifier : public Classifier |
| 114 | 117 | BR_PROPERTY(int, numNegs, 1000) |
| 115 | 118 | BR_PROPERTY(float, maxFAR, pow(0.5, numStages)) |
| 116 | 119 | BR_PROPERTY(bool, requireAllStages, false) |
| 120 | + BR_PROPERTY(int, maxStage, -1) | |
| 117 | 121 | |
| 118 | 122 | QList<Classifier *> stages; |
| 119 | 123 | TemplateList posImages, negImages; |
| ... | ... | @@ -231,7 +235,11 @@ class CascadeClassifier : public Classifier |
| 231 | 235 | float classify(const Template &src, bool process, float *confidence) const |
| 232 | 236 | { |
| 233 | 237 | float stageConf = 0.0f; |
| 234 | - foreach (const Classifier *stage, stages) { | |
| 238 | + const int stopStage = maxStage == -1 ? numStages : maxStage; | |
| 239 | + int stageIndex = 0; | |
| 240 | + foreach (const Classifier *stage, stages) { | |
| 241 | + if (stageIndex == stopStage) | |
| 242 | + break; | |
| 235 | 243 | float result = stage->classify(src, process, &stageConf); |
| 236 | 244 | if (confidence) |
| 237 | 245 | *confidence += stageConf; | ... | ... |