打开train_val.prototxt文件,修改name,输出类别数,两个lr_mult均扩大十倍,因为我们主要训练最后一层
layer { name: "fc8_15" type: "InnerProduct" bottom: "fc7" top: "fc8_15" param { lr_mult: 10 decay_mult: 1 } param { lr_mult: 20 decay_mult: 0 } inner_product_param { num_output: 15 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } } layer { name: "accuracy" type: "Accuracy" bottom: "fc8_15" bottom: "label" top: "accuracy" include { phase: TEST } } layer { name: "loss" type: "SoftmaxWithLoss" bottom: "fc8_15" bottom: "label" top: "loss" }
然后下载预训练的模型bvlc_reference_caffenet.caffemodel放入自己设置的文件夹下,在终端运行:
cd caffe #进入caffe根目录
./build/tools/caffe train --solver=/home/qf/git/myfile/bvlc_reference_caffenet/solver.prototxt --weights=./models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
即可!!!!
若直接在终端测试网络,可直接运行:
./build/tools/caffe test --solver=/home/qf/git/myfile/bvlc_reference_caffenet/solver.prototxt --weights=/home/qf/git/myfile/bvlc_reference_caffenet/my_bvlc_reference_caffenet.caffemodel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
以下为个人理解:
题外话1:如训练网络时不想将txt文件转换为lmdb文件也是可以的,在train_val.prototxt文件中前两层的输入类型由Data改为ImageData,同时将输入的train_lmdb和val_lmdb换成txt文件。
题外话2:我们训练时使用的train_val.prototxt文件前两部分是TRAIN 和TEST,如果我们的train 和val数据集图像不重合,则在训练过程中已经进行了分类测试。一般情况下验证集图像是训练集图像的一部分,这时,在使用测试集测试时,可以在train_val.prototxt文件中加一层,然后训练和测试时改一下solver.prototxt 就好了。