Commit e3a2aca78aee3ce99ca81f8fe08e8905679a13e8

Authored by Josh Klontz
2 parents 3ed08edc b531dc36

Merge pull request #305 from biometrics/distance_trainable

introduced br::Distance::trainable() and UntrainableDistance
openbr/core/core.cpp
... ... @@ -77,7 +77,7 @@ struct AlgorithmCore
77 77 qDebug("Training Enrollment");
78 78 trainingWrapper->train(data);
79 79  
80   - if (!distance.isNull()) {
  80 + if (!distance.isNull() && distance->trainable()) {
81 81 if (Globals->crossValidate > 0)
82 82 for (int i=data.size()-1; i>=0; i--) if (data[i].file.get<bool>("allPartitions",false)) data.removeAt(i);
83 83  
... ...
openbr/openbr_plugin.h
... ... @@ -1358,7 +1358,8 @@ public:
1358 1358 static Distance *make(QString str, QObject *parent); /*!< \brief Make a distance from a string. */
1359 1359  
1360 1360 static QSharedPointer<Distance> fromAlgorithm(const QString &algorithm); /*!< \brief Retrieve an algorithm's distance. */
1361   - virtual void train(const TemplateList &src) { (void) src; } /*!< \brief Train the distance. */
  1361 + virtual bool trainable() { return true; } /*!< \brief \c true if The distance implements train(), false otherwise. */
  1362 + virtual void train(const TemplateList &src) = 0; /*!< \brief Train the distance. */
1362 1363 virtual void compare(const TemplateList &target, const TemplateList &query, Output *output) const; /*!< \brief Compare two template lists. */
1363 1364 virtual QList<float> compare(const TemplateList &targets, const Template &query) const; /*!< \brief Compute the normalized distance between a template and a template list. */
1364 1365 virtual float compare(const Template &a, const Template &b) const; /*!< \brief Compute the distance between two templates. */
... ...
openbr/plugins/distance.cpp
... ... @@ -35,7 +35,7 @@ namespace br
35 35 * \brief Standard distance metrics
36 36 * \author Josh Klontz \cite jklontz
37 37 */
38   -class DistDistance : public Distance
  38 +class DistDistance : public UntrainableDistance
39 39 {
40 40 Q_OBJECT
41 41 Q_ENUMS(Metric)
... ... @@ -128,7 +128,7 @@ BR_REGISTER(Distance, DistDistance)
128 128 * \brief DistDistance wrapper.
129 129 * \author Josh Klontz \cite jklontz
130 130 */
131   -class DefaultDistance : public Distance
  131 +class DefaultDistance : public UntrainableDistance
132 132 {
133 133 Q_OBJECT
134 134 Distance *distance;
... ... @@ -279,7 +279,7 @@ BR_REGISTER(Distance, FuseDistance)
279 279 * \brief Fast 8-bit L1 distance
280 280 * \author Josh Klontz \cite jklontz
281 281 */
282   -class ByteL1Distance : public Distance
  282 +class ByteL1Distance : public UntrainableDistance
283 283 {
284 284 Q_OBJECT
285 285  
... ... @@ -296,7 +296,7 @@ BR_REGISTER(Distance, ByteL1Distance)
296 296 * \brief Fast 4-bit L1 distance
297 297 * \author Josh Klontz \cite jklontz
298 298 */
299   -class HalfByteL1Distance : public Distance
  299 +class HalfByteL1Distance : public UntrainableDistance
300 300 {
301 301 Q_OBJECT
302 302  
... ... @@ -313,7 +313,7 @@ BR_REGISTER(Distance, HalfByteL1Distance)
313 313 * \brief Returns -log(distance(a,b)+1)
314 314 * \author Josh Klontz \cite jklontz
315 315 */
316   -class NegativeLogPlusOneDistance : public Distance
  316 +class NegativeLogPlusOneDistance : public UntrainableDistance
317 317 {
318 318 Q_OBJECT
319 319 Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false)
... ... @@ -347,7 +347,7 @@ BR_REGISTER(Distance, NegativeLogPlusOneDistance)
347 347 * \brief Returns \c true if the templates are identical, \c false otherwise.
348 348 * \author Josh Klontz \cite jklontz
349 349 */
350   -class IdenticalDistance : public Distance
  350 +class IdenticalDistance : public UntrainableDistance
351 351 {
352 352 Q_OBJECT
353 353  
... ... @@ -368,7 +368,7 @@ BR_REGISTER(Distance, IdenticalDistance)
368 368 * \brief Online distance metric to attenuate match scores across multiple frames
369 369 * \author Brendan klare \cite bklare
370 370 */
371   -class OnlineDistance : public Distance
  371 +class OnlineDistance : public UntrainableDistance
372 372 {
373 373 Q_OBJECT
374 374 Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false)
... ... @@ -395,7 +395,7 @@ BR_REGISTER(Distance, OnlineDistance)
395 395 * \brief Attenuation function based distance from attributes
396 396 * \author Scott Klum \cite sklum
397 397 */
398   -class AttributeDistance : public Distance
  398 +class AttributeDistance : public UntrainableDistance
399 399 {
400 400 Q_OBJECT
401 401 Q_PROPERTY(QString attribute READ get_attribute WRITE set_attribute RESET reset_attribute STORED false)
... ... @@ -421,7 +421,7 @@ BR_REGISTER(Distance, AttributeDistance)
421 421 * \brief Sum match scores across multiple distances
422 422 * \author Scott Klum \cite sklum
423 423 */
424   -class SumDistance : public Distance
  424 +class SumDistance : public UntrainableDistance
425 425 {
426 426 Q_OBJECT
427 427 Q_PROPERTY(QList<br::Distance*> distances READ get_distances WRITE set_distances RESET reset_distances)
... ...
openbr/plugins/eigen3.cpp
... ... @@ -657,7 +657,7 @@ BR_REGISTER(Transform, SparseLDATransform)
657 657 * \brief L1 distance computed using eigen.
658 658 * \author Josh Klontz \cite jklontz
659 659 */
660   -class L1Distance : public Distance
  660 +class L1Distance : public UntrainableDistance
661 661 {
662 662 Q_OBJECT
663 663  
... ... @@ -677,7 +677,7 @@ BR_REGISTER(Distance, L1Distance)
677 677 * \brief L2 distance computed using eigen.
678 678 * \author Josh Klontz \cite jklontz
679 679 */
680   -class L2Distance : public Distance
  680 +class L2Distance : public UntrainableDistance
681 681 {
682 682 Q_OBJECT
683 683  
... ...
openbr/plugins/keypoint.cpp
... ... @@ -109,7 +109,7 @@ BR_REGISTER(Transform, KeyPointDescriptorTransform)
109 109 * \brief Wraps OpenCV Key Point Matcher
110 110 * \author Josh Klontz \cite jklontz
111 111 */
112   -class KeyPointMatcherDistance : public Distance
  112 +class KeyPointMatcherDistance : public UntrainableDistance
113 113 {
114 114 Q_OBJECT
115 115 Q_PROPERTY(QString matcher READ get_matcher WRITE set_matcher RESET reset_matcher STORED false)
... ...
openbr/plugins/openbr_internal.h
... ... @@ -501,6 +501,18 @@ typedef QVector&lt;Neighbors&gt; Neighborhood;
501 501  
502 502 BR_EXPORT bool compareNeighbors(const Neighbor &a, const Neighbor &b);
503 503  
  504 +/*!
  505 + * \brief A br::Distance that does not require training data.
  506 + */
  507 +class BR_EXPORT UntrainableDistance : public Distance
  508 +{
  509 + Q_OBJECT
  510 +
  511 +private:
  512 + bool trainable() { return false; }
  513 + void train(const TemplateList &data) { (void) data; }
  514 +};
  515 +
504 516 }
505 517  
506 518 #endif // OPENBR_INTERNAL_H
... ...
openbr/plugins/pp5.cpp
... ... @@ -407,7 +407,7 @@ BR_REGISTER(Transform, PP5EnrollTransform)
407 407 * \author E. Taborsky \cite mmtaborsky
408 408 * \note PP5 distance is known to be asymmetric
409 409 */
410   -class PP5CompareDistance : public Distance
  410 +class PP5CompareDistance : public UntrainableDistance
411 411 , public PP5Context
412 412 {
413 413 Q_OBJECT
... ...
openbr/plugins/quantize.cpp
... ... @@ -251,7 +251,7 @@ QVector&lt;Mat&gt; ProductQuantizationLUTs;
251 251 * \brief Distance in a product quantized space \cite jegou11
252 252 * \author Josh Klontz \cite jklontz
253 253 */
254   -class ProductQuantizationDistance : public Distance
  254 +class ProductQuantizationDistance : public UntrainableDistance
255 255 {
256 256 Q_OBJECT
257 257 Q_PROPERTY(bool bayesian READ get_bayesian WRITE set_bayesian RESET reset_bayesian STORED false)
... ... @@ -291,7 +291,7 @@ BR_REGISTER(Distance, ProductQuantizationDistance)
291 291 * \brief Recurively computed distance in a product quantized space
292 292 * \author Josh Klontz \cite jklontz
293 293 */
294   -class RecursiveProductQuantizationDistance : public Distance
  294 +class RecursiveProductQuantizationDistance : public UntrainableDistance
295 295 {
296 296 Q_OBJECT
297 297 Q_PROPERTY(float t READ get_t WRITE set_t RESET reset_t STORED false)
... ...
openbr/plugins/sentence.cpp
... ... @@ -39,7 +39,7 @@ BR_REGISTER(Transform, SentenceTransform)
39 39 * \brief Distance between sentences
40 40 * \author Josh Klontz \cite jklontz
41 41 */
42   -class SentenceSimilarityDistance : public Distance
  42 +class SentenceSimilarityDistance : public UntrainableDistance
43 43 {
44 44 Q_OBJECT
45 45  
... ...
openbr/plugins/turk.cpp
... ... @@ -138,7 +138,7 @@ BR_REGISTER(Transform, TurkClassifierTransform)
138 138 * \brief Unmaps Turk HITs to be compared against query mats
139 139 * \author Scott Klum \cite sklum
140 140 */
141   -class TurkDistance : public Distance
  141 +class TurkDistance : public UntrainableDistance
142 142 {
143 143 Q_OBJECT
144 144 Q_PROPERTY(QString key READ get_key WRITE set_key RESET reset_key)
... ...
openbr/plugins/validate.cpp
... ... @@ -139,7 +139,7 @@ BR_REGISTER(Transform, CrossValidateTransform)
139 139 * \brief Cross validate a distance metric.
140 140 * \author Josh Klontz \cite jklontz
141 141 */
142   -class CrossValidateDistance : public Distance
  142 +class CrossValidateDistance : public UntrainableDistance
143 143 {
144 144 Q_OBJECT
145 145  
... ... @@ -159,7 +159,7 @@ BR_REGISTER(Distance, CrossValidateDistance)
159 159 * \brief Checks target metadata against filters.
160 160 * \author Josh Klontz \cite jklontz
161 161 */
162   -class FilterDistance : public Distance
  162 +class FilterDistance : public UntrainableDistance
163 163 {
164 164 Q_OBJECT
165 165  
... ... @@ -190,7 +190,7 @@ BR_REGISTER(Distance, FilterDistance)
190 190 * \brief Checks target metadata against query metadata.
191 191 * \author Scott Klum \cite sklum
192 192 */
193   -class MetadataDistance : public Distance
  193 +class MetadataDistance : public UntrainableDistance
194 194 {
195 195 Q_OBJECT
196 196  
... ... @@ -241,7 +241,7 @@ BR_REGISTER(Distance, MetadataDistance)
241 241 * \brief Sets distance to -FLOAT_MAX if a target template has/doesn't have a key.
242 242 * \author Scott Klum \cite sklum
243 243 */
244   -class RejectDistance : public Distance
  244 +class RejectDistance : public UntrainableDistance
245 245 {
246 246 Q_OBJECT
247 247  
... ...