Commit b531dc36ccf4a45e37ecfd92fef3c430ed279af7

Authored by Josh Klontz
1 parent 3ed08edc

introduced br::Distance::trainable() and UntrainableDistance

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