From 792edb3308e835670f6b4d9fd670c9186e6bbaa1 Mon Sep 17 00:00:00 2001 From: bhklein Date: Fri, 29 Aug 2014 16:46:52 -0400 Subject: [PATCH] changed parameter to number of matches desired. Added plotting for .png. --- openbr/core/eval.cpp | 45 +++++++++++++++++++++++++-------------------- openbr/core/eval.h | 4 ++-- openbr/core/plot.cpp | 18 ++++++++++-------- openbr/openbr.cpp | 2 +- openbr/openbr.h | 4 ++-- 5 files changed, 40 insertions(+), 33 deletions(-) diff --git a/openbr/core/eval.cpp b/openbr/core/eval.cpp index 8ebcd48..9b37e5d 100755 --- a/openbr/core/eval.cpp +++ b/openbr/core/eval.cpp @@ -100,10 +100,10 @@ static cv::Mat constructMatchingMask(const cv::Mat &scores, const FileList &targ float Evaluate(const cv::Mat &scores, const FileList &target, const FileList &query, const QString &csv, int partition) { - return Evaluate(scores, constructMatchingMask(scores, target, query, partition), target, query, csv, true); + return Evaluate(scores, constructMatchingMask(scores, target, query, partition), target, query, csv, 10); } -float Evaluate(const QString &simmat, const QString &mask, const QString &csv, bool matches) +float Evaluate(const QString &simmat, const QString &mask, const QString &csv, int matches) { qDebug("Evaluating %s%s%s", qPrintable(simmat), @@ -140,7 +140,7 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv, b return Evaluate(scores, truth, TemplateList::fromGallery(target).files(), TemplateList::fromGallery(query).files(), csv, matches); } -float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const FileList &query, const QString &csv, bool matches) +float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const FileList &query, const QString &csv, int matches) { if (simmat.size() != mask.size()) 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 float result = -1; // Lists of top impostors and worst genuine - QList topImpostors; topImpostors.reserve(10); - QList botGenuines; botGenuines.reserve(10); + QList topImpostors; topImpostors.reserve(matches); + QList botGenuines; botGenuines.reserve(matches); // Make comparisons QList comparisons; comparisons.reserve(simmat.rows*simmat.cols); @@ -171,23 +171,27 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const comparisons.append(comparison); if (comparison.genuine) { genuineCount++; - if (botGenuines.size() < 10) { - botGenuines.append(comparison); - std::sort(botGenuines.begin(), botGenuines.end()); - } else if (comparison.score < botGenuines.first().score) { - botGenuines.removeFirst(); - botGenuines.append(comparison); - std::sort(botGenuines.begin(), botGenuines.end()); + if (matches != 0){ + if (botGenuines.size() < matches) { + botGenuines.append(comparison); + std::sort(botGenuines.begin(), botGenuines.end()); + } else if (comparison.score < botGenuines.first().score) { + botGenuines.removeFirst(); + botGenuines.append(comparison); + std::sort(botGenuines.begin(), botGenuines.end()); + } } } else { impostorCount++; - if (topImpostors.size() < 10) { - topImpostors.append(comparison); - std::sort(topImpostors.begin(), topImpostors.end()); - } else if (topImpostors.last().score < comparison.score) { - topImpostors.removeLast(); - topImpostors.append(comparison); - std::sort(topImpostors.begin(), topImpostors.end()); + if (matches != 0) { + if (topImpostors.size() < matches) { + topImpostors.append(comparison); + std::sort(topImpostors.begin(), topImpostors.end()); + } else if (topImpostors.last().score < comparison.score) { + topImpostors.removeLast(); + topImpostors.append(comparison); + std::sort(topImpostors.begin(), topImpostors.end()); + } } } @@ -260,11 +264,12 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const lines.append("Metadata,"+QString::number(simmat.cols*simmat.rows-(genuineCount+impostorCount))+",Ignored"); QString filePath = Globals->path; - if (matches) { + if (matches != 0) { for (int i=0; i("Label")+":" +filePath+"/"+target[topImpostors[i].target].name+":"+query[topImpostors[i].query].get("Label")+":"+filePath+"/"+query[topImpostors[i].query].name); } + std::reverse(botGenuines.begin(), botGenuines.end()); for (int i=0; i("Label")+":" +filePath+"/"+target[botGenuines[i].target].name+":"+query[botGenuines[i].query].get("Label")+":"+filePath+"/"+query[botGenuines[i].query].name); diff --git a/openbr/core/eval.h b/openbr/core/eval.h index a0ca5f4..b3ecce1 100644 --- a/openbr/core/eval.h +++ b/openbr/core/eval.h @@ -23,9 +23,9 @@ namespace br { - float Evaluate(const QString &simmat, const QString &mask = "", const QString &csv = "", bool matches = false); // Returns TAR @ FAR = 0.001 + float Evaluate(const QString &simmat, const QString &mask = "", const QString &csv = "", int matches = 0); // Returns TAR @ FAR = 0.001 float Evaluate(const cv::Mat &scores, const FileList &target, const FileList &query, const QString &csv = "", int parition = 0); - float Evaluate(const cv::Mat &scores, const cv::Mat &masks, const FileList &target, const FileList &query, const QString &csv = "", bool matches = false); + float Evaluate(const cv::Mat &scores, const cv::Mat &masks, const FileList &target, const FileList &query, const QString &csv = "", int matches = 0); float InplaceEval(const QString & simmat, const QString & target, const QString & query, const QString & csv = ""); void EvalClassification(const QString &predictedGallery, const QString &truthGallery, QString predictedProperty = "", QString truthProperty = ""); diff --git a/openbr/core/plot.cpp b/openbr/core/plot.cpp index f1ba75f..5be7fd8 100644 --- a/openbr/core/plot.cpp +++ b/openbr/core/plot.cpp @@ -328,16 +328,18 @@ bool Plot(const QStringList &files, const File &destination, bool show) 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") + 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"))); - 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") + - 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") + - 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") + - 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") + + 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") + + 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}") + + 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") + + 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") + + 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") + QString("multiplot(plot1, plot2, cols=2)\n\t}"))); - 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") + - 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") + - 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") + - 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") + + 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") + + 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}") + + 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") + + 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") + + 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") + QString("multiplot(plot1, plot2, cols=2)\n\t}\n}\n\n"))); return p.finalize(show); diff --git a/openbr/openbr.cpp b/openbr/openbr.cpp index 83e2eee..9a5ffff 100644 --- a/openbr/openbr.cpp +++ b/openbr/openbr.cpp @@ -104,7 +104,7 @@ void br_project(const char *input, const char *gallery) Project(File(input), File(gallery)); } -float br_eval(const char *simmat, const char *mask, const char *csv, bool matches) +float br_eval(const char *simmat, const char *mask, const char *csv, int matches) { return Evaluate(simmat, mask, csv, matches); } diff --git a/openbr/openbr.h b/openbr/openbr.h index 766602b..9c197a3 100644 --- a/openbr/openbr.h +++ b/openbr/openbr.h @@ -154,11 +154,11 @@ BR_EXPORT void br_project(const char *input, const char *output); * \param simmat The \ref simmat to use. * \param mask The \ref mask to use. * \param csv Optional \c .csv file to contain performance metrics. - * \param matches Optional bool flag to output top impostor matches and bottom genuine matches. + * \param matches Optional integer number of top impostor matches and bottom genuine matches to output defualts to 0. * \return True accept rate at a false accept rate of one in one thousand. * \see br_plot */ -BR_EXPORT float br_eval(const char *simmat, const char *mask, const char *csv = "", bool matches = false); +BR_EXPORT float br_eval(const char *simmat, const char *mask, const char *csv = "", int matches = 0); /*! * \brief Creates a \c .csv file containing performance metrics from evaluating the similarity matrix using galleries containing ground truth labels -- libgit2 0.21.4