caffe-cmd

some cmd

cifar-10 tutorial

  1. download the binary data
    1
    ./data/cifar10/get_cifar.sh

download:
batches.meta.txt data_batch_2.bin data_batch_4.bin get_cifar10.sh test_batch.bin
data_batch_1.bin data_batch_3.bin data_batch_5.bin readme.html

  1. convert binary data into leveldb format
    1
    2
    3
    4
    5
    6
    ./examples/cifar10/create_cifar10.sh
    % calling:
    ./examples/cifar/convert_cifar_data.bin <folder storing the binary data> <pat to store the db file>

    compute the image mean:
    ./build/tools/compute_image_mean -backend=lmdb <folder of db file> <outputfile: mean.binaryproto>

train caffe from CMD:

http://vision.princeton.edu/courses/COS598/2015sp/slides/Caffe/caffe_tutorial.pdf

1
2
3
4
5
./train_lenet.sh

TOOLS=../../build/tools
GLOG_logtostderr=1 $TOOLS/train_net.bin
lenet_solver.prototxt

fine tuning

1
2
3
4
5
caffe train —solver models/finetune_flickr_style/solver.prototxt —weights bvlc_reference_caffenet.caffemodel

//net = new Caffe::Net("style_solver.prototxt");
//net.CopyTrainedNetFrom(pretrained_model);
//solver.Solve(net);

extracting features:

1
2
build/tools/extract_features.bin imagenet_model
imagenet_val.prototxt fc7 temp/features(output file) 10(batch size)

a paper about the batch size

add layer:

implement xx_layer.cpp
forward_cpu
backward_cpu
setup

select data

1
2
3
4
5
6
// get the file list of the image in folder _temp
find `pwd`/examples/images -type f -exec echo {} \; > examples/_temp/temp.txt


sed "s/$/ 0/" examples/_temp/temp.txt > examples/_temp/file_list.txt
// The ImageDataLayer we’ll use expects labels after each filenames,

creating lmdb from data

1
./examples/cifar10/convert_cifar_data.bin path/to/data ./examples/cifar10 lmdb

get the mean image

1
2
./build/tools/compute_image_mean -backend=lmdb ./example/cifar10_train_lmdb ./example/mean.binaryproto
// get: data/ilsvrc212/imagenet_mean.binaryproto

subtracting the mean image from a dataset significantly improves classification accuracies. Download the mean image of the ILSVRC dataset.

run

1
./tools/extract_features models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel examples/_temp/imagenet_val.prototxt fc7 examples/_temp/features 10 lmdb

train.sh

1
2
3
4
5
// train_full.sh -- for cifar1000?
$TOOLS/caffe train \
--solver=examples/cifar10/cifar10_full_solver.prototxt
// The train/test net protocol buffer definition
// net: "examples/cifar10/cifar10_full_train_test.prototxt"
1
2
3
4
5
6
// train_quick.sh

$TOOLS/caffe train \
--solver=examples/cifar10/cifar10_quick_solver.prototxt
//net: "examples/cifar10/cifar10_quick_train_test.prototxt"
--snapshot=examples/cifar10/cifar10_full_iter_60000.solverstate.h5