plot_statistics.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 ##############
00003 # View the statistics for a single experiment (bag file)
00004 #
00005 # Statistics are plotted separately, i.e. one window per object per variant,
00006 # showing precision and recall.
00007 
00008 
00009 import numpy as np
00010 import matplotlib.pylab as plt
00011 import matplotlib
00012 matplotlib.rcParams['ps.useafm'] = True
00013 matplotlib.rcParams['pdf.use14corefonts'] = True
00014 matplotlib.rcParams['text.usetex'] = True
00015 
00016 import sys
00017 import os
00018 import os.path
00019 
00020 
00021 def plot_statistics(folder):
00022   for f in os.listdir(folder):
00023     if f[-3:] != "txt":
00024       continue
00025     filename = os.path.join(folder, f)
00026       
00027     data = np.genfromtxt(filename, dtype=float, delimiter=' ', names=True)
00028 
00029     precision = data['tp'] / (data['tp']+data['fp'])
00030     recall = data['tp'] / (data['tp']+data['fn'])
00031     seg_acc = data['tp'] / (data['tp']+data['fp']+data['fn'])
00032       
00033     time = data['time'] - data['time'][0]
00034     
00035     # clean up
00036     precision[np.where(np.isnan(precision))] = 0.
00037     recall[np.where(np.isnan(recall))] = 0.
00038     seg_acc[np.where(np.isnan(seg_acc))] = 0.
00039 
00040     plt.figure(figsize=(7.5,5))
00041     for y in np.arange(0.0, 1.1, 0.2):  
00042       plt.plot(time, [y] * len(time), "--", lw=0.5, color="black", alpha=0.3)  
00043   
00044     plt.plot(time, seg_acc, "k", label="Segmentation Accuracy", lw=3.0)
00045     plt.plot(time, precision, "b", label="Precision", lw=2.0, ls="--")
00046     plt.plot(time, recall, "r", label="Recall", lw=2.0, ls="--")
00047     
00048     plt.xlim(0, data['time'][-1] - data['time'][0])
00049     plt.ylim(-0.1, 1.1)
00050     plt.xlabel("time")
00051     
00052     plt.title(os.path.basename(filename[:-3]))
00053     plt.legend(loc=4)
00054     
00055     img_path = os.path.join(folder, f[:-3]+"pdf")
00056     print ("Saving image at %s" % img_path)
00057     plt.savefig(img_path, bbox_inches="tight")
00058 
00059 if __name__ == "__main__":
00060   if len(sys.argv) != 2:
00061     print "Usage: plot_statistics.py <experiment folder>"
00062     sys.exit()
00063 
00064   print ("Starting plot statistics")
00065   plot_statistics(sys.argv[1])
00066 
00067   plt.show()
00068 


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:34:12