From 9ef4da29d32ee4979aa7d4c5db8e92ce8457485d Mon Sep 17 00:00:00 2001 From: bhklein Date: Fri, 5 Dec 2014 14:02:44 -0500 Subject: [PATCH] output impostor and genuine matches around the EER score threshold. --- openbr/core/eval.cpp | 48 ++++++++++++++++-------------------------------- openbr/core/plot.cpp | 14 +++++++------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/openbr/core/eval.cpp b/openbr/core/eval.cpp index 92ca2b3..67d75c6 100755 --- a/openbr/core/eval.cpp +++ b/openbr/core/eval.cpp @@ -155,10 +155,6 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv, const QSt float result = -1; - // Lists of top impostors and worst genuine - QList topImpostors; topImpostors.reserve(matches); - QList botGenuines; botGenuines.reserve(matches); - // Make comparisons QList comparisons; comparisons.reserve(simmat.rows*simmat.cols); int genuineCount = 0, impostorCount = 0, numNaNs = 0; @@ -172,29 +168,8 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv, const QSt comparisons.append(comparison); if (comparison.genuine) { genuineCount++; - if (matches != 0){ - if (botGenuines.size() < (int)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 (matches != 0) { - if (topImpostors.size() < (int)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()); - } - } - } } } @@ -214,6 +189,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv, const QSt int falsePositives = 0, previousFalsePositives = 0; int truePositives = 0, previousTruePositives = 0; int index = 0; + int EERIndex = 0; float minGenuineScore = std::numeric_limits::max(); float minImpostorScore = std::numeric_limits::max(); @@ -246,6 +222,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv, const QSt if ((falsePositives > previousFalsePositives) && (truePositives > previousTruePositives)) { operatingPoints.append(OperatingPoint(thresh, float(falsePositives)/impostorCount, float(truePositives)/genuineCount)); + if (floor(float(falsePositives)/impostorCount*1000+0.5)/1000 == floor((1-float(truePositives)/genuineCount)*1000+0.5)/1000) EERIndex = index-1; previousFalsePositives = falsePositives; previousTruePositives = truePositives; } @@ -268,14 +245,21 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv, const QSt if (matches != 0) { const FileList targetFiles = TemplateList::fromGallery(target).files(); const FileList queryFiles = TemplateList::fromGallery(query).files(); - for (int i=0; i("Label")+":" - +filePath+"/"+targetFiles[topImpostors[i].target].name+":"+queryFiles[topImpostors[i].query].get("Label")+":"+filePath+"/"+queryFiles[topImpostors[i].query].name); + unsigned int count = 0; + for (int i = EERIndex-1; i >= 0; i--) { + if (comparisons[i].genuine) { + lines.append("GM,"+QString::number(comparisons[i].score)+","+targetFiles[comparisons[i].target].get("Label")+":" + +filePath+"/"+targetFiles[comparisons[i].target].name+":"+queryFiles[comparisons[i].query].get("Label")+":"+filePath+"/"+queryFiles[comparisons[i].query].name); + if (++count == matches) break; + } } - std::reverse(botGenuines.begin(), botGenuines.end()); - for (int i=0; i("Label")+":" - +filePath+"/"+targetFiles[botGenuines[i].target].name+":"+queryFiles[botGenuines[i].query].get("Label")+":"+filePath+"/"+queryFiles[botGenuines[i].query].name); + count = 0; + for (int i = EERIndex+1; i < comparisons.size(); i++) { + if (!comparisons[i].genuine) { + lines.append("IM,"+QString::number(comparisons[i].score)+","+targetFiles[comparisons[i].target].get("Label")+":" + +filePath+"/"+targetFiles[comparisons[i].target].name+":"+queryFiles[comparisons[i].query].get("Label")+":"+filePath+"/"+queryFiles[comparisons[i].query].name); + if (++count == matches) break; + } } } diff --git a/openbr/core/plot.cpp b/openbr/core/plot.cpp index baebf17..2730107 100644 --- a/openbr/core/plot.cpp +++ b/openbr/core/plot.cpp @@ -148,8 +148,8 @@ struct RPlot "# Split data into individual plots\n" "plot_index = which(names(data)==\"Plot\")\n" "Metadata <- data[grep(\"Metadata\",data$Plot),-c(1)]\n" - "TI <- data[grep(\"TI\",data$Plot),-c(1)]\n" - "BG <- data[grep(\"BG\",data$Plot),-c(1)]\n" + "IM <- data[grep(\"IM\",data$Plot),-c(1)]\n" + "GM <- data[grep(\"GM\",data$Plot),-c(1)]\n" "DET <- data[grep(\"DET\",data$Plot),-c(1)]\n" "FAR <- data[grep(\"FAR\",data$Plot),-c(1)]\n" "FRR <- data[grep(\"FRR\",data$Plot),-c(1)]\n" @@ -166,8 +166,8 @@ struct RPlot "\n" "# Format data\n" "Metadata$Y<-factor(Metadata$Y, levels=c(\"Genuine\",\"Impostor\",\"Ignored\",\"Gallery\",\"Probe\"))\n" - "TI$Y <- as.character(TI$Y)\n" - "BG$Y <- as.character(BG$Y)\n" + "IM$Y <- as.character(IM$Y)\n" + "GM$Y <- as.character(GM$Y)\n" "DET$Y <- as.numeric(as.character(DET$Y))\n" "ERR$Y <- as.numeric(as.character(ERR$Y))\n" "SD$Y <- as.factor(unique(as.character(SD$Y)))\n" @@ -332,14 +332,14 @@ bool Plot(const QStringList &files, const File &destination, bool show) ((p.flip ? p.minor.size : p.major.size) > 1 ? QString(" + facet_wrap(~ %1, scales=\"free_x\")").arg(p.flip ? p.minor.header : p.major.header) : QString()) + QString(" + theme(aspect.ratio=1)\n\n"))); - p.file.write(qPrintable(QString("if (nrow(TI) != 0) {\n\tlibrary(jpeg)\n\tlibrary(png)\n\tlibrary(tiff)\n\tlibrary(grid)\n\t") + + p.file.write(qPrintable(QString("if (nrow(IM) != 0) {\n\tlibrary(jpeg)\n\tlibrary(png)\n\tlibrary(grid)\n\t") + QString("multiplot <- function(..., plotlist=NULL, cols) {\n\t") + QString("\trequire(grid)\n\n\t\t# Make a list from the ... arguments and plotlist\n\t\tplots <- c(list(...), plotlist)\n") + QString("\t\tnumPlots = length(plots)\n\n\t\t# Make the panel\n\t\tplotCols = cols\n\t\tplotRows = ceiling(numPlots/plotCols)\n\n") + 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\text1 <- unlist(strsplit(files[2], \"[.]\"))[2]\n\t\text2 <- unlist(strsplit(files[4], \"[.]\"))[2]\n\t\t") + + p.file.write(qPrintable(QString("\t# Print top impostor matches\n\tfor (i in 1:nrow(IM)) {\n\t\tscore <- IM[i,1]\n\t\tfiles <- IM[i,2]\n\t\talg <- IM[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 if (ext1 == \"TIFF\" || ext1 == \"tiff\" || ext1 == \"TIF\" || ext1 == \"tif\") {\n\t\t\timg1 <- readTIFF(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} ") + QString("else if (ext2 == \"PNG\" || ext2 == \"png\") {\n\t\t\timg2 <- readPNG(files[4])\n\t\t} else if (ext2 == \"TIFF\" || ext2 == \"tiff\" || ext2 == \"TIF\" || ext2 == \"tif\") {\n\t\t\timg2 <- readTIFF(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") + @@ -347,7 +347,7 @@ bool Plot(const QStringList &files, const File &destination, bool show) 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\text1 <- unlist(strsplit(files[2], \"[.]\"))[2]\n\t\text2 <- unlist(strsplit(files[4], \"[.]\"))[2]\n\t\t") + + p.file.write(qPrintable(QString("\n\n\t# Print worst genuine matches\n\tfor (i in 1:nrow(GM)) {\n\t\tscore <- GM[i,1]\n\t\tfiles <- GM[i,2]\n\t\talg <- GM[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 if (ext1 == \"TIFF\" || ext1 == \"tiff\" || ext1 == \"TIF\" || ext1 == \"tif\") {\n\t\t\timg1 <- readTIFF(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} ") + QString("else if (ext2 == \"PNG\" || ext2 == \"png\") {\n\t\t\timg2 <- readPNG(files[4])\n\t\t} else if (ext2 == \"TIFF\" || ext2 == \"tiff\" || ext2 == \"TIF\" || ext2 == \"tif\") {\n\t\t\timg2 <- readTIFF(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") + -- libgit2 0.21.4