Fine Tuning of GoogLeNet Model

10,794

Solution 1

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 

Solution 2

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.

Share:
10,794

Related videos on Youtube

Ashutosh Singla
Author by

Ashutosh Singla

I am Ashutosh Singla, Master of Science in Communications Engineering from RWTH Aachen University, Germany. I am currently pursuing a PhD degree from the Institute of Media Technology at TU Ilmenau, Germany. Since September 2016, I am an active member of Audiovisual Technology Group (AVT) in the IMT of the university. My research interest includes: Image and Video Coding/Processing, 3D Video Coding, Virtual Reality, and Deep Learning 7+ years' research and development experience in image and video coding/processing and authored/co-authored 12+ papers Proficiency in C/C++, Matlab programming

Updated on January 19, 2022

Comments

  • Ashutosh Singla
    Ashutosh Singla over 2 years

    I trained GoogLeNet model from scratch. But it didn't give me the promising results.
    As an alternative, I would like to do fine tuning of GoogLeNet model on my dataset. Does anyone know what are the steps should I follow?

  • Ashutosh Singla
    Ashutosh Singla about 8 years
    Thanks a lot Shai for your reply. Could you also tell me how can I get the pre-trained GoogLeNet model? I used the link given below to download the pre-trained model. dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel
  • Shai
    Shai about 8 years
    @AshutoshSingla look in caffe model zoo
  • Ashutosh Singla
    Ashutosh Singla about 8 years
    I did the fine tunning but the results are not promising. I am only getting the accuracy of 50% after 1000 iterations. My training dataset has 3k images validation has 1k images and evaluation has 1k images. I set the base_lr to 0.001 and max_itr to 10000. Is this accuracy normal or did I do something wrong? I can also share what changes I did in the files, if needed. @shai do you have any suggestions?
  • Shai
    Shai almost 4 years
    @AshutoshSingla you'll have to be more specific. If you have a new question you should ask.

Related