1. 程式人生 > >臨時儲存(Python)求SSD test accuracy

臨時儲存(Python)求SSD test accuracy

import numpy as np
import os
import matplotlib.pyplot as plt
data_path = '/home/wgb/Downloads/accuracy'
save_path = '/home/wgb/Downloads/accuracy.png'

object_accuracies = []
grasp_accuracies = []
steps = []
for i in range(34):
    step = 100+i*100
    txt_name = str(step)+'.txt'
    txt_path = os.path.join(data_path,txt_name)

    conts = []
    with open(txt_path,'r') as f:
        cont = f.readline()
        while cont:
            conts.append(cont)
            cont = f.readline()
    f.close()

    object_accuracy = np.float32(conts[2].split(':')[1].split('grasp')[0])
    grasp_accuracy = np.float32(conts[2].split(':')[2])
    object_accuracies.append(object_accuracy)
    grasp_accuracies.append(grasp_accuracy)
    steps.append(step)

max_object = round(max(object_accuracies),4)
max_grasp = round(max(grasp_accuracies),4)

plt.plot(steps,object_accuracies)
to ='object_accuracy; max_val=%s'%max_object
plt.text(1500, 0.95, to, ha='left', rotation=0, wrap=True)
plt.plot(steps,grasp_accuracies)

tg ='grasp_accuracy; max_val=%s'%max_grasp
plt.text(1500, 0.83, tg, ha='left', rotation=0, wrap=True)
plt.savefig(save_path)
plt.show()