Commit 17b6c8f0ce42012d046d80523b7aed9197935393

Authored by Charles Otto
1 parent 6a1fa990

Replace some direct use of "Label" with inputVariable properties

Replace direct use of "Label" by most supervised learning algorithms with
inputVariable br properties (default value "Label")
openbr/plugins/cluster.cpp
@@ -90,11 +90,13 @@ class KNNTransform : public Transform @@ -90,11 +90,13 @@ class KNNTransform : public Transform
90 Q_PROPERTY(bool weighted READ get_weighted WRITE set_weighted RESET reset_weighted STORED false) 90 Q_PROPERTY(bool weighted READ get_weighted WRITE set_weighted RESET reset_weighted STORED false)
91 Q_PROPERTY(int numSubjects READ get_numSubjects WRITE set_numSubjects RESET reset_numSubjects STORED false) 91 Q_PROPERTY(int numSubjects READ get_numSubjects WRITE set_numSubjects RESET reset_numSubjects STORED false)
92 Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) 92 Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
  93 + Q_PROPERTY(QString outputVariable READ get_outputVariable WRITE set_outputVariable RESET reset_outputVariable STORED false)
93 BR_PROPERTY(int, k, 1) 94 BR_PROPERTY(int, k, 1)
94 BR_PROPERTY(br::Distance*, distance, NULL) 95 BR_PROPERTY(br::Distance*, distance, NULL)
95 BR_PROPERTY(bool, weighted, false) 96 BR_PROPERTY(bool, weighted, false)
96 BR_PROPERTY(int, numSubjects, 1) 97 BR_PROPERTY(int, numSubjects, 1)
97 BR_PROPERTY(QString, inputVariable, "Label") 98 BR_PROPERTY(QString, inputVariable, "Label")
  99 + BR_PROPERTY(QString, outputVariable, "KNN")
98 100
99 TemplateList gallery; 101 TemplateList gallery;
100 102
@@ -123,7 +125,7 @@ class KNNTransform : public Transform @@ -123,7 +125,7 @@ class KNNTransform : public Transform
123 sortedScores.removeAt(j); 125 sortedScores.removeAt(j);
124 } 126 }
125 127
126 - dst.file.set("KNN", subjects.size() > 1 ? "[" + subjects.join(",") + "]" : subjects.first()); 128 + dst.file.set(outputVariable, subjects.size() > 1 ? "[" + subjects.join(",") + "]" : subjects.first());
127 } 129 }
128 130
129 void store(QDataStream &stream) const 131 void store(QDataStream &stream) const
openbr/plugins/independent.cpp
@@ -9,7 +9,7 @@ using namespace cv; @@ -9,7 +9,7 @@ using namespace cv;
9 namespace br 9 namespace br
10 { 10 {
11 11
12 -static TemplateList Downsample(const TemplateList &templates, const Transform *transform) 12 +static TemplateList Downsample(const TemplateList &templates, const Transform *transform, const QString & inputVariable)
13 { 13 {
14 // Return early when no downsampling is required 14 // Return early when no downsampling is required
15 if ((transform->classes == std::numeric_limits<int>::max()) && 15 if ((transform->classes == std::numeric_limits<int>::max()) &&
@@ -20,11 +20,11 @@ static TemplateList Downsample(const TemplateList &amp;templates, const Transform *t @@ -20,11 +20,11 @@ static TemplateList Downsample(const TemplateList &amp;templates, const Transform *t
20 const bool atLeast = transform->instances < 0; 20 const bool atLeast = transform->instances < 0;
21 const int instances = abs(transform->instances); 21 const int instances = abs(transform->instances);
22 22
23 - QList<QString> allLabels = templates.get<QString>("Label"); 23 + QList<QString> allLabels = templates.get<QString>(inputVariable);
24 QList<QString> uniqueLabels = allLabels.toSet().toList(); 24 QList<QString> uniqueLabels = allLabels.toSet().toList();
25 qSort(uniqueLabels); 25 qSort(uniqueLabels);
26 26
27 - QMap<QString,int> counts = templates.countValues<QString>("Label", instances != std::numeric_limits<int>::max()); 27 + QMap<QString,int> counts = templates.countValues<QString>(inputVariable, instances != std::numeric_limits<int>::max());
28 28
29 if ((instances != std::numeric_limits<int>::max()) && (transform->classes != std::numeric_limits<int>::max())) 29 if ((instances != std::numeric_limits<int>::max()) && (transform->classes != std::numeric_limits<int>::max()))
30 foreach (const QString & label, counts.keys()) 30 foreach (const QString & label, counts.keys())
@@ -74,7 +74,9 @@ class IndependentTransform : public MetaTransform @@ -74,7 +74,9 @@ class IndependentTransform : public MetaTransform
74 { 74 {
75 Q_OBJECT 75 Q_OBJECT
76 Q_PROPERTY(br::Transform* transform READ get_transform WRITE set_transform RESET reset_transform STORED false) 76 Q_PROPERTY(br::Transform* transform READ get_transform WRITE set_transform RESET reset_transform STORED false)
  77 + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
77 BR_PROPERTY(br::Transform*, transform, NULL) 78 BR_PROPERTY(br::Transform*, transform, NULL)
  79 + BR_PROPERTY(QString, inputVariable, "Label")
78 80
79 QList<Transform*> transforms; 81 QList<Transform*> transforms;
80 82
@@ -123,7 +125,7 @@ class IndependentTransform : public MetaTransform @@ -123,7 +125,7 @@ class IndependentTransform : public MetaTransform
123 transforms.append(transform->clone()); 125 transforms.append(transform->clone());
124 126
125 for (int i=0; i<templatesList.size(); i++) 127 for (int i=0; i<templatesList.size(); i++)
126 - templatesList[i] = Downsample(templatesList[i], transforms[i]); 128 + templatesList[i] = Downsample(templatesList[i], transforms[i], inputVariable);
127 129
128 QFutureSynchronizer<void> futures; 130 QFutureSynchronizer<void> futures;
129 for (int i=0; i<templatesList.size(); i++) 131 for (int i=0; i<templatesList.size(); i++)
openbr/plugins/normalize.cpp
@@ -97,6 +97,7 @@ class CenterTransform : public Transform @@ -97,6 +97,7 @@ class CenterTransform : public Transform
97 Q_OBJECT 97 Q_OBJECT
98 Q_ENUMS(Method) 98 Q_ENUMS(Method)
99 Q_PROPERTY(Method method READ get_method WRITE set_method RESET reset_method STORED false) 99 Q_PROPERTY(Method method READ get_method WRITE set_method RESET reset_method STORED false)
  100 + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
100 101
101 public: 102 public:
102 /*!< */ 103 /*!< */
@@ -107,6 +108,7 @@ public: @@ -107,6 +108,7 @@ public:
107 108
108 private: 109 private:
109 BR_PROPERTY(Method, method, Mean) 110 BR_PROPERTY(Method, method, Mean)
  111 + BR_PROPERTY(QString, inputVariable, "Label")
110 112
111 Mat a, b; // dst = (src - b) / a 113 Mat a, b; // dst = (src - b) / a
112 114
@@ -127,7 +129,7 @@ private: @@ -127,7 +129,7 @@ private:
127 Mat m; 129 Mat m;
128 OpenCVUtils::toMat(data.data()).convertTo(m, CV_64F); 130 OpenCVUtils::toMat(data.data()).convertTo(m, CV_64F);
129 131
130 - const QList<int> labels = data.indexProperty("Label"); 132 + const QList<int> labels = data.indexProperty(inputVariable);
131 const int dims = m.cols; 133 const int dims = m.cols;
132 134
133 vector<Mat> mv, av, bv; 135 vector<Mat> mv, av, bv;
openbr/plugins/quality.cpp
@@ -19,17 +19,20 @@ class ImpostorUniquenessMeasureTransform : public Transform @@ -19,17 +19,20 @@ class ImpostorUniquenessMeasureTransform : public Transform
19 Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) 19 Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false)
20 Q_PROPERTY(double mean READ get_mean WRITE set_mean RESET reset_mean) 20 Q_PROPERTY(double mean READ get_mean WRITE set_mean RESET reset_mean)
21 Q_PROPERTY(double stddev READ get_stddev WRITE set_stddev RESET reset_stddev) 21 Q_PROPERTY(double stddev READ get_stddev WRITE set_stddev RESET reset_stddev)
  22 + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
22 BR_PROPERTY(br::Distance*, distance, Distance::make("Dist(L2)", this)) 23 BR_PROPERTY(br::Distance*, distance, Distance::make("Dist(L2)", this))
23 BR_PROPERTY(double, mean, 0) 24 BR_PROPERTY(double, mean, 0)
24 BR_PROPERTY(double, stddev, 1) 25 BR_PROPERTY(double, stddev, 1)
  26 + BR_PROPERTY(QString, inputVariable, "Label")
  27 +
25 TemplateList impostors; 28 TemplateList impostors;
26 29
27 float calculateIUM(const Template &probe, const TemplateList &gallery) const 30 float calculateIUM(const Template &probe, const TemplateList &gallery) const
28 { 31 {
29 - const QString probeLabel = probe.file.get<QString>("Label"); 32 + const QString probeLabel = probe.file.get<QString>(inputVariable);
30 TemplateList subset = gallery; 33 TemplateList subset = gallery;
31 for (int j=subset.size()-1; j>=0; j--) 34 for (int j=subset.size()-1; j>=0; j--)
32 - if (subset[j].file.get<QString>("Label") == probeLabel) 35 + if (subset[j].file.get<QString>(inputVariable) == probeLabel)
33 subset.removeAt(j); 36 subset.removeAt(j);
34 37
35 QList<float> scores = distance->compare(subset, probe); 38 QList<float> scores = distance->compare(subset, probe);
@@ -151,6 +154,7 @@ class MatchProbabilityDistance : public Distance @@ -151,6 +154,7 @@ class MatchProbabilityDistance : public Distance
151 Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) 154 Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false)
152 Q_PROPERTY(bool gaussian READ get_gaussian WRITE set_gaussian RESET reset_gaussian STORED false) 155 Q_PROPERTY(bool gaussian READ get_gaussian WRITE set_gaussian RESET reset_gaussian STORED false)
153 Q_PROPERTY(bool crossModality READ get_crossModality WRITE set_crossModality RESET reset_crossModality STORED false) 156 Q_PROPERTY(bool crossModality READ get_crossModality WRITE set_crossModality RESET reset_crossModality STORED false)
  157 + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
154 158
155 MP mp; 159 MP mp;
156 160
@@ -158,7 +162,7 @@ class MatchProbabilityDistance : public Distance @@ -158,7 +162,7 @@ class MatchProbabilityDistance : public Distance
158 { 162 {
159 distance->train(src); 163 distance->train(src);
160 164
161 - const QList<int> labels = src.indexProperty("Label"); 165 + const QList<int> labels = src.indexProperty(inputVariable);
162 QScopedPointer<MatrixOutput> matrixOutput(MatrixOutput::make(FileList(src.size()), FileList(src.size()))); 166 QScopedPointer<MatrixOutput> matrixOutput(MatrixOutput::make(FileList(src.size()), FileList(src.size())));
163 distance->compare(src, src, matrixOutput.data()); 167 distance->compare(src, src, matrixOutput.data());
164 168
@@ -201,6 +205,7 @@ protected: @@ -201,6 +205,7 @@ protected:
201 BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) 205 BR_PROPERTY(br::Distance*, distance, make("Dist(L2)"))
202 BR_PROPERTY(bool, gaussian, true) 206 BR_PROPERTY(bool, gaussian, true)
203 BR_PROPERTY(bool, crossModality, false) 207 BR_PROPERTY(bool, crossModality, false)
  208 + BR_PROPERTY(QString, inputVariable, "Label")
204 }; 209 };
205 210
206 BR_REGISTER(Distance, MatchProbabilityDistance) 211 BR_REGISTER(Distance, MatchProbabilityDistance)
@@ -217,10 +222,12 @@ class HeatMapDistance : public Distance @@ -217,10 +222,12 @@ class HeatMapDistance : public Distance
217 Q_PROPERTY(bool gaussian READ get_gaussian WRITE set_gaussian RESET reset_gaussian STORED false) 222 Q_PROPERTY(bool gaussian READ get_gaussian WRITE set_gaussian RESET reset_gaussian STORED false)
218 Q_PROPERTY(bool crossModality READ get_crossModality WRITE set_crossModality RESET reset_crossModality STORED false) 223 Q_PROPERTY(bool crossModality READ get_crossModality WRITE set_crossModality RESET reset_crossModality STORED false)
219 Q_PROPERTY(int step READ get_step WRITE set_step RESET reset_step STORED false) 224 Q_PROPERTY(int step READ get_step WRITE set_step RESET reset_step STORED false)
  225 + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
220 BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) 226 BR_PROPERTY(br::Distance*, distance, make("Dist(L2)"))
221 BR_PROPERTY(bool, gaussian, true) 227 BR_PROPERTY(bool, gaussian, true)
222 BR_PROPERTY(bool, crossModality, false) 228 BR_PROPERTY(bool, crossModality, false)
223 BR_PROPERTY(int, step, 1) 229 BR_PROPERTY(int, step, 1)
  230 + BR_PROPERTY(QString, inputVariable, "Label")
224 231
225 QList<MP> mp; 232 QList<MP> mp;
226 233
@@ -228,7 +235,7 @@ class HeatMapDistance : public Distance @@ -228,7 +235,7 @@ class HeatMapDistance : public Distance
228 { 235 {
229 distance->train(src); 236 distance->train(src);
230 237
231 - const QList<int> labels = src.indexProperty("Label"); 238 + const QList<int> labels = src.indexProperty(inputVariable);
232 239
233 QList<TemplateList> patches; 240 QList<TemplateList> patches;
234 241
@@ -309,14 +316,16 @@ class UnitDistance : public Distance @@ -309,14 +316,16 @@ class UnitDistance : public Distance
309 Q_PROPERTY(br::Distance *distance READ get_distance WRITE set_distance RESET reset_distance) 316 Q_PROPERTY(br::Distance *distance READ get_distance WRITE set_distance RESET reset_distance)
310 Q_PROPERTY(float a READ get_a WRITE set_a RESET reset_a) 317 Q_PROPERTY(float a READ get_a WRITE set_a RESET reset_a)
311 Q_PROPERTY(float b READ get_b WRITE set_b RESET reset_b) 318 Q_PROPERTY(float b READ get_b WRITE set_b RESET reset_b)
  319 + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
312 BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) 320 BR_PROPERTY(br::Distance*, distance, make("Dist(L2)"))
313 BR_PROPERTY(float, a, 1) 321 BR_PROPERTY(float, a, 1)
314 BR_PROPERTY(float, b, 0) 322 BR_PROPERTY(float, b, 0)
  323 + BR_PROPERTY(QString, inputVariable, "Label")
315 324
316 void train(const TemplateList &templates) 325 void train(const TemplateList &templates)
317 { 326 {
318 const TemplateList samples = templates.mid(0, 2000); 327 const TemplateList samples = templates.mid(0, 2000);
319 - const QList<int> sampleLabels = samples.indexProperty("Label"); 328 + const QList<int> sampleLabels = samples.indexProperty(inputVariable);
320 QScopedPointer<MatrixOutput> matrixOutput(MatrixOutput::make(FileList(samples.size()), FileList(samples.size()))); 329 QScopedPointer<MatrixOutput> matrixOutput(MatrixOutput::make(FileList(samples.size()), FileList(samples.size())));
321 Distance::compare(samples, samples, matrixOutput.data()); 330 Distance::compare(samples, samples, matrixOutput.data());
322 331
openbr/plugins/quantize.cpp
@@ -120,6 +120,10 @@ BR_REGISTER(Transform, HistEqQuantizationTransform) @@ -120,6 +120,10 @@ BR_REGISTER(Transform, HistEqQuantizationTransform)
120 class BayesianQuantizationDistance : public Distance 120 class BayesianQuantizationDistance : public Distance
121 { 121 {
122 Q_OBJECT 122 Q_OBJECT
  123 +
  124 + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
  125 + BR_PROPERTY(QString, inputVariable, "Label")
  126 +
123 QVector<float> loglikelihoods; 127 QVector<float> loglikelihoods;
124 128
125 static void computeLogLikelihood(const Mat &data, const QList<int> &labels, float *loglikelihood) 129 static void computeLogLikelihood(const Mat &data, const QList<int> &labels, float *loglikelihood)
@@ -150,7 +154,7 @@ class BayesianQuantizationDistance : public Distance @@ -150,7 +154,7 @@ class BayesianQuantizationDistance : public Distance
150 qFatal("Expected sigle matrix templates of type CV_8UC1!"); 154 qFatal("Expected sigle matrix templates of type CV_8UC1!");
151 155
152 const Mat data = OpenCVUtils::toMat(src.data()); 156 const Mat data = OpenCVUtils::toMat(src.data());
153 - const QList<int> templateLabels = src.indexProperty("Label"); 157 + const QList<int> templateLabels = src.indexProperty(inputVariable);
154 loglikelihoods = QVector<float>(data.cols*256, 0); 158 loglikelihoods = QVector<float>(data.cols*256, 0);
155 159
156 QFutureSynchronizer<void> futures; 160 QFutureSynchronizer<void> futures;
@@ -343,9 +347,11 @@ class ProductQuantizationTransform : public Transform @@ -343,9 +347,11 @@ class ProductQuantizationTransform : public Transform
343 Q_PROPERTY(int n READ get_n WRITE set_n RESET reset_n STORED false) 347 Q_PROPERTY(int n READ get_n WRITE set_n RESET reset_n STORED false)
344 Q_PROPERTY(br::Distance *distance READ get_distance WRITE set_distance RESET reset_distance STORED false) 348 Q_PROPERTY(br::Distance *distance READ get_distance WRITE set_distance RESET reset_distance STORED false)
345 Q_PROPERTY(bool bayesian READ get_bayesian WRITE set_bayesian RESET reset_bayesian STORED false) 349 Q_PROPERTY(bool bayesian READ get_bayesian WRITE set_bayesian RESET reset_bayesian STORED false)
  350 + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
346 BR_PROPERTY(int, n, 2) 351 BR_PROPERTY(int, n, 2)
347 BR_PROPERTY(br::Distance*, distance, Distance::make("L2", this)) 352 BR_PROPERTY(br::Distance*, distance, Distance::make("L2", this))
348 BR_PROPERTY(bool, bayesian, false) 353 BR_PROPERTY(bool, bayesian, false)
  354 + BR_PROPERTY(QString, inputVariable, "Label")
349 355
350 quint16 index; 356 quint16 index;
351 QList<Mat> centers; 357 QList<Mat> centers;
@@ -474,7 +480,7 @@ private: @@ -474,7 +480,7 @@ private:
474 Mat data = OpenCVUtils::toMat(src.data()); 480 Mat data = OpenCVUtils::toMat(src.data());
475 const int step = getStep(data.cols); 481 const int step = getStep(data.cols);
476 482
477 - const QList<int> labels = src.indexProperty("Label"); 483 + const QList<int> labels = src.indexProperty(inputVariable);
478 484
479 Mat &lut = ProductQuantizationLUTs[index]; 485 Mat &lut = ProductQuantizationLUTs[index];
480 lut = Mat(getDims(data.cols), 256*(256+1)/2, CV_32FC1); 486 lut = Mat(getDims(data.cols), 256*(256+1)/2, CV_32FC1);
openbr/plugins/quantize2.cpp
@@ -19,6 +19,10 @@ namespace br @@ -19,6 +19,10 @@ namespace br
19 class BayesianQuantizationTransform : public Transform 19 class BayesianQuantizationTransform : public Transform
20 { 20 {
21 Q_OBJECT 21 Q_OBJECT
  22 +
  23 + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
  24 + BR_PROPERTY(QString, inputVariable, "Label")
  25 +
22 QVector<float> thresholds; 26 QVector<float> thresholds;
23 27
24 static void computeThresholdsRecursive(const QVector<int> &cumulativeGenuines, const QVector<int> &cumulativeImpostors, 28 static void computeThresholdsRecursive(const QVector<int> &cumulativeGenuines, const QVector<int> &cumulativeImpostors,
@@ -77,7 +81,7 @@ class BayesianQuantizationTransform : public Transform @@ -77,7 +81,7 @@ class BayesianQuantizationTransform : public Transform
77 void train(const TemplateList &src) 81 void train(const TemplateList &src)
78 { 82 {
79 const Mat data = OpenCVUtils::toMat(src.data()); 83 const Mat data = OpenCVUtils::toMat(src.data());
80 - const QList<int> labels = src.indexProperty("Label"); 84 + const QList<int> labels = src.indexProperty(inputVariable);
81 85
82 thresholds = QVector<float>(256*data.cols); 86 thresholds = QVector<float>(256*data.cols);
83 87