This is a story about an amateur learning MNIST data in Caffe (CPU_only mode). MNIST database is a dataset of 0-9 handwritten characters created by LeCun et al. I couldn't find any information about Mac OS 10.11, so I'll make a note of it as a memorandum.
(1) Execution environment (2) Learn MNIST with Caffe (3) Precision PLOT (4) Errors actually encountered and how to deal with them (5) Referenced site
The installation version is here.
OS:Mac OSX El Capitan (10.11.6) CPU: Core i5 1.6GHz GPU: Intel HD Graphics 6000 1536 MB Memory: 8GB
Basically, I refer to Training LeNet on MNIST with Caffe.
First, download the dataset and create training data. (1st line) Go to the Caffe folder hierarchy (2nd line) Download mnist data (3rd line) Create training data from mnist data
cd $CAFFE_ROOT
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh
If you get an error here, there are two likely possibilities: ・ The hierarchy is different ・ There is no wget or gunzip
Switch the solver definition from GPU mode to CPU mode (because it is used in CPU mode). Edit the following file with an editor.
$CAFFE_ROOT/examples/mnist/lenet_solver.prototxt
Rewrite as solver_mode: CPU as follows.
# solver mode: CPU or GPU
solver_mode: CPU
Next, train the dataset.
Later, I will add 2> & 1 | tee your_name.log
to draw a precision PLOT. It doesn't matter if you know the name of your_name.log.
(It was said that a log file could be created in the / tmp / folder without 2> & 1 | tee your_name.log
, but it was not created under my own environment)
cd $CAFFE_ROOT
./examples/mnist/train_lenet.sh 2>&1 | tee your_name.log
Some of the actual results are shown below. The log will be displayed in the terminal, and a your_name.log
file will be created in the ./examples/mnist/
hierarchy.
I0924 20:28:43.185619 2030800896 solver.cpp:228] Iteration 9900, loss = 0.00506415
I0924 20:28:43.185690 2030800896 solver.cpp:244] Train net output #0: loss = 0.00506419 (* 1 = 0.00506419 loss)
I0924 20:28:43.185703 2030800896 sgd_solver.cpp:106] Iteration 9900, lr = 0.00596843
I0924 20:28:47.841295 2030800896 solver.cpp:454] Snapshotting to binary proto file examples/mnist/lenet_iter_10000.caffemodel
I0924 20:28:47.865257 2030800896 sgd_solver.cpp:273] Snapshotting solver state to binary proto file examples/mnist/lenet_iter_10000.solverstate
I0924 20:28:47.902568 2030800896 solver.cpp:317] Iteration 10000, loss = 0.00462559
I0924 20:28:47.902603 2030800896 solver.cpp:337] Iteration 10000, Testing net (#0)
I0924 20:28:51.194413 2030800896 solver.cpp:404] Test net output #0: accuracy = 0.9909
I0924 20:28:51.194463 2030800896 solver.cpp:404] Test net output #1: loss = 0.0286294 (* 1 = 0.0286294 loss)
meaning | |
---|---|
loss | Loss function value of training data(loss is the training function) |
lr | Learning rate(lr is the learning rate of that iteration) |
#0: accuracy | Correct answer rate of test data |
#1: loss | Test data loss function value(testing loss function) |
Basically, I refer to I tried plotting the progress of learning MNIST with Caffe.
Since Gnuplot is used for display, it is necessary to install Gnuplot. Install by referring to Install Gnuplot (Mac El Capitan).
Run parse_log.sh
with your_name.log
created in the dataset training as an argument.
cd $CAFFE_ROOT/tools/extra
./parse_log.sh your_name.log
The following two files are created.
your_name.log.test
your_name.log.train
Change your_name part of the above two files to mnist. (In the $ CAFFE_ROOT / tools / extra folder) Then execute the following command.
gnuplot plot_log.gnuplot.example
The drawn image (horizontal axis: "Training iterations", vertical axis: "Training loss") is saved.
your_chart_name.png
·Error message
I0922 20:46:13.136147 2030800896 caffe.cpp:217] Using GPUs 0
F0922 20:46:13.138036 2030800896 common.cpp:66] Cannot use GPU in CPU-only Caffe: check mode.
*** Check failure stack trace: ***
@ 0x104c87636 google::LogMessage::Fail()
@ 0x104c86d2d google::LogMessage::SendToLog()
@ 0x104c87295 google::LogMessage::Flush()
@ 0x104c8a5e7 google::LogMessageFatal::~LogMessageFatal()
@ 0x104c87923 google::LogMessageFatal::~LogMessageFatal()
@ 0x1049cba06 caffe::Caffe::SetDevice()
@ 0x10493feb0 train()
@ 0x10494274a main
@ 0x7fff968535ad start
@ 0x3 (unknown)
./examples/mnist/train_lenet.sh: line 4: 62566 Abort trap: 6
./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt $@
·Workaround
Edit lenet_solver.prototxt
to switch the mode to CPU.
# solver mode: CPU or GPU
solver_mode: CPU
Caffe Official | Training LeNet on MNIST with Caffe (20) MNIST automatic recognition with Caffe (1) [From the introduction of "Caffe" that allows deep learning without GPU to learning, test, and self-made data](http://sssslide.com/speakerdeck.com/suneo3476/gpuwu-sidedeipuraningudekiru-caffe-dao-ru-karaxue-xi-tesutodetazi -zuo-made) I plotted the process of learning MNIST with Caffe Caffe Logging and Loss Plotting Where to find log files? How can I get the figures like this Install Gnuplot (Mac El Capitan)
Recommended Posts