From 1fc7134f2112ec4173ba3a54590a9a3d004d5277 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Mon, 28 Jan 2013 15:34:53 +0400 Subject: [PATCH] add legend for ROC plot --- apps/sft/misc/roc_test.py | 16 +++++++++------- apps/sft/misc/sft.py | 23 ++++++++++------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/apps/sft/misc/roc_test.py b/apps/sft/misc/roc_test.py index f640af30ae..f0fc3a809a 100755 --- a/apps/sft/misc/roc_test.py +++ b/apps/sft/misc/roc_test.py @@ -7,7 +7,7 @@ import sys, os, os.path, glob, math, cv2 from datetime import datetime import numpy -plot_colors = ['b', 'r', 'g', 'c', 'm'] +plot_colors = ['b', 'c', 'r', 'g', 'm'] # "key" : ( b, g, r) bgr = { "red" : ( 0, 0, 255), @@ -25,7 +25,7 @@ def call_parser(f, a): return eval( "sft.parse_" + f + "('" + a + "')") if __name__ == "__main__": - parser = argparse.ArgumentParser(description = 'Plot ROC curve using Caltech mathod of per image detection performance estimation.') + parser = argparse.ArgumentParser(description = 'Plot ROC curve using Caltech method of per image detection performance estimation.') # positional parser.add_argument("cascade", help = "Path to the tested detector.", nargs='+') @@ -35,22 +35,24 @@ if __name__ == "__main__": # optional parser.add_argument("-m", "--min_scale", dest = "min_scale", type = float, metavar= "fl", help = "Minimum scale to be tested.", default = 0.4) parser.add_argument("-M", "--max_scale", dest = "max_scale", type = float, metavar= "fl", help = "Maximum scale to be tested.", default = 5.0) - parser.add_argument("-o", "--output", dest = "output", type = str, metavar= "path", help = "Path to store resultiong image.", default = "./roc.png") - parser.add_argument("-n", "--nscales", dest = "nscales", type = int, metavar= "n", help = "Prefered count of scales from min to max.", default = 55) + parser.add_argument("-o", "--output", dest = "output", type = str, metavar= "path", help = "Path to store resulting image.", default = "./roc.png") + parser.add_argument("-n", "--nscales", dest = "nscales", type = int, metavar= "n", help = "Preferred count of scales from min to max.", default = 55) parser.add_argument("-r", "--scale-range", dest = "scale_range", type = range, default = (128 * 0.4, 128 * 2.4)) parser.add_argument("-e", "--extended-range-ratio", dest = "ext_ratio", type = float, default = 1.25) + parser.add_argument("-t", "--title", dest = "title", type = str, default = "ROC curve Bahnhof") # required parser.add_argument("-f", "--anttn-format", dest = "anttn_format", choices = ['inria', 'caltech', "idl"], help = "Annotation file for test sequence.", required = True) + parser.add_argument("-l", "--labels", dest = "labels" ,required=True, help = "Plot labels for legend.", nargs='+') args = parser.parse_args() print args.scale_range print args.cascade - # # parse annotations - sft.initPlot() + # parse annotations + sft.initPlot(args.title) samples = call_parser(args.anttn_format, args.annotations) for idx, each in enumerate(args.cascade): print each @@ -98,4 +100,4 @@ if __name__ == "__main__": fppi, miss_rate = sft.computeROC(confidenses, tp, nannotated, nframes, ignored) sft.plotLogLog(fppi, miss_rate, plot_colors[idx]) - sft.showPlot("roc_curve.png") \ No newline at end of file + sft.showPlot(args.output, args.labels) \ No newline at end of file diff --git a/apps/sft/misc/sft.py b/apps/sft/misc/sft.py index 147c391cb2..cac8094050 100644 --- a/apps/sft/misc/sft.py +++ b/apps/sft/misc/sft.py @@ -61,11 +61,7 @@ def crop_rect(rect, factor): return x """ Initialize plot axises.""" -def initPlot(name = "ROC curve Bahnhof"): - - fig, ax = plt.subplots() - fig.canvas.draw() - +def initPlot(name): plt.xlabel("fppi") plt.ylabel("miss rate") plt.title(name) @@ -73,11 +69,16 @@ def initPlot(name = "ROC curve Bahnhof"): plt.xscale('log') plt.yscale('log') +""" Draw plot.""" +def plotLogLog(fppi, miss_rate, c): + plt.loglog(fppi, miss_rate, color = c, linewidth = 2) + """ Show resulted plot.""" -def showPlot(file_name): - plt.savefig(file_name) - plt.axis((pow(10, -3), pow(10, 1), 0.0, 1)) +def showPlot(file_name, labels): + plt.axis((pow(10, -3), pow(10, 1), .035, 1)) plt.yticks( [0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.64, 0.8, 1], ['.05', '.10', '.20', '.30', '.40', '.50', '.64', '.80', '1'] ) + plt.legend(labels, loc = "lower left") + plt.savefig(file_name) plt.show() """ Filter true positives and ignored detections for cascade detector output.""" @@ -110,10 +111,6 @@ def match(gts, dts): matches_ignore[idx] = 1 return matches_dt, matches_ignore -""" Draw plot.""" -def plotLogLog(fppi, miss_rate, c): - print - plt.loglog(fppi, miss_rate, color = c, linewidth = 2) """ Draw detections or ground truth on image.""" def draw_rects(img, rects, color, l = lambda x, y : x + y): @@ -209,7 +206,7 @@ def norm_acpect_ratio(boxes, ratio): """ Filter detections out of extended range. """ def filter_for_range(boxes, scale_range, ext_ratio): - boxes = sft.norm_acpect_ratio(boxes, 0.5) + boxes = norm_acpect_ratio(boxes, 0.5) boxes = [b for b in boxes if (b[3] - b[1]) > scale_range[0] / ext_ratio] boxes = [b for b in boxes if (b[3] - b[1]) < scale_range[1] * ext_ratio] return boxes