Commit 57118ef4956cd0b645492d95a99bf40537a46d97
Merge pull request #247 from biometrics/eval
Eval matches fix
Showing
2 changed files
with
15 additions
and
12 deletions
openbr/core/eval.cpp
| @@ -100,10 +100,10 @@ static cv::Mat constructMatchingMask(const cv::Mat &scores, const FileList &targ | @@ -100,10 +100,10 @@ static cv::Mat constructMatchingMask(const cv::Mat &scores, const FileList &targ | ||
| 100 | 100 | ||
| 101 | float Evaluate(const cv::Mat &scores, const FileList &target, const FileList &query, const QString &csv, int partition) | 101 | float Evaluate(const cv::Mat &scores, const FileList &target, const FileList &query, const QString &csv, int partition) |
| 102 | { | 102 | { |
| 103 | - return Evaluate(scores, constructMatchingMask(scores, target, query, partition), target, query, csv, 10); | 103 | + return Evaluate(scores, constructMatchingMask(scores, target, query, partition), csv, QString(), QString(), 0); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | -float Evaluate(const QString &simmat, const QString &mask, const QString &csv, int matches) | 106 | +float Evaluate(const QString &simmat, const QString &mask, const QString &csv, unsigned int matches) |
| 107 | { | 107 | { |
| 108 | qDebug("Evaluating %s%s%s", | 108 | qDebug("Evaluating %s%s%s", |
| 109 | qPrintable(simmat), | 109 | qPrintable(simmat), |
| @@ -137,11 +137,12 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv, i | @@ -137,11 +137,12 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv, i | ||
| 137 | truth = format->read(); | 137 | truth = format->read(); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | - return Evaluate(scores, truth, TemplateList::fromGallery(target).files(), TemplateList::fromGallery(query).files(), csv, matches); | 140 | + return Evaluate(scores, truth, csv, target, query, matches); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | -float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const FileList &query, const QString &csv, int matches) | 143 | +float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv, const QString &target, const QString &query, unsigned int matches) |
| 144 | { | 144 | { |
| 145 | + if (target.isEmpty() || query.isEmpty()) matches = 0; | ||
| 145 | if (simmat.size() != mask.size()) | 146 | if (simmat.size() != mask.size()) |
| 146 | qFatal("Similarity matrix (%ix%i) differs in size from mask matrix (%ix%i).", | 147 | qFatal("Similarity matrix (%ix%i) differs in size from mask matrix (%ix%i).", |
| 147 | simmat.rows, simmat.cols, mask.rows, mask.cols); | 148 | simmat.rows, simmat.cols, mask.rows, mask.cols); |
| @@ -172,7 +173,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const | @@ -172,7 +173,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const | ||
| 172 | if (comparison.genuine) { | 173 | if (comparison.genuine) { |
| 173 | genuineCount++; | 174 | genuineCount++; |
| 174 | if (matches != 0){ | 175 | if (matches != 0){ |
| 175 | - if (botGenuines.size() < matches) { | 176 | + if (botGenuines.size() < (int)matches) { |
| 176 | botGenuines.append(comparison); | 177 | botGenuines.append(comparison); |
| 177 | std::sort(botGenuines.begin(), botGenuines.end()); | 178 | std::sort(botGenuines.begin(), botGenuines.end()); |
| 178 | } else if (comparison.score < botGenuines.first().score) { | 179 | } else if (comparison.score < botGenuines.first().score) { |
| @@ -184,7 +185,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const | @@ -184,7 +185,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const | ||
| 184 | } else { | 185 | } else { |
| 185 | impostorCount++; | 186 | impostorCount++; |
| 186 | if (matches != 0) { | 187 | if (matches != 0) { |
| 187 | - if (topImpostors.size() < matches) { | 188 | + if (topImpostors.size() < (int)matches) { |
| 188 | topImpostors.append(comparison); | 189 | topImpostors.append(comparison); |
| 189 | std::sort(topImpostors.begin(), topImpostors.end()); | 190 | std::sort(topImpostors.begin(), topImpostors.end()); |
| 190 | } else if (topImpostors.last().score < comparison.score) { | 191 | } else if (topImpostors.last().score < comparison.score) { |
| @@ -265,14 +266,16 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const | @@ -265,14 +266,16 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const | ||
| 265 | 266 | ||
| 266 | QString filePath = Globals->path; | 267 | QString filePath = Globals->path; |
| 267 | if (matches != 0) { | 268 | if (matches != 0) { |
| 269 | + const FileList targetFiles = TemplateList::fromGallery(target).files(); | ||
| 270 | + const FileList queryFiles = TemplateList::fromGallery(query).files(); | ||
| 268 | for (int i=0; i<topImpostors.size(); i++) { | 271 | for (int i=0; i<topImpostors.size(); i++) { |
| 269 | - lines.append("TI,"+QString::number(topImpostors[i].score)+","+target[topImpostors[i].target].get<QString>("Label")+":" | ||
| 270 | - +filePath+"/"+target[topImpostors[i].target].name+":"+query[topImpostors[i].query].get<QString>("Label")+":"+filePath+"/"+query[topImpostors[i].query].name); | 272 | + lines.append("TI,"+QString::number(topImpostors[i].score)+","+targetFiles[topImpostors[i].target].get<QString>("Label")+":" |
| 273 | + +filePath+"/"+targetFiles[topImpostors[i].target].name+":"+queryFiles[topImpostors[i].query].get<QString>("Label")+":"+filePath+"/"+queryFiles[topImpostors[i].query].name); | ||
| 271 | } | 274 | } |
| 272 | std::reverse(botGenuines.begin(), botGenuines.end()); | 275 | std::reverse(botGenuines.begin(), botGenuines.end()); |
| 273 | for (int i=0; i<botGenuines.size(); i++) { | 276 | for (int i=0; i<botGenuines.size(); i++) { |
| 274 | - lines.append("BG,"+QString::number(botGenuines[i].score)+","+target[botGenuines[i].target].get<QString>("Label")+":" | ||
| 275 | - +filePath+"/"+target[botGenuines[i].target].name+":"+query[botGenuines[i].query].get<QString>("Label")+":"+filePath+"/"+query[botGenuines[i].query].name); | 277 | + lines.append("BG,"+QString::number(botGenuines[i].score)+","+targetFiles[botGenuines[i].target].get<QString>("Label")+":" |
| 278 | + +filePath+"/"+targetFiles[botGenuines[i].target].name+":"+queryFiles[botGenuines[i].query].get<QString>("Label")+":"+filePath+"/"+queryFiles[botGenuines[i].query].name); | ||
| 276 | } | 279 | } |
| 277 | } | 280 | } |
| 278 | 281 |
openbr/core/eval.h
| @@ -23,9 +23,9 @@ | @@ -23,9 +23,9 @@ | ||
| 23 | 23 | ||
| 24 | namespace br | 24 | namespace br |
| 25 | { | 25 | { |
| 26 | - float Evaluate(const QString &simmat, const QString &mask = "", const QString &csv = "", int matches = 0); // Returns TAR @ FAR = 0.001 | 26 | + float Evaluate(const QString &simmat, const QString &mask = "", const QString &csv = "", unsigned int matches = 0); // Returns TAR @ FAR = 0.001 |
| 27 | float Evaluate(const cv::Mat &scores, const FileList &target, const FileList &query, const QString &csv = "", int parition = 0); | 27 | float Evaluate(const cv::Mat &scores, const FileList &target, const FileList &query, const QString &csv = "", int parition = 0); |
| 28 | - float Evaluate(const cv::Mat &scores, const cv::Mat &masks, const FileList &target, const FileList &query, const QString &csv = "", int matches = 0); | 28 | + float Evaluate(const cv::Mat &scores, const cv::Mat &masks, const QString &csv = "", const QString &target = "", const QString &query = "", unsigned int matches = 0); |
| 29 | float InplaceEval(const QString & simmat, const QString & target, const QString & query, const QString & csv = ""); | 29 | float InplaceEval(const QString & simmat, const QString & target, const QString & query, const QString & csv = ""); |
| 30 | 30 | ||
| 31 | void EvalClassification(const QString &predictedGallery, const QString &truthGallery, QString predictedProperty = "", QString truthProperty = ""); | 31 | void EvalClassification(const QString &predictedGallery, const QString &truthGallery, QString predictedProperty = "", QString truthProperty = ""); |