how to load reference .caffemodel for training

2019-07-12 20:34发布

问题:

I'm using alexnet to train my own dataset. The example code in caffe comes with

bvlc_reference_caffenet.caffemodel
solver.prototxt
train_val.prototxt
deploy.prototxt

When I train with the following command:

./build/tools/caffe train --solver=models/bvlc_reference_caffenet/solver.prototxt

I'd like to start with weights given in bvlc_reference.caffenet.caffemodel.

My questions are

  1. How do I do that?

  2. Is it a good idea to start from the those weights? Would this converge faster? Would this be bad if my data are vastly different from the Imagenet dataset?

回答1:

1.
In order to use existing .caffemodel weights for fine-tuning, you need to use --weights command line argument:

./build/tools/caffe train --solver=models/bvlc_reference_caffenet/solver.prototxt --weights=models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel 

2.
In most cases fine-tuning a net is quite a recommended practice, even when the input images are quite different than "imagenet" photos.
However, you should note that when training for the original weights you are about to use, some (very reasonable) assumptions were made. You should decide whether these assumptions are still true for your task.
For instance, most nets were trained with simple data augmentation using an image and its horizontal flip. However, if your task is to distinguish between images that are flipped you will find it very difficult to fine tune.