Sunday, October 18, 2015

MNIST + Caffe

(http://caffe.berkeleyvision.org/gathered/examples/mnist.html)

cd $CAFFE_ROOT
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh

Define MNIST Network


layers are defined in lenet_train_test.prototxt under $CAFFE_ROOT/examples/mnist/

protocol buffers – a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more.
It represents a serialized data structure, saved in .proto file. It is better than XML. (https://developers.google.com/protocol-buffers/docs/overview)

  • are simpler
  • are 3 to 10 times smaller
  • are 20 to 100 times faster
  • are less ambiguous
  • generate data access classes that are easier to use programmatically













The protobuf for Caffe is stored in  $CAFFE_ROOT/src/caffe/proto/caffe.proto
A Blob is a wrapper over the actual data being processed and passed along by Caffe, and also under the hood provides synchronization capability between the CPU and the GPU. Mathematically, a blob is an N-dimensional array stored in a C-contiguous fashion.

lr_mults are the learning rate adjustments for the layer’s learnable parameters. In this case, we will set the weight learning rate to be the same as the learning rate given by the solver during runtime, and the bias learning rate to be twice as large as that - this usually leads to better convergence rates. (http://caffe.berkeleyvision.org/gathered/examples/mnist.html)

MNIST Solver

$CAFFE_ROOT/examples/mnist/lenet_solver.prototxt


Training and Testing the Model

cd $CAFFE_ROOT
./examples/mnist/train_lenet.sh


Data Flow In Details

[step 1]
~/caffe/tools/caffe.cpp
read the command line, calling ~/caffe/src/caffe/common.cpp
[step 2]
~/caffe/src/caffe/solver.cpp, initializing solver from parameters
[step 3]
solver creates a training net from net file: examples/mnist/lenet_train_test.prototxt
[step 4]
net.cpp, StateMeetsRule() function,
Caffe::root_solver(), Initializing net from parameters
[step 5]
In ~/caffe/include/caffe/layer_factory.hpp, CreateLayer() function
[step 6]
~/caffe/src/caffe/net.cpp
 LOG(INFO) << layer_param->name() << " -> " << blob_name;
[step 7]
read lmdb
[step 8]
set up mnist
    LOG_IF(INFO, Caffe::root_solver())
        << "Creating Layer " << layer_param.name();

[step 7]



time to create train and test networks :
21:32:45.919808 -  21:32:46.008837     Network initialization done.
less than 1 second

start optimization till the 10000 iterations
21:32:46.009042 -  21:33:24.866451     Optimization done.
39 seconds on GTX 760 using cuDNN

No comments:

Post a Comment