官方例程: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:

  1. 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).
  2. Change num_output to the right number of output classes you are trying to predict.
  3. 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:

  1. New dataset is small and similar to original dataset.
  2. New dataset is small but is different to original dataset (Most common cases)
  3. New dataset is large and similar to original dataset.
  4. 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的更多相关文章

  1. DL开源框架Caffe | 模型微调 (finetune)的场景、问题、技巧以及解决方案

    转自:http://blog.csdn.net/u010402786/article/details/70141261 前言 什么是模型的微调?   使用别人训练好的网络模型进行训练,前提是必须和别人 ...

  2. Caffe学习系列(13):对训练好的模型进行fine-tune

    使用http://www.cnblogs.com/573177885qq/p/5804863.html中的图片进行训练和测试. 整个流程差不多,fine-tune命令: ./build/tools/c ...

  3. caffe进行finetune时出现"shapeequals(proto) shape mismatch (reshape not set)"的解决办法

    声明:加载的caffemodel会根据你的net.prototxt文件里的各个layer的name来进行参数赋值. 错误:[Caffe]: Check failed: ShapeEquals(prot ...

  4. 【转】Caffe初试(十)命令行解析

    caffe的运行提供三种接口:C++接口(命令行).Python接口和matlab接口.本文先对命令行进行解析,后续会依次介绍其它两种接口. caffe的C++主程序(caffe.cpp)放在根目录下 ...

  5. finetuning caffe

    还没解决,以下是解释fine-tune 比如说,先设计出一个CNN结构.然后用一个大的数据集A,训练该CNN网络,得到网络a.可是在数据集B上,a网络预测效果并不理想(可能的原因是数据集A和B存在一些 ...

  6. caffe使用

    训练时, solver.prototxt中使用的是train_val.prototxt ./build/tools/caffe/train -solver ./models/bvlc_referenc ...

  7. caffe: test code for PETA dataset

    test code for PETA datasets .... #ifdef WITH_PYTHON_LAYER #include "boost/python.hpp" name ...

  8. 转:谷歌大脑科学家 Caffe缔造者 贾扬清 微信讲座完整版

    [转:http://blog.csdn.net/buaalei/article/details/46344675] 大家好!我是贾扬清,目前在Google Brain,今天有幸受雷鸣师兄邀请来和大家聊 ...

  9. Chapter 3 Start Caffe with MNIST Demo

    先从一个具体的例子来开始Caffe,以MNIST手写数据为例. 1.下载数据 下载mnist到caffe-master\data\mnist文件夹. THE MNIST DATABASE:Yann L ...

随机推荐

  1. Django - day00 第一个页面

    Django - day00 0.写在最前面 第一次接触Django,是在大三的做数据库课程设计的时候,当时好像还是1.8的版本,现转眼就到了2.0的版本. 当时由于没太多的课,仅花了不到一周的时间就 ...

  2. mysql bin log配置及查看

    mysql执行sql可以通过设置mysql bin 日志进行记录查看   mysql bin日志配置如下:   log_bin:on log_bin_basename:bin文件路径及名前缀(/var ...

  3. 【WXS数据类型】Number

    Number包括整数与小数. 属性: 名称 返回 说明 [Number].constructor 值为字符串“Number” 返回该类型的结构字符串 方法: 原型:[Number].toString( ...

  4. 【halcon】算子

    算子 rgb1_to_gray  灰度化 threshold:英文是阈的意思    二值化算子 Connection Compute connected components of a region. ...

  5. IMX6移植htop

    top命令查看CPU利用率并不是很方便,因此打算移植htop到imx6上,主要包括以下几个步骤: - 资源下载 htop 下载http://hisham.hm/htop/releases/1.0.1/ ...

  6. HDU 2490 Parade(DPの单调队列)(2008 Asia Regional Beijing)

    Description Panagola, The Lord of city F likes to parade very much. He always inspects his city in h ...

  7. 《剑指Offer》题一~题十

    一.赋值运算符函数 题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString { public: CMyString(char *pData = nul ...

  8. c# byte[] 保存图片

    1.用函数即可,File.WriteAllBytes(@"E:\123.bmp", pcBMPBuffer); 2.byte[]也可和image互相转化.

  9. tabales1.10版参数详解

    //@translator codepiano //@blog codepiano //@email codepiano.li@gmail.com //尝试着翻译了一下,难免有错误的地方,欢迎发邮件告 ...

  10. java文件操作(普通文件以及配置文件的读写操作)

    转自:java文件操作(普通文件以及配置文件的读写操作) 读取普通文件 : /** * xiangqiao123欢迎你 如果对代码有疑问可以加qq群咨询:151648295 * * 读取MyFile文 ...