windows下输出训练caffemodel的log日志并画出accuracy和loss曲线

1、在训练的指令后加入将日志导入文件的指令:

"..\caffe.exe" train --solver=E:/caffe/caffe-master/Build/x64/Release/lenet/lenet_solver.prototxt >./log/lenet_mnist.log 2>&1

会在log文件下生成:lenet_mnist.log.test lenet_mnist.log.train两个文件


2、将E:\caffe\caffe-master\tools\extra目录下的:

plot_training_log.py.example

parse_log.py

extract_seconds.py

文件拷贝到log文件下,然后重命名plot_training_log.py.example为plot_training_log.py


3、修改plot_training_log.py

下面修改的部分是为了和生成的文件格式对应,如下图

windows下输出训练caffemodel的log日志并画出accuracy和loss曲线_第1张图片

3.1 修改函数load_data,分割符号为','

def load_data(data_file, field_idx0, field_idx1):
    data = [[], []]
    line_index = 0
    with open(data_file, 'r') as f:
        for line in f:
            if line_index == 0:
                line_index += 1
                continue
            line = line.strip(',')
            if line[0] != '#':
                fields = line.split(',')
                data[0].append(float(fields[field_idx0].strip()))
                data[1].append(float(fields[field_idx1].strip()))
    return data

3.2 修改解析的文件为python版本

def get_log_parsing_script():
    dirname = os.path.dirname(os.path.abspath(inspect.getfile(
        inspect.currentframe())))
    return dirname + '/parse_log.py'

3.3 修改执行python解析日志文件的程序parse_log.py

def plot_chart(chart_type, path_to_png, path_to_log_list):
    for path_to_log in path_to_log_list:
        os.system('%s %s %s %s' % ('F:/wxf/Anaconda2/python.exe', 
                                   get_log_parsing_script(), 
                                   path_to_log, 
                                   'E:/caffe/caffe-master/Build/x64/Release/lenet/log/'))
        ...

然后就ok了


4、Supported chart types:
    0: Test accuracy  vs. Iters
    1: Test accuracy  vs. Seconds
    2: Test loss  vs. Iters
    3: Test loss  vs. Seconds
    4: Train learning rate  vs. Iters
    5: Train learning rate  vs. Seconds
    6: Train loss  vs. Iters
    7: Train loss  vs. Seconds


5、执行的脚本

F:\wxf\Anaconda2\python.exe plot_training_log.py 4 save.png lenet_mnist.log lenet_mnist_dropout.log


windows下输出训练caffemodel的log日志并画出accuracy和loss曲线_第2张图片windows下输出训练caffemodel的log日志并画出accuracy和loss曲线_第3张图片

你可能感兴趣的:(机器学习&深度学习)