Advertisement
Sohibbek

draw_prec-recall

Aug 1st, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.89 KB | None | 0 0
  1. import sys
  2. import argparse
  3. import matplotlib.pyplot as plt
  4. from pylab import *
  5. import numpy as np
  6.  
  7. def compare(line1,line2):
  8.     print ("line1 = ",line1)
  9.     print ("line2 = ",line2)
  10.  
  11.     iter_num1  = int(line1.split()[0])
  12.     iter_num2  = int(line2.split()[0])
  13.     if iter_num1<iter_num2:
  14.         return -1
  15.     elif iter_num1>iter_num2:
  16.         return 1
  17.     else :
  18.         return 0
  19.  
  20. def main(argv):
  21.     parser = argparse.ArgumentParser()
  22.     parser.add_argument('input_file',default = "C:\\darknet_fire_detection\\build\\darknet\\x64\\log\\precision_recall5.txt", help="file to read precision and recall")
  23.  
  24.     args = parser.parse_args()
  25.     args.output_file = args.input_file.replace(".txt",".png")
  26.  
  27.     print ("input file you provided is {}".format(args.input_file))
  28.     print ("output file you provided is {}".format(args.output_file))
  29.  
  30.     f = open(args.input_file)    
  31.  
  32.     lines = [line.rstrip("\n") for line in f.readlines()]
  33.     print (lines)
  34.     f.close()
  35.  
  36.  
  37.     iters = []
  38.     fire_precisions = []
  39.     fire_recalls = []
  40.  
  41.     smoke_precisions = []
  42.     smoke_recalls = []
  43.  
  44.     for line in lines:
  45.         cols = line.split()
  46.        
  47.         iters.append(float(cols[0][:-1]))
  48.         fire_precisions.append(float(cols[1]))
  49.  
  50.         if 'nan' in cols[2]:
  51.             cols[2]='0'
  52.         fire_recalls.append(float(cols[2]))
  53.  
  54.         smoke_precisions.append(float(cols[3]))
  55.  
  56.         if 'nan' in cols[4]:
  57.             cols[4]='0'
  58.         smoke_recalls.append(float(cols[4]))
  59.  
  60.     fire_F1s = 2*np.array(fire_precisions)*np.array(fire_recalls)/(np.array(fire_precisions)+np.array(fire_recalls))
  61.     smoke_F1s = 2*np.array(smoke_precisions)*np.array(smoke_recalls)/(np.array(smoke_precisions)+np.array(smoke_recalls))
  62.  
  63.     fig= plt.figure()
  64.     fig.set_size_inches(8,6)
  65.     ax = fig.add_subplot(221)
  66.     plt.plot(iters,fire_precisions,label = "fire precision")
  67.     plt.plot(iters,fire_recalls, label = "fire recall")
  68.     plt.plot(iters,fire_F1s, label = "fire F1")
  69.     plt.legend()
  70.     ax.set_yticks(np.linspace(0,1,11))
  71.     plt.grid()
  72.     plt.ylabel("precision/recall value. Ideally should be 1")    
  73.    
  74.     plt.legend()
  75.     ax.set_yticks(np.linspace(0,1,11))
  76.  
  77.     ax = fig.add_subplot(222)
  78.     plt.plot(iters,smoke_precisions,label = "smoke precision")
  79.     plt.plot(iters,smoke_recalls, label = "smoke recall")
  80.     plt.plot(iters,smoke_F1s, label = "smoke F1")
  81.     plt.legend()
  82.     ax.set_yticks(np.linspace(0,1,11))
  83.     plt.grid()
  84.  
  85.  
  86.  
  87.     ax = fig.add_subplot(223)
  88.  
  89.     avg_F1s = 2*(np.array(fire_F1s)*np.array(smoke_F1s))/(np.array(fire_F1s)+np.array(smoke_F1s))
  90.  
  91.     plt.plot(iters,avg_F1s, color='g', label = "F1 of F1s")
  92.     ax.set_yticks(np.linspace(0,1,11))
  93.     plt.grid()
  94.     plt.xlabel("number of iterations in K(1.0 means 1000)")
  95.     plt.legend()
  96.  
  97.     savefig(args.output_file,dpi=200)    
  98.     plt.show()
  99.  
  100. if __name__ == "__main__":
  101.     main(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement