Commit bd3d5b0d0bea367e08cc8193597923f29de17f41

Authored by Josh Klontz
1 parent 9756e99f

wrote more of evalDetection

Showing 1 changed file with 33 additions and 4 deletions
openbr/core/classify.cpp
@@ -34,7 +34,6 @@ struct Counter @@ -34,7 +34,6 @@ struct Counter
34 void br::EvalClassification(const QString &predictedInput, const QString &truthInput) 34 void br::EvalClassification(const QString &predictedInput, const QString &truthInput)
35 { 35 {
36 qDebug("Evaluating classification of %s against %s", qPrintable(predictedInput), qPrintable(truthInput)); 36 qDebug("Evaluating classification of %s against %s", qPrintable(predictedInput), qPrintable(truthInput));
37 -  
38 TemplateList predicted(TemplateList::fromGallery(predictedInput)); 37 TemplateList predicted(TemplateList::fromGallery(predictedInput));
39 TemplateList truth(TemplateList::fromGallery(truthInput)); 38 TemplateList truth(TemplateList::fromGallery(truthInput));
40 if (predicted.size() != truth.size()) qFatal("Input size mismatch."); 39 if (predicted.size() != truth.size()) qFatal("Input size mismatch.");
@@ -90,16 +89,46 @@ void br::EvalClassification(const QString &predictedInput, const QString &truthI @@ -90,16 +89,46 @@ void br::EvalClassification(const QString &predictedInput, const QString &truthI
90 qDebug("Overall Accuracy = %f", (float)tpc / (float)(tpc + fnc)); 89 qDebug("Overall Accuracy = %f", (float)tpc / (float)(tpc + fnc));
91 } 90 }
92 91
  92 +struct Detection
  93 +{
  94 + QRectF boundingBox;
  95 + float confidence;
  96 + Detection() {}
  97 + Detection(const QRectF &boundingBox_, float confidence_ = -1)
  98 + : boundingBox(boundingBox_), confidence(confidence_) {}
  99 +};
  100 +
  101 +struct Detections
  102 +{
  103 + QList<Detection> predicted, truth;
  104 +};
  105 +
93 void br::EvalDetection(const QString &predictedInput, const QString &truthInput) 106 void br::EvalDetection(const QString &predictedInput, const QString &truthInput)
94 { 107 {
95 - (void) predictedInput;  
96 - (void) truthInput; 108 + qDebug("Evaluating detection of %s against %s", qPrintable(predictedInput), qPrintable(truthInput));
  109 + const TemplateList predicted(TemplateList::fromGallery(predictedInput));
  110 + const TemplateList truth(TemplateList::fromGallery(truthInput));
  111 +
  112 + // Figure out which metadata field contains a bounding box
  113 + QString detectKey;
  114 + foreach (const QString &key, truth.first().file.localKeys())
  115 + if (!truth.first().file.get<QRectF>(key, QRectF()).isNull()) {
  116 + detectKey = key;
  117 + break;
  118 + }
  119 + if (detectKey.isNull()) qFatal("No suitable metadata key found.");
  120 + else qDebug("Using metadata key: %s", qPrintable(detectKey));
  121 +
  122 + QHash<QString, Detections> allDetections; // Organized by file
  123 + foreach (const Template &t, predicted)
  124 + allDetections[t.file.baseName()].predicted.append(Detection(t.file.get<QRectF>(detectKey), t.file.get<float>("Confidence", -1)));
  125 + foreach (const Template &t, truth)
  126 + allDetections[t.file.baseName()].truth.append(Detection(t.file.get<QRectF>(detectKey)));
97 } 127 }
98 128
99 void br::EvalRegression(const QString &predictedInput, const QString &truthInput) 129 void br::EvalRegression(const QString &predictedInput, const QString &truthInput)
100 { 130 {
101 qDebug("Evaluating regression of %s against %s", qPrintable(predictedInput), qPrintable(truthInput)); 131 qDebug("Evaluating regression of %s against %s", qPrintable(predictedInput), qPrintable(truthInput));
102 -  
103 const TemplateList predicted(TemplateList::fromGallery(predictedInput)); 132 const TemplateList predicted(TemplateList::fromGallery(predictedInput));
104 const TemplateList truth(TemplateList::fromGallery(truthInput)); 133 const TemplateList truth(TemplateList::fromGallery(truthInput));
105 if (predicted.size() != truth.size()) qFatal("Input size mismatch."); 134 if (predicted.size() != truth.size()) qFatal("Input size mismatch.");