caffe 根据log画图 train-loss

根据caffe训练打印的
I1102 20:42:49.268401 188 solver.cpp:352] Iteration 135020 (0.108123 iter/s, 92.4871s/10 iter), 114.5/13668.5ep, loss = 0.0899582
提取iteration和loss值画图

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()

posted @ 2022-11-04 14:39  无左无右  阅读(25)  评论(0编辑  收藏  举报