caffe使用预训练的模型进行finetune--caffe学习(1)
2016-12-30 20:27
931 查看
首先明确预训练好的模型和自己的网络结构是有差异的,预训练模型的参数如何跟自己的网络匹配的呢:
参考官网教程:http://caffe.berkeleyvision.org/gathered/examples/finetune_flickr_style.html
–If we provide the weights argument to the caffe train command, the pretrained weights will be loaded into our model, matching layers by name.
意思就是预训练的模型根据你当前网络的layer 名进行匹配参数,加入预训练原始网络的第一个卷积层name是conv1,而你自己的第一个卷积层网络name是Convolution1,那么这个层在预网络中的参数就不会被匹配调用,这就没有实现我们finetune的目的!
因为没有匹配上的layer会这样处理:Since there is no layer named that in the bvlc_reference_caffenet, that layer will begin training with random weights.也就是随机初始化
原来网络结构中的全连接层fc8, 需要改一下名字,如我的改成”re-fc8”. 因为我们做的是微调。微调的意思就是先在别的数据集上进行训练,把训练好的权值,作为我们现在数据集的权值初始化,就不再需要随机初始化了。现在的数据和训练时的数据不一致,因此有些层数的设置就会有点区别。比如这个例子中,用来训练模型的数据集是imagenet,分为1000类,而我们的数据集就只有5类,因此在fc8这层上的num_output就会有区别,因此在这一层上就不能用人家的权值了,就需要把这层的名字改得和原来的网络结构不一样。
因此我们在finetune的时候一般同时使用模型和模型对应的训练网络结构,保证所有参数被正确加载和调用
常见的fintune基础思路:We will also decrease the overall learning rate base_lr in the solver prototxt, but boost the lr_multon the newly introduced layer. The idea is to have the rest of the model change very slowly with new data, but let the new layer learn fast. Additionally, we set stepsize in the solver to a lower value than if we were training from scratch, since we’re virtually far along in training and therefore want the learning rate to go down faster. Note that we could also entirely prevent fine-tuning of all layers other than fc8_flickr by setting their lr_mult to 0.
常用pre-trained模型下载地址:https://github.com/BVLC/caffe/wiki/Model-Zoo
更多可参考:http://www.cnblogs.com/denny402/p/5137534.html
一些实际finetune的建议:http://blog.csdn.net/nongfu_spring/article/details/51514040
参考官网教程:http://caffe.berkeleyvision.org/gathered/examples/finetune_flickr_style.html
–If we provide the weights argument to the caffe train command, the pretrained weights will be loaded into our model, matching layers by name.
意思就是预训练的模型根据你当前网络的layer 名进行匹配参数,加入预训练原始网络的第一个卷积层name是conv1,而你自己的第一个卷积层网络name是Convolution1,那么这个层在预网络中的参数就不会被匹配调用,这就没有实现我们finetune的目的!
因为没有匹配上的layer会这样处理:Since there is no layer named that in the bvlc_reference_caffenet, that layer will begin training with random weights.也就是随机初始化
原来网络结构中的全连接层fc8, 需要改一下名字,如我的改成”re-fc8”. 因为我们做的是微调。微调的意思就是先在别的数据集上进行训练,把训练好的权值,作为我们现在数据集的权值初始化,就不再需要随机初始化了。现在的数据和训练时的数据不一致,因此有些层数的设置就会有点区别。比如这个例子中,用来训练模型的数据集是imagenet,分为1000类,而我们的数据集就只有5类,因此在fc8这层上的num_output就会有区别,因此在这一层上就不能用人家的权值了,就需要把这层的名字改得和原来的网络结构不一样。
因此我们在finetune的时候一般同时使用模型和模型对应的训练网络结构,保证所有参数被正确加载和调用
常见的fintune基础思路:We will also decrease the overall learning rate base_lr in the solver prototxt, but boost the lr_multon the newly introduced layer. The idea is to have the rest of the model change very slowly with new data, but let the new layer learn fast. Additionally, we set stepsize in the solver to a lower value than if we were training from scratch, since we’re virtually far along in training and therefore want the learning rate to go down faster. Note that we could also entirely prevent fine-tuning of all layers other than fc8_flickr by setting their lr_mult to 0.
常用pre-trained模型下载地址:https://github.com/BVLC/caffe/wiki/Model-Zoo
更多可参考:http://www.cnblogs.com/denny402/p/5137534.html
一些实际finetune的建议:http://blog.csdn.net/nongfu_spring/article/details/51514040
相关文章推荐
- 深度学习Caffe平台实例——CIFAR-10数据集在caffe平台上模型训练及实例使用模型进行预测
- 【神经网络与深度学习】Caffe使用step by step:使用自己数据对已经训练好的模型进行finetuning
- Caffe学习:使用pycaffe进行网络训练与测试
- 使用Caffe训练适合自己样本集的AlexNet网络模型,并对其进行分类
- caffe学习--使用caffe中的imagenet对自己的图片进行分类训练(超级详细版) -----linux
- 【Caffe的C++接口使用说明(三)】Ubuntu14.04下Caffe利用训练好的模型进行分类的C++接口使用说明(三)
- caffe学习笔记(五)--使用自己的数据集第一次进行训练
- 【caffe】c++中使用训练好的caffe模型,classification工程生成动态链接库——【caffe学习六】
- caffe2:使用训练好的模型进行训练(使用mnist模型)
- 使用MATLAB加载训练好的caffe模型进行识别分类
- Caffe使用step by step:使用自己数据对已经训练好的模型进行finetuning
- 深度学习文章5:使用caffe对自己的图像数据进行训练并测试
- 【深度学习】笔记6:使用caffe中的CIFAR10网络模型和自己的图片数据训练自己的模型(步骤详解)
- caffe+python 使用训练好的VGG16模型 对 单张图片进行分类,输出置信度
- Caffe学习3-使用预训练模型finetuning
- 使用caffe训练好的模型进行分类
- caffe的python接口学习(9):Caffe在Python中使用内存数据(MemoryData)进行训练
- 使用三种继承回归模型对美国波士顿房价训练数据进行学习,并对测试数据进行预测
- caffe+python 使用训练好的VGG16模型 对 单张图片进行分类,输出置信度
- Caffe使用step by step:使用自己数据对已经训练好的模型进行finetuning