Commit 792edb3308e835670f6b4d9fd670c9186e6bbaa1
1 parent
0a55e14f
changed parameter to number of matches desired. Added plotting for .png.
Showing
5 changed files
with
40 additions
and
33 deletions
openbr/core/eval.cpp
| ... | ... | @@ -100,10 +100,10 @@ static cv::Mat constructMatchingMask(const cv::Mat &scores, const FileList &targ |
| 100 | 100 | |
| 101 | 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, true); | |
| 103 | + return Evaluate(scores, constructMatchingMask(scores, target, query, partition), target, query, csv, 10); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | -float Evaluate(const QString &simmat, const QString &mask, const QString &csv, bool matches) | |
| 106 | +float Evaluate(const QString &simmat, const QString &mask, const QString &csv, int matches) | |
| 107 | 107 | { |
| 108 | 108 | qDebug("Evaluating %s%s%s", |
| 109 | 109 | qPrintable(simmat), |
| ... | ... | @@ -140,7 +140,7 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv, b |
| 140 | 140 | return Evaluate(scores, truth, TemplateList::fromGallery(target).files(), TemplateList::fromGallery(query).files(), csv, matches); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | -float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const FileList &query, const QString &csv, bool matches) | |
| 143 | +float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const FileList &query, const QString &csv, int matches) | |
| 144 | 144 | { |
| 145 | 145 | if (simmat.size() != mask.size()) |
| 146 | 146 | qFatal("Similarity matrix (%ix%i) differs in size from mask matrix (%ix%i).", |
| ... | ... | @@ -155,8 +155,8 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const |
| 155 | 155 | float result = -1; |
| 156 | 156 | |
| 157 | 157 | // Lists of top impostors and worst genuine |
| 158 | - QList<Comparison> topImpostors; topImpostors.reserve(10); | |
| 159 | - QList<Comparison> botGenuines; botGenuines.reserve(10); | |
| 158 | + QList<Comparison> topImpostors; topImpostors.reserve(matches); | |
| 159 | + QList<Comparison> botGenuines; botGenuines.reserve(matches); | |
| 160 | 160 | |
| 161 | 161 | // Make comparisons |
| 162 | 162 | QList<Comparison> comparisons; comparisons.reserve(simmat.rows*simmat.cols); |
| ... | ... | @@ -171,23 +171,27 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const |
| 171 | 171 | comparisons.append(comparison); |
| 172 | 172 | if (comparison.genuine) { |
| 173 | 173 | genuineCount++; |
| 174 | - if (botGenuines.size() < 10) { | |
| 175 | - botGenuines.append(comparison); | |
| 176 | - std::sort(botGenuines.begin(), botGenuines.end()); | |
| 177 | - } else if (comparison.score < botGenuines.first().score) { | |
| 178 | - botGenuines.removeFirst(); | |
| 179 | - botGenuines.append(comparison); | |
| 180 | - std::sort(botGenuines.begin(), botGenuines.end()); | |
| 174 | + if (matches != 0){ | |
| 175 | + if (botGenuines.size() < matches) { | |
| 176 | + botGenuines.append(comparison); | |
| 177 | + std::sort(botGenuines.begin(), botGenuines.end()); | |
| 178 | + } else if (comparison.score < botGenuines.first().score) { | |
| 179 | + botGenuines.removeFirst(); | |
| 180 | + botGenuines.append(comparison); | |
| 181 | + std::sort(botGenuines.begin(), botGenuines.end()); | |
| 182 | + } | |
| 181 | 183 | } |
| 182 | 184 | } else { |
| 183 | 185 | impostorCount++; |
| 184 | - if (topImpostors.size() < 10) { | |
| 185 | - topImpostors.append(comparison); | |
| 186 | - std::sort(topImpostors.begin(), topImpostors.end()); | |
| 187 | - } else if (topImpostors.last().score < comparison.score) { | |
| 188 | - topImpostors.removeLast(); | |
| 189 | - topImpostors.append(comparison); | |
| 190 | - std::sort(topImpostors.begin(), topImpostors.end()); | |
| 186 | + if (matches != 0) { | |
| 187 | + if (topImpostors.size() < matches) { | |
| 188 | + topImpostors.append(comparison); | |
| 189 | + std::sort(topImpostors.begin(), topImpostors.end()); | |
| 190 | + } else if (topImpostors.last().score < comparison.score) { | |
| 191 | + topImpostors.removeLast(); | |
| 192 | + topImpostors.append(comparison); | |
| 193 | + std::sort(topImpostors.begin(), topImpostors.end()); | |
| 194 | + } | |
| 191 | 195 | } |
| 192 | 196 | |
| 193 | 197 | } |
| ... | ... | @@ -260,11 +264,12 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const |
| 260 | 264 | lines.append("Metadata,"+QString::number(simmat.cols*simmat.rows-(genuineCount+impostorCount))+",Ignored"); |
| 261 | 265 | |
| 262 | 266 | QString filePath = Globals->path; |
| 263 | - if (matches) { | |
| 267 | + if (matches != 0) { | |
| 264 | 268 | for (int i=0; i<topImpostors.size(); i++) { |
| 265 | 269 | lines.append("TI,"+QString::number(topImpostors[i].score)+","+target[topImpostors[i].target].get<QString>("Label")+":" |
| 266 | 270 | +filePath+"/"+target[topImpostors[i].target].name+":"+query[topImpostors[i].query].get<QString>("Label")+":"+filePath+"/"+query[topImpostors[i].query].name); |
| 267 | 271 | } |
| 272 | + std::reverse(botGenuines.begin(), botGenuines.end()); | |
| 268 | 273 | for (int i=0; i<botGenuines.size(); i++) { |
| 269 | 274 | lines.append("BG,"+QString::number(botGenuines[i].score)+","+target[botGenuines[i].target].get<QString>("Label")+":" |
| 270 | 275 | +filePath+"/"+target[botGenuines[i].target].name+":"+query[botGenuines[i].query].get<QString>("Label")+":"+filePath+"/"+query[botGenuines[i].query].name); | ... | ... |
openbr/core/eval.h
| ... | ... | @@ -23,9 +23,9 @@ |
| 23 | 23 | |
| 24 | 24 | namespace br |
| 25 | 25 | { |
| 26 | - float Evaluate(const QString &simmat, const QString &mask = "", const QString &csv = "", bool matches = false); // Returns TAR @ FAR = 0.001 | |
| 26 | + float Evaluate(const QString &simmat, const QString &mask = "", const QString &csv = "", int matches = 0); // Returns TAR @ FAR = 0.001 | |
| 27 | 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 = "", bool matches = false); | |
| 28 | + float Evaluate(const cv::Mat &scores, const cv::Mat &masks, const FileList &target, const FileList &query, const QString &csv = "", int matches = 0); | |
| 29 | 29 | float InplaceEval(const QString & simmat, const QString & target, const QString & query, const QString & csv = ""); |
| 30 | 30 | |
| 31 | 31 | void EvalClassification(const QString &predictedGallery, const QString &truthGallery, QString predictedProperty = "", QString truthProperty = ""); | ... | ... |
openbr/core/plot.cpp
| ... | ... | @@ -328,16 +328,18 @@ bool Plot(const QStringList &files, const File &destination, bool show) |
| 328 | 328 | QString("\t\t# Set up the page\n\t\tgrid.newpage()\n\t\tpushViewport(viewport(layout = grid.layout(plotRows, plotCols)))\n\t\tvplayout <- function(x, y)\n\t\t\tviewport(layout.pos.row = x, layout.pos.col = y)\n\n") + |
| 329 | 329 | QString("\t\t# Make each plot, in the correct location\n\t\tfor (i in 1:numPlots) {\n\t\t\tcurRow = ceiling(i/plotCols)\n\t\t\tcurCol = (i-1) %% plotCols + 1\n\t\t\tprint(plots[[i]], vp = vplayout(curRow, curCol))\n\t\t}\n\t}\n\n"))); |
| 330 | 330 | |
| 331 | - p.file.write(qPrintable(QString("\t# Print top impostor matches\n\tfor (i in 1:nrow(TI)) {\n\t\tscore <- TI[i,1]\n\t\tfiles <- TI[i,2]\n\t\talg <- TI[i,3]\n\t\tfiles <- unlist(strsplit(files, \"[:]\"))\n\n\t\t") + | |
| 332 | - QString("name1 <- files[1]\n\t\timg1 <- readJPEG(files[2])\n\t\tname2 <- files[3]\n\t\timg2 <- readJPEG(files[4])\n\n\t\tg1 <- rasterGrob(img1, interpolate=TRUE)\n\t\tg2 <- rasterGrob(img2, interpolate=TRUE)\n\n\t\t") + | |
| 333 | - QString("plot1 <- qplot(1:10, 1:10, geom=\"blank\") + annotation_custom(g1, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=alg) + ylab(files[2]) + xlab(name1)\n\t\t") + | |
| 334 | - QString("plot2 <- qplot(1:10, 1:10, geom=\"blank\") + annotation_custom(g2, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=paste(\"Impostor score =\", score)) + ylab(files[4]) + xlab(name2)\n\n\t\t") + | |
| 331 | + p.file.write(qPrintable(QString("\t# Print top impostor matches\n\tfor (i in 1:nrow(TI)) {\n\t\tscore <- TI[i,1]\n\t\tfiles <- TI[i,2]\n\t\talg <- TI[i,3]\n\t\tfiles <- unlist(strsplit(files, \"[:]\"))\n\n\t\text1 <- unlist(strsplit(files[2], \"[.]\"))[2]\n\t\text2 <- unlist(strsplit(files[4], \"[.]\"))[2]\n\t\t") + | |
| 332 | + QString("if (ext1 == \"jpg\" || ext1 == \"JPEG\" || ext1 == \"jpeg\" || ext1 == \"JPG\") {\n\t\t\timg1 <- readJPEG(files[2])\n\t\t} else if (ext1 == \"PNG\" || ext1 == \"png\") {\n\t\t\timg1 <- readPNG(files[2])\n\t\t} else {\n\t\t\tnext\n\t\t}\n\t\tif (ext2 == \"jpg\" || ext2 == \"JPEG\" || ext2 == \"jpeg\" || ext2 == \"JPG\") {\n\t\t\timg2 <- readJPEG(files[4])\n\t\t} else if (ext2 == \"PNG\" || ext2 == \"png\") {\n\t\t\timg2 <- readPNG(files[4])\n\t\t} else {\n\t\t\tnext\n\t\t}") + | |
| 333 | + QString("\n\t\tname1 <- files[1]\n\t\tname2 <- files[3]\n\n\t\tg1 <- rasterGrob(img1, interpolate=TRUE)\n\t\tg2 <- rasterGrob(img2, interpolate=TRUE)\n\n\t\t") + | |
| 334 | + QString("plot1 <- qplot(1:10, 1:10, geom=\"blank\") + annotation_custom(g1, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=alg) + ylab(unlist(strsplit(files[2], \"[/]\"))[length(unlist(strsplit(files[2], \"[/]\")))]) + xlab(name1)\n\t\t") + | |
| 335 | + QString("plot2 <- qplot(1:10, 1:10, geom=\"blank\") + annotation_custom(g2, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=paste(\"Impostor score =\", score)) + ylab(unlist(strsplit(files[4], \"[/]\"))[length(unlist(strsplit(files[4], \"[/]\")))]) + xlab(name2)\n\n\t\t") + | |
| 335 | 336 | QString("multiplot(plot1, plot2, cols=2)\n\t}"))); |
| 336 | 337 | |
| 337 | - p.file.write(qPrintable(QString("\n\n\t# Print worst genuine matches\n\tfor (i in 1:nrow(BG)) {\n\t\tscore <- BG[i,1]\n\t\tfiles <- BG[i,2]\n\t\talg <- BG[i,3]\n\t\tfiles <- unlist(strsplit(files, \"[:]\"))\n\n\t\t") + | |
| 338 | - QString("name1 <- files[1]\n\t\timg1 <- readJPEG(files[2])\n\t\tname2 <- files[3]\n\t\timg2 <- readJPEG(files[4])\n\n\t\tg1 <- rasterGrob(img1, interpolate=TRUE)\n\t\tg2 <- rasterGrob(img2, interpolate=TRUE)\n\n\t\t") + | |
| 339 | - QString("plot1 <- qplot(1:10, 1:10, geom=\"blank\") + annotation_custom(g1, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=alg) + ylab(files[2]) + xlab(name1)\n\t\t") + | |
| 340 | - QString("plot2 <- qplot(1:10, 1:10, geom=\"blank\") + annotation_custom(g2, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=paste(\"Genuine score =\", score)) + ylab(files[4]) + xlab(name2)\n\n\t\t") + | |
| 338 | + p.file.write(qPrintable(QString("\n\n\t# Print worst genuine matches\n\tfor (i in 1:nrow(BG)) {\n\t\tscore <- BG[i,1]\n\t\tfiles <- BG[i,2]\n\t\talg <- BG[i,3]\n\t\tfiles <- unlist(strsplit(files, \"[:]\"))\n\n\t\text1 <- unlist(strsplit(files[2], \"[.]\"))[2]\n\t\text2 <- unlist(strsplit(files[4], \"[.]\"))[2]\n\t\t") + | |
| 339 | + QString("if (ext1 == \"jpg\" || ext1 == \"JPEG\" || ext1 == \"jpeg\" || ext1 == \"JPG\") {\n\t\t\timg1 <- readJPEG(files[2])\n\t\t} else if (ext1 == \"PNG\" || ext1 == \"png\") {\n\t\t\timg1 <- readPNG(files[2])\n\t\t} else {\n\t\t\tnext\n\t\t}\n\t\tif (ext2 == \"jpg\" || ext2 == \"JPEG\" || ext2 == \"jpeg\" || ext2 == \"JPG\") {\n\t\t\timg2 <- readJPEG(files[4])\n\t\t} else if (ext2 == \"PNG\" || ext2 == \"png\") {\n\t\t\timg2 <- readPNG(files[4])\n\t\t} else {\n\t\t\tnext\n\t\t}") + | |
| 340 | + QString("\n\t\tname1 <- files[1]\n\t\tname2 <- files[3]\n\n\t\tg1 <- rasterGrob(img1, interpolate=TRUE)\n\t\tg2 <- rasterGrob(img2, interpolate=TRUE)\n\n\t\t") + | |
| 341 | + QString("plot1 <- qplot(1:10, 1:10, geom=\"blank\") + annotation_custom(g1, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=alg) + ylab(unlist(strsplit(files[2], \"[/]\"))[length(unlist(strsplit(files[2], \"[/]\")))]) + xlab(name1)\n\t\t") + | |
| 342 | + QString("plot2 <- qplot(1:10, 1:10, geom=\"blank\") + annotation_custom(g2, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme(axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(), axis.ticks=element_blank(), panel.background=element_blank()) + labs(title=paste(\"Genuine score =\", score)) + ylab(unlist(strsplit(files[4], \"[/]\"))[length(unlist(strsplit(files[4], \"[/]\")))]) + xlab(name2)\n\n\t\t") + | |
| 341 | 343 | QString("multiplot(plot1, plot2, cols=2)\n\t}\n}\n\n"))); |
| 342 | 344 | |
| 343 | 345 | return p.finalize(show); | ... | ... |
openbr/openbr.cpp
| ... | ... | @@ -104,7 +104,7 @@ void br_project(const char *input, const char *gallery) |
| 104 | 104 | Project(File(input), File(gallery)); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | -float br_eval(const char *simmat, const char *mask, const char *csv, bool matches) | |
| 107 | +float br_eval(const char *simmat, const char *mask, const char *csv, int matches) | |
| 108 | 108 | { |
| 109 | 109 | return Evaluate(simmat, mask, csv, matches); |
| 110 | 110 | } | ... | ... |
openbr/openbr.h
| ... | ... | @@ -154,11 +154,11 @@ BR_EXPORT void br_project(const char *input, const char *output); |
| 154 | 154 | * \param simmat The \ref simmat to use. |
| 155 | 155 | * \param mask The \ref mask to use. |
| 156 | 156 | * \param csv Optional \c .csv file to contain performance metrics. |
| 157 | - * \param matches Optional bool flag to output top impostor matches and bottom genuine matches. | |
| 157 | + * \param matches Optional integer number of top impostor matches and bottom genuine matches to output defualts to 0. | |
| 158 | 158 | * \return True accept rate at a false accept rate of one in one thousand. |
| 159 | 159 | * \see br_plot |
| 160 | 160 | */ |
| 161 | -BR_EXPORT float br_eval(const char *simmat, const char *mask, const char *csv = "", bool matches = false); | |
| 161 | +BR_EXPORT float br_eval(const char *simmat, const char *mask, const char *csv = "", int matches = 0); | |
| 162 | 162 | |
| 163 | 163 | /*! |
| 164 | 164 | * \brief Creates a \c .csv file containing performance metrics from evaluating the similarity matrix using galleries containing ground truth labels | ... | ... |