caffe深度学习(一)fine-tune
来源:互联网 发布:淘宝网蓝月亮洗衣液 编辑:程序博客网 时间:2024/06/05 12:02
转自:http://www.cnblogs.com/alexcai/p/5469478.html
我们来说一下如何fine tune。
所谓fine tune就是用别人训练好的模型,加上我们自己的数据,来训练新的模型。fine tune相当于使用别人的模型的前几层,来提取浅层特征,然后在最后再落入我们自己的分类中。
fine tune的好处在于不用完全重新训练模型,从而提高效率,因为一般新训练模型准确率都会从很低的值开始慢慢上升,但是fine tune能够让我们在比较少的迭代次数之后得到一个比较好的效果。在数据量不是很大的情况下,fine tune会是一个比较好的选择。但是如果你希望定义自己的网络结构的话,就需要从头开始了。
这里采用一个实际的例子,钱币分类
1、我们收集了2W张图片,将其中4000张作为测试集,剩下作为训练集。
2、接着我们使用上一篇博客中的方法,生成words.txt、train.txt、test.txt三个文件,这里可以不用生成lmdb,因为caffe支持直接指定图片文件。
3、编辑配置文件,这里我们参考finetune_flickr_style例子(它是用caffenet的训练结果进行finetune的),拷贝其配置文件:
solver.prototxt
net: "examples/money_test/fine_tune/train_val.prototxt"test_iter: 20test_interval: 50base_lr: 0.001lr_policy: "step"gamma: 0.1stepsize: 2000display: 1max_iter: 10000momentum: 0.9weight_decay: 0.0005snapshot: 1000snapshot_prefix: "examples/money_test/fine_tune/finetune_money"solver_mode: CPU
train_val.prototxt
其实fine tune使用的网络跟原有网络基本一样,只不过每层调整了一些参数,具体可以参照finetune_flickr_style和caffenet网络配置的对比
name: "FlickrStyleCaffeNet"layer { name: "data" type: "ImageData" top: "data" top: "label" include { phase: TRAIN } transform_param { mirror: true crop_size: 227 mean_file: "data/ilsvrc12/imagenet_mean.binaryproto" } image_data_param { source: "examples/money_test/data/train.txt" batch_size: 50 new_height: 256 new_width: 256 }}layer { name: "data" type: "ImageData" top: "data" top: "label" include { phase: TEST } transform_param { mirror: false crop_size: 227 mean_file: "data/ilsvrc12/imagenet_mean.binaryproto" } image_data_param { source: "examples/money_test/data/test.txt" batch_size: 50 new_height: 256 new_width: 256 }}..........layer { name: "fc8_flickr" type: "InnerProduct" bottom: "fc7" top: "fc8_flickr" # lr_mult is set to higher than for other layers, because this layer is starting from random while the others are already trained param { lr_mult: 10 decay_mult: 1 } param { lr_mult: 20 decay_mult: 0 } inner_product_param { num_output: 17 #这里我们的分类数目 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } }}.....
deploy.prototxt
用于实际分类时的网络
.........layer { name: "fc8_flickr" type: "InnerProduct" bottom: "fc7" top: "fc8_flickr" # lr_mult is set to higher than for other layers, because this layer is starting from random while the others are already trained param { lr_mult: 10 decay_mult: 1 } param { lr_mult: 20 decay_mult: 0 } inner_product_param { num_output: 17 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } }}...........
4、开始训练
./build/tools/caffe train -solver examples/money_test/fine_tune/solver.prototxt -weights models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
其中model指定的是caffenet训练好的model。
使用fine tune的效果比较好,经过3400多次迭代后,测试集上正确率达到92%(可以更高),实际测试效果也比较理想。这也许就是深度学习的优势,不需要仔细地挑选特征,只要数据足够,也能得到不错的效果。
- caffe深度学习(一)fine-tune
- caffe 学习之 Fine-tune
- caffe fine-tune策略
- Caffe之fine tune
- Caffe windows 下进行(微调)fine-tune 模型
- caffe— 使用模型进行fine tune
- caffe简易上手指南(三)—— 使用模型进行fine tune
- 使用caffe fine-tune一个单标签图像分类模型
- 使用caffe fine-tune一个单标签图像分类模型
- 使用caffe fine-tune一个单标签图像分类模型
- Caffe fine-tuning 学习
- 迁移学习(transfer learning)和微调(fine-tune)的几点认识
- pytorch学习笔记(十一):fine-tune 预训练的模型
- 【深度学习】caffe结构解析(一)
- 深度学习fine-tuning
- fine-tune convolutional network
- digits fine-tune方法
- tensorflow & keras fine tune
- Git撤销&回滚操作
- 郭霖大神的LitePal版本历程
- VO、 PO、DO、DTO、 BO、 QO、DAO、POJO在开发项目中概念
- cordova 在APP内打开
- 文章标题
- caffe深度学习(一)fine-tune
- 话说对ubuntu不同环境变量的切换问题和apm编译的后续
- 玩转java多线程学习篇四 Thread类的常用API之currentThread,isAlive,sleep,interrupt,isInterrupted,stop
- TComPicYuv、TComPic、TComPicSym、TComDataCU以及TComYuv的关系
- 撸了隔壁的网,满足一下窝的偷窥癖
- php编译安装升级
- 锁(三) 完成量
- 复习UNITY3D网络模块UNET
- angularjs指令中的compile与link函数详解