问题
I used Caffe GoogleNet model to train my own data (10k images, 2 classes). I stop it at 400000th iteration with an accuracy of ~80%.
If I run the below command:
./build/examples/cpp_classification/classification.bin
models/bvlc_googlenet/deploy.prototxt
models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
data/ilsvrc12/imagenet_mean.binaryproto
data/ilsvrc12/synset_words.txt
1.png
it gives me a different -- apparently random -- result each time (i.e. if I run it n times, then I get n different results). Why? Does my training fail? Does it still use the old data from the reference model?
回答1:
I don't think it is a problem with the training. Even if the training data wasn't, it should give the same (possibly wrong) output every time. If you are getting random results, it indicates that the weights are not being loaded properly.
When you load a .caffemodel against a .prototxt, caffe will load the weights of all the layers in the prototxt whose names match with the ones in the caffemodel. For the other layers, it will do a random initialisation (gaussian xavier, etc according to the specification in the prototxt).
So the best thing for you to do now is to check if the model was trained using the same prototxt you are using now.
I see that you are using GoogleNet prototxt and reference_caffenet caffemodel. Is this intentional?
回答2:
When you want to deploy the fine-tuned model, you should check two main things:
Inputs:
- Input image uses a BGR channel instead of RGB (e.g. opencv)
- Mean file: Is same as mean file when training?
Prototxt:
- When fintuning the model, you will change some layers' name in the original prototxt, and you should check whether the same layer name used?
And there are some Fine-tune tricks and CS231n_transfer_learning which are very useful for finetuning.
来源:https://stackoverflow.com/questions/38312250/caffe-googlenet-classification-cpp-gives-random-outputs