finetune on caffe
官方例程:http://caffe.berkeleyvision.org/gathered/examples/finetune_flickr_style.html
相应的中文说明:http://blog.csdn.net/liumaolincycle/article/details/48501423
下文链接:https://stackoverflow.com/questions/36841158/fine-tuning-of-googlenet-model
Assuming you are trying to do image classification. These should be the steps for finetuning a model:
1. Classification layer
The original classification layer "loss3/classifier" outputs predictions for 1000 classes (it's mum_output is set to 1000). You'll need to replace it with a new layer with appropriate num_output. Replacing the classification layer:
- Change layer's name (so that when you read the original weights from caffemodel file there will be no conflict with the weights of this layer).
- Change
num_outputto the right number of output classes you are trying to predict. - Note that you need to change ALL classification layers. Usually there is only one, but GoogLeNet happens to have three:
"loss1/classifier","loss2/classifier"and"loss3/classifier".
2. Data
You need to make a new training dataset with the new labels you want to fine tune to. See, for example, this post on how to make an lmdb dataset.
3. How extensive a finetuning you want?
When finetuning a model, you can train ALL model's weights or choose to fix some weights (usually filters of the lower/deeper layers) and train only the weights of the top-most layers. This choice is up to you and it ususally depends on the amount of training data available (the more examples you have the more weights you can afford to finetune).
Each layer (that holds trainable parameters) has param { lr_mult: XX }. This coefficient determines how susceptible these weights to SGD updates. Setting param { lr_mult: 0 }means you FIX the weights of this layer and they will not be changed during the training process.
Edit your train_val.prototxt accordingly.
4. Run caffe
Run caffe train but supply it with caffemodel weights as an initial weights:
~$ $CAFFE_ROOT/build/tools/caffe train -solver /path/to/solver.ptototxt -weights /path/to/orig_googlenet_weights.caffemodel
Fine-tuning is a very useful trick to achieve a promising accuracy compared to past manual feature. @Shai already posted a good tutorial for fine-tuning the Googlenet using Caffe, so I just want to give some recommends and tricks for fine-tuning for general cases.
In most of time, we face a task classification problem that new dataset (e.g. Oxford 102 flower dataset or Cat&Dog) has following four common situations CS231n:
- New dataset is small and similar to original dataset.
- New dataset is small but is different to original dataset (Most common cases)
- New dataset is large and similar to original dataset.
- New dataset is large but is different to original dataset.
In practice, most of time we do not have enough data to train the network from scratch, but may be enough for pre-trained model. Whatever which cases I mentions above only thing we must care about is that do we have enough data to train the CNN?
If yes, we can train the CNN from scratch. However, in practice it is still beneficial to initialize the weight from pre-trained model.
If no, we need to check whether data is very different from original datasets? If it is very similar, we can just fine-tune the fully connected neural network or fine-tune with SVM. However, If it is very different from original dataset, we may need to fine-tune the convolutional neural network to improve the generalization.
参考链接:https://groups.google.com/forum/#!topic/caffe-users/3x82qPZ2f8E
http://www.cnblogs.com/louyihang-loves-baiyan/p/5038758.html
finetune on caffe的更多相关文章
- DL开源框架Caffe | 模型微调 (finetune)的场景、问题、技巧以及解决方案
转自:http://blog.csdn.net/u010402786/article/details/70141261 前言 什么是模型的微调? 使用别人训练好的网络模型进行训练,前提是必须和别人 ...
- Caffe学习系列(13):对训练好的模型进行fine-tune
使用http://www.cnblogs.com/573177885qq/p/5804863.html中的图片进行训练和测试. 整个流程差不多,fine-tune命令: ./build/tools/c ...
- caffe进行finetune时出现"shapeequals(proto) shape mismatch (reshape not set)"的解决办法
声明:加载的caffemodel会根据你的net.prototxt文件里的各个layer的name来进行参数赋值. 错误:[Caffe]: Check failed: ShapeEquals(prot ...
- 【转】Caffe初试(十)命令行解析
caffe的运行提供三种接口:C++接口(命令行).Python接口和matlab接口.本文先对命令行进行解析,后续会依次介绍其它两种接口. caffe的C++主程序(caffe.cpp)放在根目录下 ...
- finetuning caffe
还没解决,以下是解释fine-tune 比如说,先设计出一个CNN结构.然后用一个大的数据集A,训练该CNN网络,得到网络a.可是在数据集B上,a网络预测效果并不理想(可能的原因是数据集A和B存在一些 ...
- caffe使用
训练时, solver.prototxt中使用的是train_val.prototxt ./build/tools/caffe/train -solver ./models/bvlc_referenc ...
- caffe: test code for PETA dataset
test code for PETA datasets .... #ifdef WITH_PYTHON_LAYER #include "boost/python.hpp" name ...
- 转:谷歌大脑科学家 Caffe缔造者 贾扬清 微信讲座完整版
[转:http://blog.csdn.net/buaalei/article/details/46344675] 大家好!我是贾扬清,目前在Google Brain,今天有幸受雷鸣师兄邀请来和大家聊 ...
- Chapter 3 Start Caffe with MNIST Demo
先从一个具体的例子来开始Caffe,以MNIST手写数据为例. 1.下载数据 下载mnist到caffe-master\data\mnist文件夹. THE MNIST DATABASE:Yann L ...
随机推荐
- Spring Cloud(十):服务网关 Zuul(路由)【Finchley 版】
Spring Cloud(十):服务网关 Zuul(路由)[Finchley 版] 发表于 2018-04-23 | 更新于 2018-05-09 | 通过之前几篇 Spring Cloud 中 ...
- [C++] OOP - Base and Derived Classes
There is a base class at the root of the hierarchy, from which the other class inherit, directly or ...
- return语句的用法
1.return语句的作用:a.返回一个值,这个值可以是任意类型.b.使程序返回到操作系统(即终止程序)2.java中对于一个函数,不论有没有返回值类型,都可以带有return 语句.但是区别在于,r ...
- scrapy(2)——scrapy爬取新浪微博(单机版)
Sina爬虫教程 Scrapy环境搭建 环境:window10 + python2.7(包含scrapy)+ mongoDB 1.1 安装集成了python2.7的anaconda ana ...
- 3dContactPointAnnotationTool开发日志(六)
一种可行的思路就是枚举一个模型的三角面片,然后判断三角形是否与另一个物体相交即可.为了让效果更好我想只渲染模型的线框. 在网上查了半天好像Unity里都没有自带的方便的渲染线框的方式,我又自己 ...
- 关于FEer发展方向的思考
今天学习了HTTP权威指南这本书,虽然标题是对FEer发展的思考,不过我打算稍后再说这个议题,先对今天学习的内容做个总结. 首先:原来访问服务器的方式有多重,核心是URI,也就是统一资源定位,按照访问 ...
- xpath教程二 ---- 通过ID和Class检索
必备知识点 在html中,id是唯一的 在html中,class是可以多处引用的 工具 Python3版本 lxml库[优点是解析快] HTML代码块[从网络中获取或者自己杜撰一个] requests ...
- 【Docker】- 基本命令
1.docker ps -a 显示所有容器 2.doker ps -l 显示最近一次启动的容器 3.docker ps 显示正在运行的容器 4.docker start [容器ID] 启动 ...
- 检测固定IP的端口是否开放批出
因为运维工作经常需要telnet某个IP的端口是否正常,因此有了下文 .BAT内容如下: @echo off for /f %%i in ('type ip.txt') do ( echo %%i t ...
- DEDE去掉会员登录及注册验证码的方法
1.登录打开member/index_do.php 删除245-250行,即: if(strtolower($vdcode)!=$svali || $svali=='') { ResetVdValue ...