Caffe study notes - test caffe with lenet network and mnist dataset

This article uses the simplest network structure lenet to test the caffe just installed:

1. Unzip the downloaded mnist dataset to D:\caffe\caffe-master\caffe-master\data\mnist:

2. Convert data format

       Convert to the data format required by caffe, here is converted to LMDB (cifar is converted to LEVELDB, you can compare and refer to how to achieve), the conversion format needs to use the project convert_mnist_data in caffe, this convert_mnist_data.exe program is placed in caffe-master Under \Build\x64\Release, if the solution is generated by debug, it is under caffe-master\Build\x64\Debug. When writing bat files, pay attention to changing the corresponding path. (PS: If you want to convert to LEVELDB format, you only need to change mnist_train_lmdb to mnist_train_leveldb in the .bat file, there are two places!)

(1) Create a new script file create_mnist.bat under the root directory caffe_master of caffe :


(2) Write the following content in the script file:


In fact, the first path is the path where the exe file is located, the last two are the path where the data is located, and the last one is the output file path

(3) After saving the script, double-click to run:


Then generate the corresponding folder in the D:\caffe\caffe-master\caffe-master\examples\mnist directory:




3. Modify D:\caffe\caffe-master\caffe-master\examples\mnist\lenet_solver.prototxt, change the last line to solver_mode:CPU, and modify D:\caffe\caffe-master\caffe-master\examples\mnist \lenet_train_test.prototxt, as shown below, original on the left and modified on the right.


4. In the caffe root directory, create a new train_mnist.bat, and then enter the following script:


After saving, double-click to run to start training. After training, you will get the corresponding accuracy rate (0.991) and loss rate.


Errors encountered during:

1. Debug and Release, this is selected in VS2013. When calling applications such as convert_mnist_data.exe, compute_image_mean.exe, etc., to select the path, be sure to see clearly that what you generate is in the Debug folder (caffe-master \Build\x64\Debug) or in Release (caffe-master\Build\x64\Release), if you generate it in Debug and call it with the path: .Build\x64\Release, then The following error occurs:


You can select Debug and Release respectively in VS2013 to generate the solution, and the problem will not appear.

2. When converting data, it is necessary to determine whether to convert LMDB or LEVELDB. This is set at the beginning of the conversion. Once set, it must be changed correspondingly in the train_test.prototxt file later.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325791210&siteId=291194637