Caffe Code reading notes (1) _caffe

Source: Internet
Author: User
1. Procedure Entrance

The entry of the program is in/caffe_root/tools/caffe.cpp, the class file where the main () function is located. In the/tools/directory, a framework tool is provided. However, several training-related tools, such as Train,test,finetune, have been integrated into the/caffe.cpp.

What we want to know is that a standard training instruction:
/build/tools/caffe train--solver=models/xx_caffenet/solver.prototxt, what happened when we hit the ENTER key. 1.1 Caffe.cpp Overview

This class provides a response interface for user directives. The commands it supports include the following:
-Train: Training or finetune a model
-Test:score a model
-Device_query:show GPU Diagnostic information
-Time:benchmark Model Execution time

In the class file, the above commands correspond to four functions: train (), test (), Time (), Device_query (). The main function acts as the entry point for all commands, and by parsing the command line, the command is imported into the appropriate processing process. 1.2 Parsing the command line

Command-line parsing is a task that requires patience and error-prone. Presumably for convenience, the framework uses an open source library called GFlags.

GFlags is an open-source library of Google Open source that handles command-line arguments. It is developed using C + + and has a Python interface. This framework is easy to use, but does not support parameter shorthand.

The use of this library is also relatively simple.
1. Include header file #include <gflags/gflags.h>
2. Define the command line arguments you want using the GFLAGS macro in the file. The macro definition is global and has a format such as DEFINE_XXXX (variable name, default value, description)
3. The supported parameter types are as follows:
-Define_bool:boolean
-Define_int32:32-bit Integer
-Define_int64:64-bit Integer
-Define_string:c++ string
-Define_uint64:64-bit unsigned integer
-Define_double:double
4. GFlags defaults have been defined for-H and--version, which can be set by gflags::setversionstring and Gflags::setusagemessage. More detailed information to search the network, or direct reference to Https://github.com/gflags.

With these introductions, some of the relevant code can see what's going on. For example Caffe::globalinit (&ARGC, &ARGV); This line of code is the initialization of the gflags related content. 1.3 Booting to the processing process

If Python is used in the command, in the case of Python support, it responds to Python commands or throws an error message directly. Standard process, use the function getbrewfunction (caffe::string (argv[1)) to import into the command flow.

The static brewfunction getbrewfunction (const caffe::string& name) function returns a function pointer "typedef int (*brewfunction) (). The function pointer is stored in a map and should be registered when the macro definition expands.

So, you can see that each command function last has a sentence of registerbrewfunction (name).

For example, Caffe train ... command, the final program extracts the train, maps it to the already registered train () function, and executes it.

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.