Caffe 不会在 SIGINT 上制作快照

Caffe does not make snapshots on SIGINT

当我在终端中按下 CTRL+C 时,caffe 停止训练但不制作快照。如何解决? 我的求解器:

net: "course-work/testing/model.prototxt"
test_iter: 200
test_interval: 500

base_lr: 0.001
momentum: 0.9
weight_decay: 0.005
lr_policy: "fixed"

display: 50
max_iter: 60000

snapshot: 5000
snapshot_format: HDF5
snapshot_prefix: "course-work/testing/by_solver_lr0"
snapshot_after_train: true

solver_mode: CPU

Bash 脚本:

TOOLS=./build/tools
NET_DIR=course-work/testing

$TOOLS/caffe train \
    --solver=$NET_DIR/solver_lr0.prototxt 2>&1 | tee $NET_DIR/1.log

通过 tee 和管道重定向 caffe 的输出可能会改变 OS 处理信号并将信号传输到进程的方式。尽量避免 | tee 以确保 SIGINT 达到 caffe。

注意 caffe tool 有两个标志

DEFINE_string(sigint_effect, "stop",
             "Optional; action to take when a SIGINT signal is received: "
              "snapshot, stop or none.");
DEFINE_string(sighup_effect, "snapshot",
             "Optional; action to take when a SIGHUP signal is received: "
             "snapshot, stop or none.");

这些标志可以帮助您定义 caffe 在 SIGINT and SIGHUP 上的行为。

记录 caffe 输出的一个好方法是

GLOG_log_dir=/path/to/log/dir $CAFFE_ROOT/bin/caffe.bin train 
—solver=/path/to/solver.prototxt

这会实时记录 caffe 输出,SIGINT 肯定会到达 caffe。