0、参考文献
[1]https://github.com/ouceduxzk/Fine_Grained_Classification/tree/master/codes
[2]http://blog.csdn.net/lynnandwei/article/details/44458033
1.
install caffe
download bvlc_googlenet.caffemodel
http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel
download images into the cars_train and cars_test folder under the prepare folder
http://ai.stanford.edu/~jkrause/cars/car_dataset.html
2.
in the prepare folder, change the directory of train_path and test_path to your own path
run : python preprocessing.py, which will generate the crop_train and crop_test
train_path = 'D:/caffe_test/caffe-master/fine_grained/cars_train/'
train_files = os.listdir(train_path)
train_files = [ f for f in train_files if f.endswith('jpg')]
test_path = 'D:/caffe_test/caffe-master/fine_grained/cars_test/'
test_files = os.listdir(test_path)
遇到unindent的报错的话,用Notepad解决,具体参考https://www.crifan.com/python_syntax_error_indentationerror/
结果:
![](https://img-blog.csdn.net/20171010213746715?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
3.
sh pre.sh , which will call caffe to save the images into a database
#!/bin/bash
D:/caffe_test/caffe-master/Build/x64/Release/convert_imageset D:/caffe_test/caffe-master/fine-grained/crop_train/ train2.txt ./train -resize_width=227 -resize_height=227 -check_size -shuffle true
D:/caffe_test/caffe-master/Build/x64/Release/convert_imageset D:/caffe_test/caffe-master/fine-grained/crop_test/ test2.txt ./test -resize_width=227 -resize_height=227 -check_size -shuffle true
结果:
4.
change the path in the models/finetuen_car/train_val.prototxt into the path of your db
layer {
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
mirror: true
crop_size: 224
mean_value: 104
mean_value: 117
mean_value: 123
}
data_param {
source: "D:/caffe_test/caffe-master/fine-grained/train/"
batch_size: 32
backend: LMDB
}
}
layer {
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
mirror: false
crop_size: 224
mean_value: 104
mean_value: 117
mean_value: 123
}
data_param {
source: "D:/caffe_test/caffe-master/fine-grained/test/"
batch_size: 50
backend: LMDB
}
}
5.
sh run.sh, the models will be saved in the models directory
solver.prototxt:
net: "D:/caffe_test/caffe-master/fine-grained/train_val.prototxt"
test_iter: 100
test_interval: 400
test_initialization: false
display: 20
base_lr: 0.001
lr_policy: "step"
stepsize: 10000
gamma: 0.1
max_iter: 50000
momentum: 0.9
weight_decay: 0.0005
snapshot: 1000
snapshot_prefix: "D:/caffe_test/caffe-master/fine-grained/car_googlenet"
solver_mode: GPU
run.sh:
#!/bin/bash
D:/caffe_test/caffe-master/Build/x64/Release/caffe train --solver D:/caffe_test/caffe-master/fine-grained/solver.prototxt --weights D:/caffe_test/caffe-master/fine-grained/bvlc_googlenet.caffemodel --gpu 0
结果:
一直遇到*** Check failure stack trace: ***的问题,但是路径都没错啊,目前没解决。
不知道是不是Windows不好跑的原因,我放到Linux上就通过了,汗……
6.
hyper parameters are in solver.prototxt file and you can play with that .