所采用的网络是GoogleNet,故训练日志也是GoogleNet的日志。
其他网络稍微修改即可
import matplotlib.pyplot as plt
import numpy as np
import re
loss = []
iteration = 0 #存放迭代次数
with open("log.txt", 'r') as f:
for line in f:
if "Test net output #6" in line: #loss3
loss.append(re.findall(r"= (\d+\.\d+) \(", line)) #\d+,任意多数字。\.就是. 。
#if "Test net output #7" in line: #loss3_top-1
# loss.append(re.findall(r"= (\d+\.\d+)", line))
if "] Iteration" in line: #获取最大迭代次数
if(re.findall(r"Iteration (.\d+),",line)):
iteration=int(re.findall(r"Iteration (.\d+),",line)[0])#re.findall返回的是一个列表,需要[0]提取元素
print(iteration)
y = np.array(loss, dtype=np.float64) #list转array
x = np.arange(0, iteration, iteration/y.size)
plt.figure()
plt.plot(x, y)
plt.xlabel('#iters')
plt.ylabel('loss3_top-1')
# plt.ylim(0.84, 0.4) # top-1 or 5
plt.show()