def plot(arg, main=False): global i f = open(arg, "r") points = cPickle.load(f) f.close() label = arg if label.find(".") != -1: label = label[:label.rfind(".")] if label.find("/") != -1: label = label[label.rfind("/") + 1:] color = colors[i % 6] width = 2 # if main == True: if label == "ConvNet-MRC-Unsup": style = "-" color = "r" width = 3 i -= 1 elif label == "ConvNet-MRC-Random": style = "--" color = "r" width = 3 i -= 1 elif label == "ConvNet-Unsup": style = "-" color = '#00FF00' width = 3 i -= 1 elif label == "ConvNet-Random": style = "--" color = '#00FF00' width = 3 i -= 1 elif i < n_colors: style = "-" elif i < 2 * n_colors: style = "--" elif i < 3 * n_colors: style = ":" else: style = "-." i += 1 index = i # index of this curve ############################################################################ # compute this curve's AUC score # score: area under curve between x0 and x1 # find minimum and maximum x in points x0 = 0 y0 = 1 x1 = 1 score = measures.auc_percent(points, x0, y0, x1) print "area under curve for x between " + str(x0) + " and " + str(x1) \ + " AUC" + str(x0) + "_" + str(x1) + "=" + str(score) + "%" curves_auc.append([ score, index, [a[0] for a in points], [-a[1] for a in points], style, color, label + " (%.2f%%)" % score, width ]) global auc_title auc_title = "Area Under Curve [" + str(x0) + ', ' + str(x1) + '] FPPI' ############################################################################ # compute this curve's score, with y for a particular x # find y for x=val val = 1 y = 0 x1 = 0 x2 = 0 y1 = 0 y2 = 0 for a in points: x2 = x1 y2 = y1 x1 = a[0] y1 = -a[1] if (x1 > 1 and x2 <= 1): # interpolate y = y2 + (y1 - y2) * (val - x2) / (x1 - x2) if (x1 <= 1 and x2 <= 1): y = y1 y = y * 100 # use percentage score = y curves.append([ score, index, [a[0] for a in points], [-a[1] for a in points], style, color, label + " (%.2f%%)" % score, width ])
def print_DET(multi_result, n_imgs, save_filename = None, show_curve = True, xmin = None, ymin = None, xmax = None, ymax = None, grid_major = False, grid_minor = False): print "Printing DET curve with xmin: " + str(xmin) + " xmax: " + str(xmax) \ + " ymin: " + str(ymin) + " ymax: " + str(ymax) points = [] n_imgs = float(n_imgs) # each result is defined for a given threshold for result in multi_result: tp = float(result.n_true_positives()) fp = float(result.n_false_positives()) fn = float(result.n_false_negatives()) #n_imgs = float(len(result.images)) #the "-" is a trick for sorting points.append((max(xmin, fp / n_imgs), - fn / (tp + fn))) points.sort() # interpolate value at 100FPPI y = 100 * interpolate(100.0, 0, 1, 1000, 10000, points) print "miss rate at 100FPPI=" + "%.2f%%"%y # interpolate value at 10FPPI y = 100 * interpolate(10.0, 0, 1, 1000, 10000, points) print "miss rate at 10FPPI=" + "%.2f%%"%y # interpolate value at 1FPPI y = 100 * interpolate(1.0, 0, 1, 1000, 10000, points) print "miss rate at 1FPPI=" + "%.2f%%"%y # interpolate value at .001FPPI y = 100 * interpolate(.01, 0, 1, 1000, 10000, points) print "miss rate at .01FPPI=" + "%.2f%%"%y # get area under curve percentage in 0-100 x0 = 0 y0 = 1 x1 = 100 auc = measures.auc_percent(points, x0, y0, x1); print "area under curve in range [" + str(x0) + ", " + str(x1) + "]: " \ + "AUC" + str(x0) + "-" + str(x1) + "=" + str(auc) + "%" # get area under curve percentage in 0-10 x0 = 0 y0 = 1 x1 = 10 auc = measures.auc_percent(points, x0, y0, x1); print "area under curve in range [" + str(x0) + ", " + str(x1) + "]: " \ + "AUC" + str(x0) + "-" + str(x1) + "=" + str(auc) + "%" # get area under curve percentage in 0-1 x0 = 0 y0 = 1 x1 = 1 auc = measures.auc_percent(points, x0, y0, x1); print "area under curve in range [" + str(x0) + ", " + str(x1) + "]: " \ + "AUC" + str(x0) + "-" + str(x1) + "=" + str(auc) + "%" # # get total area under curve # auc = measures.auc_percent(points, x0, y0, x1); # print "area under curve in range [" + str(x0) + ", " + str(x1) + "]: " \ # + "AUC" + str(x0) + "-" + str(x1) + "=" + str(auc) + "%" # save curve if save_filename != None: f = open(save_filename, "w") cPickle.dump(points, f) f.close() #TODO : params if show_curve: pylab.loglog([a[0] for a in points], [- a[1] for a in points]) if xmin != None: pylab.axis(xmin = xmin) if xmax != None: pylab.axis(xmax = xmax) if ymin != None: pylab.axis(ymin = ymin) if ymax != None: pylab.axis(ymax = ymax) pylab.xlabel("False positives per image (FPPI)") pylab.ylabel("Miss rate") if grid_major: pylab.grid(True, which='major') if grid_minor: pylab.grid(True, which='minor') pylab.show()
def plot(arg, main = False): global i f = open(arg, "r") points = cPickle.load(f) f.close() label = arg if label.find(".") != -1: label = label[:label.rfind(".")] if label.find("/") != -1: label = label[label.rfind("/")+1:] color = colors[i%6] width = 2 # if main == True: if label == "ConvNet-MRC-Unsup": style = "-" color = "r" width = 3 i -= 1 elif label == "ConvNet-MRC-Random": style = "--" color = "r" width = 3 i -= 1 elif label == "ConvNet-Unsup": style = "-" color = '#00FF00' width = 3 i -= 1 elif label == "ConvNet-Random": style = "--" color = '#00FF00' width = 3 i -= 1 elif i < n_colors: style = "-" elif i < 2*n_colors: style = "--" elif i < 3*n_colors: style = ":" else: style = "-." i += 1 index = i # index of this curve ############################################################################ # compute this curve's AUC score # score: area under curve between x0 and x1 # find minimum and maximum x in points x0 = 0 y0 = 1 x1 = 1 score = measures.auc_percent(points, x0, y0, x1) print "area under curve for x between " + str(x0) + " and " + str(x1) \ + " AUC" + str(x0) + "_" + str(x1) + "=" + str(score) + "%" curves_auc.append([score, index, [a[0] for a in points], [- a[1] for a in points], style, color, label + " (%.2f%%)"%score, width]) global auc_title auc_title = "Area Under Curve [" + str(x0) + ', ' + str(x1) + '] FPPI' ############################################################################ # compute this curve's score, with y for a particular x # find y for x=val val = 1 y = 0 x1 = 0 x2 = 0 y1 = 0 y2 = 0 for a in points: x2 = x1 y2 = y1 x1 = a[0] y1 = -a[1] if (x1 > 1 and x2 <= 1): # interpolate y = y2 + (y1 - y2) * (val - x2) / (x1 - x2) if (x1 <= 1 and x2 <= 1): y = y1 y = y * 100 # use percentage score = y curves.append([score, index, [a[0] for a in points], [- a[1] for a in points], style, color, label + " (%.2f%%)"%score, width])
def print_DET(multi_result, n_imgs, save_filename=None, show_curve=True, xmin=None, ymin=None, xmax=None, ymax=None, grid_major=False, grid_minor=False): print "Printing DET curve with xmin: " + str(xmin) + " xmax: " + str(xmax) \ + " ymin: " + str(ymin) + " ymax: " + str(ymax) points = [] n_imgs = float(n_imgs) # each result is defined for a given threshold for result in multi_result: tp = float(result.n_true_positives()) fp = float(result.n_false_positives()) fn = float(result.n_false_negatives()) #n_imgs = float(len(result.images)) #the "-" is a trick for sorting points.append((max(xmin, fp / n_imgs), -fn / (tp + fn))) points.sort() # interpolate value at 100FPPI y = 100 * interpolate(100.0, 0, 1, 1000, 10000, points) print "miss rate at 100FPPI=" + "%.2f%%" % y # interpolate value at 10FPPI y = 100 * interpolate(10.0, 0, 1, 1000, 10000, points) print "miss rate at 10FPPI=" + "%.2f%%" % y # interpolate value at 1FPPI y = 100 * interpolate(1.0, 0, 1, 1000, 10000, points) print "miss rate at 1FPPI=" + "%.2f%%" % y # interpolate value at .001FPPI y = 100 * interpolate(.01, 0, 1, 1000, 10000, points) print "miss rate at .01FPPI=" + "%.2f%%" % y # get area under curve percentage in 0-100 x0 = 0 y0 = 1 x1 = 100 auc = measures.auc_percent(points, x0, y0, x1) print "area under curve in range [" + str(x0) + ", " + str(x1) + "]: " \ + "AUC" + str(x0) + "-" + str(x1) + "=" + str(auc) + "%" # get area under curve percentage in 0-10 x0 = 0 y0 = 1 x1 = 10 auc = measures.auc_percent(points, x0, y0, x1) print "area under curve in range [" + str(x0) + ", " + str(x1) + "]: " \ + "AUC" + str(x0) + "-" + str(x1) + "=" + str(auc) + "%" # get area under curve percentage in 0-1 x0 = 0 y0 = 1 x1 = 1 auc = measures.auc_percent(points, x0, y0, x1) print "area under curve in range [" + str(x0) + ", " + str(x1) + "]: " \ + "AUC" + str(x0) + "-" + str(x1) + "=" + str(auc) + "%" # # get total area under curve # auc = measures.auc_percent(points, x0, y0, x1); # print "area under curve in range [" + str(x0) + ", " + str(x1) + "]: " \ # + "AUC" + str(x0) + "-" + str(x1) + "=" + str(auc) + "%" # save curve if save_filename != None: f = open(save_filename, "w") cPickle.dump(points, f) f.close() #TODO : params if show_curve: pylab.loglog([a[0] for a in points], [-a[1] for a in points]) if xmin != None: pylab.axis(xmin=xmin) if xmax != None: pylab.axis(xmax=xmax) if ymin != None: pylab.axis(ymin=ymin) if ymax != None: pylab.axis(ymax=ymax) pylab.xlabel("False positives per image (FPPI)") pylab.ylabel("Miss rate") if grid_major: pylab.grid(True, which='major') if grid_minor: pylab.grid(True, which='minor') pylab.show()