caffe 入門(一)- before start: protobuf

For some reasons I have to deal with Caffe next week. So lets leave MXNet for couple of weeks and start with Caffe : (

Caffe, unlike Tensorflow and MXNet, is not a symbolic programming framework. One pro is by using protobuf, Caffe requires less coding efforts.

Installation:

  1. install dependency as guided Caffe | Installation
  2. git clone caffe repository to local BVLC/caffe
  3. under Caffe root directory

$mkdir build$cd build$cmake ..$make all$make test$make runtest

Example - MNIST

Using Caffe is simple. With prototypeMNIST demos are under cafferoot/examples/mnist. Simply run demo following the official readme.md to understand usage of Caffe prototxt.

what is protobuf Google Protocol Buffer 的使用和原理

NN model is defined in XXX.prototxt, parameters of the model are defined in XXX_solver.prototxt.

Proto format could be found in cafferoot/src/caffe/proto/caffe.proto. After Caffe has been compiled the protos outputs caffe.pb.cc and caffe.pb.h are in cafferoot/build/include/caffe/proto.

Solver

Basically XXX_solver.prototxt defines solverparameter message in caffe.proto.

//XXX_solver.prototxt# The train/test net protocol buffer definitionnet: "examples/mnist/lenet_train_test.prototxt" # test_iter specifies how many forward passes the test should carry out.# In the case of MNIST, we have test batch size 100 and 100 test iterations,# covering the full 10,000 testing images.test_iter: 100...//defination in caffe.protomessage SolverParameter { // Proto filename for the train net, possibly combined with one or more // test nets. optional string net = 24; // The number of iterations for each test net. repeated int32 test_iter = 3;...}

Solver(XXX_solver.prototxt) carries out listed procedures:

  1. set up nn network from XXX.prototxt; (usually by net="cafferoot/directorytomodel/XXX.prototxt")
  2. update weights and bias to minimize loss function by Net::Forward and Net::Backward;
  3. evaluate network performance every several training iterations.

By the way, in protobuf, we use "type" to specify solver type. Currently solver support six solver types:

enum SolverType { SGD = 0; // default NESTEROV = 1; ADAGRAD = 2; RMSPROP = 3; ADADELTA = 4; ADAM = 5; }

Net

There is not much to say about XXX.prototxt. But do notice that the input and output of a layer in Caffe is called bottom and top.

The net is defined as a set of layers and their connections in a plaintext modeling language. A simple logistic regression classifier

is defined by:

name: "LogReg"layer { name: "mnist" type: "Data" top: "data" top: "label" data_param { source: "input_leveldb" batch_size: 64 }}layer { name: "ip" type: "InnerProduct" bottom: "data" top: "ip" inner_product_param { num_output: 2 }}layer { name: "loss" type: "SoftmaxWithLoss" bottom: "ip" bottom: "label" top: "loss"}

推薦閱讀:

打算用caffe做人臉識別,用的是vgg,如何使用model?
caffe如何進行數據集測試??
遷移學習與fine-tuning有什麼區別?
caffe finetune問題:按照網上的教程微調alexnet為什麼loss一直是87.3365?
cuDNN怎麼無法下載呢?

TAG:Caffe深度学习框架 | protobuf |