首页 > 其他分享 >caffe 根据log画图 train-loss

caffe 根据log画图 train-loss

时间:2022-11-04 14:44:31浏览次数:61  
标签:loss plt log index list iteration train line

import matplotlib.pyplot as plt
import numpy as np

path_log = "/media/algo/data_1/project/lenet/logs/logs/20221020-123.log"

with open(path_log, "r") as fr:
    lines = fr.readlines()

def get_index(list_tmp, val):
    for index, value in enumerate(list_tmp):
        if val == value:
            return index
    return -1

list_iteration = []
list_loss = []
for line in lines:
    if ("Iteration " in line) and ("loss =" in line):
        line = line.rstrip()
        print(line)
        line_split = line.split(" ")
        index_iteration = get_index(line_split, "Iteration")
        index_loss = get_index(line_split, "loss")
        if -1 == index_iteration or -1 == index_loss:
            continue

        iteration_ = line_split[index_iteration + 1]
        loss_ = line_split[index_loss + 2]
        list_iteration.append(int(iteration_))
        list_loss.append(float(loss_))



plt.figure(figsize=(8,6))  # 定义图的大小
plt.xlabel("iteration")     # X轴标签
plt.ylabel("loss")        # Y轴坐标标签
plt.title("train-loss")      #  曲线图的标题

plt.plot(list_iteration, list_loss, label="train-loss", color="red", linewidth=2)
plt.savefig("11111.jpg")
plt.show()

标签:loss,plt,log,index,list,iteration,train,line
From: https://www.cnblogs.com/yanghailin/p/16857726.html

相关文章