import matplotlib.pyplot as plt


iteration = []
loss = []
with open('/home/sensetime/log.txt','r') as file:
    for line in file:
        line = line.strip()
        if(line.find('Iteration') != -1):
            if(line.find('loss') != -1):
                line = line.split()
                line[5] = line[5].split(',')[0]
                iteration.append(float(line[5]))
                loss.append(float(line[8]))
# for i in iteration:
#     print i
# for i in loss:
#     print i


_, ax1 = plt.subplots()
ax1.plot(iteration, loss)
ax1.set_xlabel('iteration')
ax1.set_ylabel('train loss')

plt.show()

参照http://www.linuxidc.com/Linux/2016-11/136774p19.htm,这个网址还把test准确率也画上来了,很好的一个例子