Commit b0f41b6e5a22f2b1eb08a77ea830c3784aec1596

Authored by Scott Klum
1 parent 373069f6

Added parameter for termination criteria

Showing 1 changed file with 12 additions and 3 deletions
openbr/plugins/tree.cpp
@@ -96,6 +96,7 @@ class ForestTransform : public Transform @@ -96,6 +96,7 @@ class ForestTransform : public Transform
96 } 96 }
97 97
98 protected: 98 protected:
  99 + Q_ENUMS(TerminationCriteria)
99 Q_PROPERTY(bool classification READ get_classification WRITE set_classification RESET reset_classification STORED false) 100 Q_PROPERTY(bool classification READ get_classification WRITE set_classification RESET reset_classification STORED false)
100 Q_PROPERTY(float splitPercentage READ get_splitPercentage WRITE set_splitPercentage RESET reset_splitPercentage STORED false) 101 Q_PROPERTY(float splitPercentage READ get_splitPercentage WRITE set_splitPercentage RESET reset_splitPercentage STORED false)
101 Q_PROPERTY(int maxDepth READ get_maxDepth WRITE set_maxDepth RESET reset_maxDepth STORED false) 102 Q_PROPERTY(int maxDepth READ get_maxDepth WRITE set_maxDepth RESET reset_maxDepth STORED false)
@@ -106,6 +107,14 @@ protected: @@ -106,6 +107,14 @@ protected:
106 Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) 107 Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
107 Q_PROPERTY(QString outputVariable READ get_outputVariable WRITE set_outputVariable RESET reset_outputVariable STORED false) 108 Q_PROPERTY(QString outputVariable READ get_outputVariable WRITE set_outputVariable RESET reset_outputVariable STORED false)
108 Q_PROPERTY(bool weight READ get_weight WRITE set_weight RESET reset_weight STORED false) 109 Q_PROPERTY(bool weight READ get_weight WRITE set_weight RESET reset_weight STORED false)
  110 + Q_PROPERTY(TerminationCriteria termCrit READ get_termCrit WRITE set_termCrit RESET reset_termCrit STORED false)
  111 +
  112 +public:
  113 + enum TerminationCriteria { Iter = CV_TERMCRIT_ITER,
  114 + EPS = CV_TERMCRIT_EPS,
  115 + Both = CV_TERMCRIT_EPS | CV_TERMCRIT_ITER};
  116 +
  117 +protected:
109 BR_PROPERTY(bool, classification, true) 118 BR_PROPERTY(bool, classification, true)
110 BR_PROPERTY(float, splitPercentage, .01) 119 BR_PROPERTY(float, splitPercentage, .01)
111 BR_PROPERTY(int, maxDepth, std::numeric_limits<int>::max()) 120 BR_PROPERTY(int, maxDepth, std::numeric_limits<int>::max())
@@ -116,6 +125,7 @@ protected: @@ -116,6 +125,7 @@ protected:
116 BR_PROPERTY(QString, inputVariable, "Label") 125 BR_PROPERTY(QString, inputVariable, "Label")
117 BR_PROPERTY(QString, outputVariable, "") 126 BR_PROPERTY(QString, outputVariable, "")
118 BR_PROPERTY(bool, weight, false) 127 BR_PROPERTY(bool, weight, false)
  128 + BR_PROPERTY(TerminationCriteria, termCrit, Iter)
119 129
120 CvRTrees forest; 130 CvRTrees forest;
121 131
@@ -139,7 +149,6 @@ protected: @@ -139,7 +149,6 @@ protected:
139 int nonZero = countNonZero(labels); 149 int nonZero = countNonZero(labels);
140 priors[0] = 1; 150 priors[0] = 1;
141 priors[1] = (float)(samples.rows-nonZero)/nonZero; 151 priors[1] = (float)(samples.rows-nonZero)/nonZero;
142 - qDebug() << priors[0] << priors[1] << (samples.rows-nonZero)/nonZero;  
143 } 152 }
144 153
145 int minSamplesForSplit = data.size()*splitPercentage; 154 int minSamplesForSplit = data.size()*splitPercentage;
@@ -149,12 +158,12 @@ protected: @@ -149,12 +158,12 @@ protected:
149 0, 158 0,
150 false, 159 false,
151 2, 160 2,
152 - usePrior ? priors : 0, //priors 161 + usePrior ? priors : 0,
153 false, 162 false,
154 0, 163 0,
155 maxTrees, 164 maxTrees,
156 forestAccuracy, 165 forestAccuracy,
157 - CV_TERMCRIT_ITER)); 166 + termCrit));
158 167
159 if (Globals->verbose) { 168 if (Globals->verbose) {
160 qDebug() << "Number of trees:" << forest.get_tree_count(); 169 qDebug() << "Number of trees:" << forest.get_tree_count();