Commit b2f41014e020a5c47b96f04a0f822246fb1a5a1e

Authored by Josh Klontz
1 parent 8a3eafe9

generalized evalDetection to handle differing keys

Showing 1 changed file with 23 additions and 10 deletions
openbr/core/eval.cpp
@@ -373,6 +373,8 @@ static QStringList computeDetectionResults(const QList<ResolvedDetection> &detec @@ -373,6 +373,8 @@ static QStringList computeDetectionResults(const QList<ResolvedDetection> &detec
373 } 373 }
374 374
375 const int keep = qMin(points.size(), Max_Points); 375 const int keep = qMin(points.size(), Max_Points);
  376 + if (keep < 2) qFatal("Insufficient points.");
  377 +
376 QStringList lines; lines.reserve(keep); 378 QStringList lines; lines.reserve(keep);
377 for (int i=0; i<keep; i++) { 379 for (int i=0; i<keep; i++) {
378 const DetectionOperatingPoint &point = points[double(i) / double(keep-1) * double(points.size()-1)]; 380 const DetectionOperatingPoint &point = points[double(i) / double(keep-1) * double(points.size()-1)];
@@ -382,6 +384,15 @@ static QStringList computeDetectionResults(const QList&lt;ResolvedDetection&gt; &amp;detec @@ -382,6 +384,15 @@ static QStringList computeDetectionResults(const QList&lt;ResolvedDetection&gt; &amp;detec
382 return lines; 384 return lines;
383 } 385 }
384 386
  387 +QString getDetectKey(const TemplateList &templates)
  388 +{
  389 + const File &f = templates.first().file;
  390 + foreach (const QString &key, f.localKeys())
  391 + if (!f.get<QRectF>(key, QRectF()).isNull())
  392 + return key;
  393 + return "";
  394 +}
  395 +
385 float EvalDetection(const QString &predictedInput, const QString &truthInput, const QString &csv) 396 float EvalDetection(const QString &predictedInput, const QString &truthInput, const QString &csv)
386 { 397 {
387 qDebug("Evaluating detection of %s against %s", qPrintable(predictedInput), qPrintable(truthInput)); 398 qDebug("Evaluating detection of %s against %s", qPrintable(predictedInput), qPrintable(truthInput));
@@ -389,20 +400,22 @@ float EvalDetection(const QString &amp;predictedInput, const QString &amp;truthInput, co @@ -389,20 +400,22 @@ float EvalDetection(const QString &amp;predictedInput, const QString &amp;truthInput, co
389 const TemplateList truth(TemplateList::fromGallery(truthInput)); 400 const TemplateList truth(TemplateList::fromGallery(truthInput));
390 401
391 // Figure out which metadata field contains a bounding box 402 // Figure out which metadata field contains a bounding box
392 - QString detectKey;  
393 - foreach (const QString &key, truth.first().file.localKeys())  
394 - if (!truth.first().file.get<QRectF>(key, QRectF()).isNull()) {  
395 - detectKey = key;  
396 - break;  
397 - }  
398 - if (detectKey.isNull()) qFatal("No suitable metadata key found.");  
399 - else qDebug("Using metadata key: %s", qPrintable(detectKey)); 403 + QString truthDetectKey = getDetectKey(truth);
  404 + if (truthDetectKey.isEmpty()) qFatal("No suitable ground truth metadata key found.");
  405 + QString predictedDetectKey = truthDetectKey;
  406 + if (predicted.first().file.get<QRectF>(predictedDetectKey, QRectF()).isNull())
  407 + predictedDetectKey = getDetectKey(predicted);
  408 + if (predictedDetectKey.isEmpty()) qFatal("No suitable predicted metadata key found.");
  409 +
  410 + qDebug("Using metadata key: %s%s",
  411 + qPrintable(predictedDetectKey),
  412 + qPrintable(predictedDetectKey == truthDetectKey ? QString() : "/"+truthDetectKey));
400 413
401 QMap<QString, Detections> allDetections; // Organized by file, QMap used to preserve order 414 QMap<QString, Detections> allDetections; // Organized by file, QMap used to preserve order
402 foreach (const Template &t, predicted) 415 foreach (const Template &t, predicted)
403 - allDetections[t.file.baseName()].predicted.append(Detection(t.file.get<QRectF>(detectKey), t.file.get<float>("Confidence", -1))); 416 + allDetections[t.file.baseName()].predicted.append(Detection(t.file.get<QRectF>(predictedDetectKey), t.file.get<float>("Confidence", -1)));
404 foreach (const Template &t, truth) 417 foreach (const Template &t, truth)
405 - allDetections[t.file.baseName()].truth.append(Detection(t.file.get<QRectF>(detectKey))); 418 + allDetections[t.file.baseName()].truth.append(Detection(t.file.get<QRectF>(truthDetectKey)));
406 419
407 QList<ResolvedDetection> resolvedDetections, falseNegativeDetections; 420 QList<ResolvedDetection> resolvedDetections, falseNegativeDetections;
408 foreach (Detections detections, allDetections.values()) { 421 foreach (Detections detections, allDetections.values()) {