Caffe practical notes

Source: Internet
Author: User

Caffe:

Caffe does not have a Windows version, so I need to remotely log on to the Linux Server

Caffe mainly processes image/Image Sequences

 Data format read by caffe

Read from a dedicated database (lmdb, leveldb)

Read images directly

Read from memory (will occupy a lot of memory)

Read from hdf5 File

Read from the sliding window (slide once in a large image as a small image)

The first two methods are most commonly used. By default, the image file is read from the lmdb database format. Therefore, you must first convert the image file to the lmdb format file. Directly Reading the image will cause the mean value to be reduced. If you do not consider the mean reduction, you can directly read the image.

 Caffe operation 1 ---- prepare data

Step 1: Get the file list

 

The image above is derived from the fer library. A single figure indicates an expression, and the TXT document is automatically generated when the code is written.

Step 2: Convert to IMDB format

Command principle:

 

The preceding four parameters are included. You can choose not to set the pink parameter. -- indicates that the parameter can be changed.

Actual Operation:

Open the terminal in the/caffe path under the Home directory in the root directory, enter the sudo command, and enter the password to enter the maximum permission:

 

Enter the command: (pay attention to spaces when entering)

 

In caffe, the author provides us with a file: convert_imageset.cpp, which is stored in the Tools Folder under the root directory. After compilation, generate the corresponding executable file under buile/tools/. This file is used to convert the image file into an IMDB file that can be directly used in the Caffe framework.

On-screen display:

 

View results:

A folder named after me is added to the target directory.

 

The folder contains two sub-files, Data. mdb stores data, and lock. mdb stores tags.

 

Basic knowledge supplement

Folders and directories in Linux

/Home

Root directory, maximum partition time

/Bin

Store system commands

/User

The largest directory for storing applications and files

/Etc

Store configuration files

/Dev

Special Device Files

/Mnt

Used to temporarily Mount hard disks and CDs

/Src

Put the source file in it, such as CPP.

How to create the train.txt file and how to adjust the image format when converting IMDB format, see: http://www.cnblogs.com/denny402/p/5082341.html

Step 3: calculate the mean value

The accuracy can be improved by subtracting the mean value. Of course, you can also choose not to subtract the mean value.

The extension must be binaryproto.

Actual code:

 

There are two parameters: one is the file address for storing IMDB data, and the other is the address for saving the mean file and the file name.

Obtain the binarypro average File

Additional reading: http://www.cnblogs.com/denny402/p/5102328.html

Caffe operation 2 ---- build the Network Structure

The entire process can be divided into three stages: training, verification, and testing. The network structure varies at different stages and is stored in the prototxt file. For convenience, the network structure of the training and verification phases is generally put in one file, and the network structure of the test phase is put in one file separately:

 

A layer indicates a layer.

Layer can be copied and nested.

1) Data Layer

Name can be retrieved at will

Type is built-in and cannot be named by yourself

Top indicates data is transferred up, and bottom indicates receiving data from below. The top or bottom determines the data flow direction and the link between different layers.

Phase: Train indicates that this layer is called only during training.

Mirror indicates flip

Cropsize indicates that a chart changes to 40*40*10, increasing the number of samples.

Batchsize is a multiple of 2, indicating batch processing.

Http://www.cnblogs.com/denny402/p/5070928.html

2) convolution Layer

 

Decay = 0 indicates no attenuation

Num_output convolution cores/node count

Kernal_size is generally 3*3 5*5 7*7 and cannot be too large.

After the padding convolution, the image becomes smaller, so it is fixed to 0. If it is equal to 2, it indicates that two pixel entries are filled in the upper, lower, and left sides of the perimeter.

Gaussian indicates that the gaussian method is used to initialize W and B.

Http://www.cnblogs.com/denny402/p/5071126.html

3) activation Layer

 

Common Relu and sigmod

Http://www.cnblogs.com/denny402/p/5072507.html

4) Pooling Layer

Caffe only supports Max and average. Stochastic is random.

Stride cannot write 1, otherwise there will be no pooling Function

Http://www.cnblogs.com/denny402/p/5071126.html

5) full connection Layer

 

The xvaier initialization method is good. The default value is 0.

All types remain unchanged

Http://www.cnblogs.com/denny402/p/5072746.html

6) Other Layers

Add the loss layer to the end of the full connection Layer

Add a softmax layer for testing.

The deploy. prototxt file is used in the test phase. The test data has no tag value. Therefore, the data input layer is different from the other two stages.

 

Caffe automatically copies the grayscale image to a 3-channel image.

Caffe operation3----Configure solver. prototxt

Set global parameters here

After each training completion of an interval, check whether the value is greater than 449.

The basic learning rate determines that convergence does not converge.

Step: change every other time

Stepshot: How many parameters are saved for each training

 

Http://www.cnblogs.com/denny402/p/5074049.html

Caffe operation4----Training Model

In this step, the model file of caffe is generated to complete parameter training.

 

 

Example:

Build/tools/caffe train-solver/home/BNU/FER/Solver. prototxt

Http://www.cnblogs.com/denny402/p/5076285.html

Caffe operation5----Test Model

 

Classification. Bin is the built-in executable body.

Http://www.cnblogs.com/denny402/p/5111018.html

 

Caffe practical notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.