Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import argparse
- import matplotlib.pyplot as plt
- from pylab import *
- import numpy as np
- def compare(line1,line2):
- print ("line1 = ",line1)
- print ("line2 = ",line2)
- iter_num1 = int(line1.split()[0])
- iter_num2 = int(line2.split()[0])
- if iter_num1<iter_num2:
- return -1
- elif iter_num1>iter_num2:
- return 1
- else :
- return 0
- def main(argv):
- parser = argparse.ArgumentParser()
- parser.add_argument('input_file',default = "C:\\darknet_fire_detection\\build\\darknet\\x64\\log\\precision_recall5.txt", help="file to read precision and recall")
- args = parser.parse_args()
- args.output_file = args.input_file.replace(".txt",".png")
- print ("input file you provided is {}".format(args.input_file))
- print ("output file you provided is {}".format(args.output_file))
- f = open(args.input_file)
- lines = [line.rstrip("\n") for line in f.readlines()]
- print (lines)
- f.close()
- iters = []
- fire_precisions = []
- fire_recalls = []
- smoke_precisions = []
- smoke_recalls = []
- for line in lines:
- cols = line.split()
- iters.append(float(cols[0][:-1]))
- fire_precisions.append(float(cols[1]))
- if 'nan' in cols[2]:
- cols[2]='0'
- fire_recalls.append(float(cols[2]))
- smoke_precisions.append(float(cols[3]))
- if 'nan' in cols[4]:
- cols[4]='0'
- smoke_recalls.append(float(cols[4]))
- fire_F1s = 2*np.array(fire_precisions)*np.array(fire_recalls)/(np.array(fire_precisions)+np.array(fire_recalls))
- smoke_F1s = 2*np.array(smoke_precisions)*np.array(smoke_recalls)/(np.array(smoke_precisions)+np.array(smoke_recalls))
- fig= plt.figure()
- fig.set_size_inches(8,6)
- ax = fig.add_subplot(221)
- plt.plot(iters,fire_precisions,label = "fire precision")
- plt.plot(iters,fire_recalls, label = "fire recall")
- plt.plot(iters,fire_F1s, label = "fire F1")
- plt.legend()
- ax.set_yticks(np.linspace(0,1,11))
- plt.grid()
- plt.ylabel("precision/recall value. Ideally should be 1")
- plt.legend()
- ax.set_yticks(np.linspace(0,1,11))
- ax = fig.add_subplot(222)
- plt.plot(iters,smoke_precisions,label = "smoke precision")
- plt.plot(iters,smoke_recalls, label = "smoke recall")
- plt.plot(iters,smoke_F1s, label = "smoke F1")
- plt.legend()
- ax.set_yticks(np.linspace(0,1,11))
- plt.grid()
- ax = fig.add_subplot(223)
- avg_F1s = 2*(np.array(fire_F1s)*np.array(smoke_F1s))/(np.array(fire_F1s)+np.array(smoke_F1s))
- plt.plot(iters,avg_F1s, color='g', label = "F1 of F1s")
- ax.set_yticks(np.linspace(0,1,11))
- plt.grid()
- plt.xlabel("number of iterations in K(1.0 means 1000)")
- plt.legend()
- savefig(args.output_file,dpi=200)
- plt.show()
- if __name__ == "__main__":
- main(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement