Caffe Windows compiles successfully, you are ready to start testing. If the compilation is not successful, please refer to: Caffe Windows Learning First step: Compiling and installing (Vs2012+win 64)
The first test is generally recommended for handwriting font minist recognition. This test is placed inside the. \examples\mnist\ folder in the root directory.
1, download the data. The program itself does not have the test data, needs to download, the test data is LEVELDB format. You can directly double-click to run the "Get_mnist_leveldb.bat" This script automatically download data, but generally unsuccessful, possibly inside the URL is wall. You can go directly to this download: http://pan.baidu.com/s/1hry1f4g
Download it and unzip it directly, get two folders (Mnist-train-leveldb and Mnist-test-leveldb), and copy the two folders directly to the. \examples\mnist\ directory.
2, modify the configuration file. The prototxt extension in this directory is a configuration file. We only need to modify the Lenet_solver.prototxt, open with vs2012 (also can be opened with Notepad, but the format is confusing, not clear), to navigate to the last line: Solver_mode:gpu, the GPU changed to CPU. If you have a GPU, this step will be free.
3, run. Just double-click on the file "Train_lenet.bat" to start running, very simple.
But what is the principle? Open the "train_lenet.bat" file to see:
copy.. \\.. \\bin\\MainCaller.exe. \\.. \\bin\\train_net.exe SET Glog_logtostderr= 1 ". /.. /bin/train_net.exe " lenet_solver.prototxtpause
This script is actually very simple, only four lines:
First line: Copy the MainCaller.exe in the Bin folder under the root directory and rename it to Train_net.exe
Second line: Set the Glog log. Glog is Google out of a C + + lightweight Log library, introduction see Glog
Line three: Run Train_net.exe with a parameter lenet_solver.prototxt (that is, the configuration file we just modified)
Line four: After the test is finished, pause.
MainCaller.exe is the entrance to the entire program, and it calls the other tests. We opened the corresponding MainCaller.cpp file (under the examples directory) and found only such a line of code:
#include ". /.. /tools/train_net.cpp "
That is to call the Execute Train_net.cpp file.
Open the Train_net.cpp under Tools, and the familiar main function is out.
#include <cuda_runtime.h>#include<iostream>#include<cstring>#include"caffe/caffe.hpp"using namespaceCaffe//nolint (build/namespaces)intMainintargcChar**argv) {:: google::initgooglelogging (argv[0]);//Initialize the log with the first parameter:: Google::setlogdestination (0,".. /tmp/");//put the log under the/tmp/folder if(ARGC <2|| ARGC >3) {LOG (ERROR)<<"usage:train_net solver_proto_file [Resume_point_file]"; return 1; } Solverparameter Solver_param; //To create a test parameter objectReadprotofromtextfileordie (argv[1], &solver_param);//read the specific parameter configurationLOG (INFO)<<"Starting Optimization";//Print log Informationsgdsolver<float> Solver (Solver_param);//Start Optimization//depending on the call, whether to take a third parameter, to perform different tests if(ARGC = =3) {LOG (INFO)<<"Resuming from"<< argv[2]; Solver. Solve (argv[2]); } Else{solver. Solve (); } LOG (INFO)<<"optimization done.";//end of optimization, print log information return 0;}
The entire minist handwritten numeral recognition process needs to iterate 10,000 times, the recognition precision will have more than 99%.
If you just want to see if Caffe is compiled successfully, and you don't need to iterate so many times, you can modify the Lenet_solver.prototxt configuration file, navigate to the max_iter:10000 line, and change the number of iterations you want.
The result of my iteration 1000 times is as follows:
These are all printed glog log information, from left to right: Date time execution file] execution information
Caffe Windows Learning: First Test program