Caffe技巧之使用snapshot来继续网络训练
有时候想在已经训练好的网络上继续之前的训练,那么可以使用snapshot的命令,本文介绍在Caffe里如何使用snapshot来继续网络训练。
Step 1:设置solver.prototxt
首先,在solver.prototxt 中设置得到snapshot 文件,例如:
<code class="hljs vala has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;"># snapshot intermediate results</span>
snapshot: <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">500</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>
这样每 500 iterations就可以得到model_iter_xxx.caffemodel 和model_iter_xxx.solverstate (例如 cifar10_quick_iter_3000.solverstate)。
Step 2:设置运行脚本sh
这样, 设置好了snapshot,在.sh 再设置一下就可以了,使用它来在原有基础上继续训练则设置如下
特别需要注意的是,图中的反斜杠 \ ,如果丢失了 “\” 那么这个选项的设置将会失效!!
以上面的设置为例,snapshot载入成功的话,Ubuntu的终端里显示的迭代次数将是从3000 iterations开始,如果还是从0 iterations开始那就是设置没有成功。
参考:
CAFFE notes