caffe简易上手指南(三)—— 使用模型进行fine tune
来源:互联网 发布:total recall mac 编辑:程序博客网 时间:2024/05/17 22:32
caffe简易上手指南(三)—— 使用模型进行fine tune
之前的教程我们说了如何使用caffe训练自己的模型,下面我们来说一下如何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 windows 下进行(微调)fine-tune 模型
- 使用caffe fine-tune一个单标签图像分类模型
- 使用caffe fine-tune一个单标签图像分类模型
- 使用caffe fine-tune一个单标签图像分类模型
- caffe深度学习(一)fine-tune
- caffe fine-tune策略
- Caffe之fine tune
- caffe 学习之 Fine-tune
- caffe上手2:使用INRIA行人数据集对BVLC Caffe进行fine-tuning
- caffe上手:使用INRIA行人数据集对BVLC Caffe进行fine-tuning
- Keras入门-预训练模型fine-tune(ResNet)
- 在caffe上做FCN模型fine-tune的一些注意事项
- keras入门 ---在预训练好网络模型上进行fine-tune
- SSD Faster-RCNN使用自己的数据fine-tune训练模型
- caffe简易上手—— 运行cifar例子
- pytorch学习笔记(十一):fine-tune 预训练的模型
- 删除mysql后再次安装报错
- Redis事务
- Android热修复技术(二)------代码修复之底层替换原理
- 树莓派ubuntu mate 使能摄像头
- java虚拟机对锁优化所做的努力
- caffe简易上手指南(三)—— 使用模型进行fine tune
- leetcode 65. Valid Number
- 葵花宝典 十三 EL表达式
- Spark性能调优之数据倾斜调优一站式解决方案原理与实战
- Spring事物介绍
- Mysql net start mysql启动,提示发生系统错误 5 拒绝访问
- linux忘记了密码怎么办
- Windows编程之旅(二)
- PHP学习之Pimple运行流程详解