I learned MNIST with Caffe and tried to draw it (MAC OS X El Capitan)

Introduction

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.

(1) Execution environment

OS:Mac OSX El Capitan (10.11.6) CPU: Core i5 1.6GHz GPU: Intel HD Graphics 6000 1536 MB Memory: 8GB

(2) Learn MNIST with Caffe

Basically, I refer to Training LeNet on MNIST with Caffe.

■ Data set preparation

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

■ Definition of solver

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

■ Data set learning

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)

(3) Precision PLOT

Basically, I refer to I tried plotting the progress of learning MNIST with Caffe.

■ Advance preparation

Since Gnuplot is used for display, it is necessary to install Gnuplot. Install by referring to Install Gnuplot (Mac El Capitan).

■ Execution of PLOT

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

(4) Errors actually encountered and how to deal with them

■ Error caused by forgetting to switch the solver mode to CPU

·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

(5) Referenced site

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

I learned MNIST with Caffe and tried to draw it (MAC OS X El Capitan)
I tried to build an environment for machine learning with Python (Mac OS X)
I installed Caffe so that I can do deep learning on MAC OS X El Capitan
I tried to display GUI on Mac with X Window System
Install lp_solve on Mac OS X and call it with python.
I tried to move GAN (mnist) with keras
I tried it with SymPy Live, Wolfram Alpha and google with reference to "Algorithm learned with Python 4th: Prime numbers".
I tried to implement and learn DCGAN with PyTorch
I tried to draw a route map with Python
How to install caffe on OS X with macports
I tried to automatically read and save with VOICEROID2
I tried to implement Grad-CAM with keras and tensorflow
Word Count with Apache Spark and python (Mac OS X)
Using NAOqi 2.4.2 Python SDK on Mac OS X El Capitan
I made a server with Python socket and ssl and tried to access it from a browser
I tried to classify MNIST by GNN (with PyTorch geometric)
Build a python environment with pyenv (OS X El Capitan 10.11.3)
I tried to make GUI tic-tac-toe with Python and Tkinter
How to install Theano on Mac OS X with homebrew
I tried to visualize bookmarks flying to Slack with Doc2Vec and PCA
A memorandum when I tried to get it automatically with selenium
I tried to make a periodical process with Selenium and Python
I tried to create Bulls and Cows with a shell program
I tried to easily detect facial landmarks with python and dlib
Steps to get Caffe into Mac OS X 10.10 in CPU Mode
I tried to express sadness and joy with the stable marriage problem.
I tried to make a calculator with Tkinter so I will write it
Build an environment with pyenv, pyenv-virtualenv, jupyter on OS X El Capitan
I tried to draw a system configuration diagram with Diagrams on Docker
I tried to convert datetime <-> string with tzinfo using strftime () and strptime ()
I tried to learn the angle from sin and cos with chainer
I tried to build a Mac Python development environment with pythonz + direnv
[Zaif] I tried to make it easy to trade virtual currencies with Python
I tried to control the network bandwidth and delay with the tc command
I tried to implement Autoencoder with TensorFlow
Wrangle x Python book I tried it [2]
Install matplotlib on OS X El Capitan
I tried to visualize AutoEncoder with TensorFlow
I installed DSX Desktop and tried it
I tried to get started with Hy
I tried to implement CVAE with PyTorch
Wrangle x Python book I tried it [1]
I tried to solve TSP with QAOA
I tried to make a periodical process with CentOS7, Selenium, Python and Chrome
When I tried to change the root password with ansible, I couldn't access it.
I tried to use Java with Termux using Termux Arch but it didn't work
When I tried to make a VPC with AWS CDK but couldn't make it
I tried to automate internal operations with Docker, Python and Twitter API + bonus
When I tried to create a virtual environment with Python, it didn't work
[ES Lab] I tried to develop a WEB application with Python and Flask ②
I want to write an element to a file with numpy and check it.
I made an image classification model and tried to move it on mobile
Load a photo and make a handwritten sketch. With zoom function. Tried to make it.
[Introduction to AWS] I tried porting the conversation app and playing with text2speech @ AWS ♪
Docker x visualization didn't work and I was addicted to it, so I summarized it!
R environment construction with Jupyter (formerly IPython notebook) (on OS X El Capitan 10.11.3)
I tried to make a simple image recognition API with Fast API and Tensorflow
I tried to use Twitter Scraper on AWS Lambda and it didn't work.
Run Qiita API v2 Python wrapper in Python3 environment (Mac OS X 10.11 (El Capitan))
I tried it with Wolfram Alpha by referring to "Solving simultaneous linear equations with Python (sweeping method and fractional expression)".
I tried to predict next year with AI