Caffe_Windows学习笔记(七)细粒度图像分类

来源:互联网 发布:c语言左移和右移 编辑:程序博客网 时间:2024/06/05 00:07

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/

结果:




3.

sh pre.sh , which will call caffe to save the images into a database

#!/bin/bashD:/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 trueD:/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: 100test_interval: 400test_initialization: falsedisplay: 20base_lr: 0.001lr_policy: "step"stepsize: 10000gamma: 0.1max_iter: 50000momentum: 0.9weight_decay: 0.0005snapshot: 1000snapshot_prefix: "D:/caffe_test/caffe-master/fine-grained/car_googlenet"solver_mode: GPU

run.sh:

#!/bin/bashD:/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 .

阅读全文
0 0
原创粉丝点击