Ink One

Caffe绘制训练过程中的loss曲线

保存训练日志

上一篇文章的 ResNet 训练过程为例,在 examples/ResNet/ 目录下新建文件夹 log, 新建脚本:

1
2
3
4
5
6
#!/bin/bash
t=$(date +%Y-%m-%d_%H:%M:%S)
LOG=examples/ResNet/log/cifar10_$t.log
./build/tools/caffe train --solver=examples/ResNet/solver.prototxt \
--gpu=0 2>&1 | tee $LOG

运行脚本进行训练。

绘制 loss 和 accuracy 曲线

使用到的文件:

1
2
3
$CAFFE_ROOT/tools/extra/parse_log.sh
$CAFFE_ROOT/tools/extra/extract_seconds.py
$CAFFE_ROOT/tools/extra/plot_training_log.py.example

绘制曲线

执行命令:

1
$ ./tools/plot_training_log.py.example <chart_type> <path_to_png> <path_to_log>

参数分别为:

  • chart_type: 绘制曲线类型,取值范围:
    • 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
  • path_to_png: 输出图片的文件名,格式为.png
  • path_to_log: 日志文件,格式为.log,本例中为cifar10_*.log

调用了同个目录下的 parse_log.sh 脚本,生成 cifar10_*.log.traincifar10_*.log.test 两个文件。

并绘制曲线。

Train loss vs. Iters Test loss vs. Iters Test accuracy vs. Iters