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