前面做好了lmdb和均值文件,下面以Googlenet为例修改网络并训练模型。
我们将caffe-master\models下的bvlc_googlenet文件夹复制到caffe-master\examples\imagenet下。(因为我们的lmdb和均值都在这里,放一起方便些)
打开train_val.txt,修改:
1.修改data层:
由于Googlenet有三个输出,所以改三个地方,其他网络一般只有一个输出,则改一个地方即可。
如果是微调,那么输出层的层名也要修改。(参数根据层名来初始化,由于输出改了,该层参数就不对应了,因此要改名)
如果是微调,该层层名和train_val.prototxt修改一致。
接着,打开solver,修改:
这时,我们回到caffe-master\examples\imagenet下,打开train_caffenet.sh,修改:
(如果是微调,在脚本里加入-weights **/**/**.caffemodel即可,即用来微调的caffemodel路径)
(如果有多个GPU,可自行选择)
然后,在caffe-master下执行改脚本即可开始训练:$caffe-master ./examples/imagenet/train_caffenet.sh
训练得到的caffemodel就可以用来做图像分类了,此时,需要(1)得到的labels.txt,(2)得到的mydata_mean.binaryproto,(3)得到的caffemodel以及已经修改过的deploy.prototxt,共四个文件,具体过程看:http://blog.csdn.net/sinat_30071459/article/details/50974695