[PYTHON] An amateur tried Deep Learning using Caffe (Introduction)

Introduction

This article

  1. What is Deep Learning? Overview
  2. Installation of Caffe, one of the Deep Learning libraries Introduction (this post)
  3. Let's do simple learning using Caffe Practice It is composed of three

Although it is also in the title, it is a post about a record left by an amateur who is not a researcher of Deep Learning, so please forgive me for any mistakes and read it. (If there is something wrong, I would appreciate it if you could point it out in the comments)

Installation environment

OS:Ubuntu 14.04 LTS CPU: Core i7 2.93GHz GPU: GeForce GTX 960 Memory: 4GB

Caffe installation procedure

Basically, do as described on the Caffe official page. Here, the configuration is as follows, but please change it appropriately according to the environment. CUDA 7.0 use cudnn ATLAS Caffe (latest in github master) Make PyCaffe available

Installation of General dependencies

Obediently follow the formula

python


sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev

Install Remaining dependencies (for 14.04)

This also obediently follows the formula

python


sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

ATLAS installation

What is ATLAS? It feels like, but a library for numerical calculation (probably matrix differentiation) Easy with Ubuntu

python


sudo apt-get install libatlas-base-dev

Install CUDA (GPU users only)

It says that you can use apt-get on Ubuntu, but from various points of view it seems better to take it from the nVidia official and put it in by yourself, so I decided to put it in by myself. (The latest seems to be 7.5, but I think it is the same as 7.0, so I will write it as it is)

Installation of CUDA main unit

From nvidia developer site, go to CUDA ZONE → CUDA DOWNLOADS to drop the CUDA installer. Then run the installer (replace xxx with the version you dropped)

python


chmod +x cuda_xxx_linux.run
sudo ./cuda_xxx_linux.run

All you have to do is follow the instructions on the screen

installation of cudnn

It doesn't seem to be required, but according to the official, it's faster to put it in, so put it in.

cuDNN Caffe: for fastest operation Caffe is accelerated by drop-in integration of NVIDIA cuDNN. To speed up your Caffe models, install cuDNN then uncomment the USE_CUDNN := 1 flag in Makefile.config when installing Caffe. Acceleration is automatic. The current version is cuDNN v3; older versions are supported in older Caffe.

user registration

Register as a developer from the above nvidia developer site

Installation

After registration, cudnn will be available for download, so download it from here. Then

python


sudo cp cudnn.h /usr/local/cuda/include/
sudo cp *.so /usr/local/cuda/lib64/
sudo cp *.a /usr/local/cuda/lib64/

Copy the library as In addition, the same symbolic link in the extracted file, Create it in / usr / local / cuda / lib64 (the following is 6.5 at the time of download)

python


cd /usr/local/cuda/lib64/
sudo ln -s libcudnn.so.6.5.48 libcudnn.so.6.5
sudo ln -s libcudnn.so.6.5 libcudnn.so

Install Caffe

Now that we are ready, we will put it in immediately (assuming that the necessary items around python are prepared separately)

Download Caffe

For some reason, it's not officially written here, but it seems that it is official to drop it from github.

git clone https://github.com/BVLC/caffe.git

Install what you need for PyCaffe

As officially

python


for req in $(cat requirements.txt); do pip install $req; done

That's it. requirements.txt is in caffe / python I didn't have gfortran in my environment, so I installed scipy once.

python


error: Setup script exited with error: library dfftpack has Fortran sources but no Fortran compiler found

In that case, please insert gfortran.

python


sudo apt-get install gfortran

Modify Makefile.config

This is important. If you make a mistake here, you may try to build with something that doesn't exist, or you may get stuck in an error point. First, copy Makefile.config.example to create the prototype of Makefile.config.

python


cp Makefile.config.example Makefile.config

Make sure that Makefile.config looks like this: (Please change according to the environment) USE_CUDNN: = 1 (when using cudnn) CPU_ONLY: = 1 (comment out when using GPU) CUDA_DIR: = / usr / local / cuda (probably not needed for CPU_ONLY) None of the lines in CUDA_ARCH: = -gencode arch = compute ... are commented out (probably commented out if CPU_ONLY) BLAS := atlas PYTHON_INCLUDE := /usr/include/python2.7 \ /usr/lib/python2.7/dist-packages/numpy/core/include PYTHON_LIB := /usr/lib The rest remains as an example

make

It will be soon after the above is over. Make at the root of your project (It is OK without the j8 part. Please change the number appropriately according to the number of CPU cores)

python


make all -j8

Run the test to see if it was installed successfully

I will do a final test to make sure it's done right here

python


make runtest

A log like the following lasts for a few minutes

python


[----------] 3 tests from DeconvolutionLayerTest/0, where TypeParam = caffe::CPUDevice<float>
[ RUN      ] DeconvolutionLayerTest/0.TestSetup
[       OK ] DeconvolutionLayerTest/0.TestSetup (0 ms)
[ RUN      ] DeconvolutionLayerTest/0.TestSimpleDeconvolution
[       OK ] DeconvolutionLayerTest/0.TestSimpleDeconvolution (1 ms)
[ RUN      ] DeconvolutionLayerTest/0.TestGradient
[       OK ] DeconvolutionLayerTest/0.TestGradient (623 ms)
[----------] 3 tests from DeconvolutionLayerTest/0 (624 ms total)

Finally, if you get PASSED as follows, you are successful.

python


[==========] 1404 tests from 222 test cases ran. (221949 ms total)
[  PASSED  ] 1404 tests.

If it fails, please check if the Makefile.config settings are correct and try again.

at the end

Thank you for your support. In the next article, I would like to actually run deep learning learning using Caffe.

Recommended Posts

An amateur tried Deep Learning using Caffe (Introduction)
An amateur tried Deep Learning using Caffe (Practice)
An amateur tried Deep Learning using Caffe (Overview)
I tried deep learning using Theano
I tried deep learning
I tried running an object detection tutorial using the latest deep learning algorithm
An introduction to machine learning
[I tried using Pythonista 3] Introduction
Introduction of caffe using pyenv
Introduction to Deep Learning ~ Learning Rules ~
Deep Reinforcement Learning 1 Introduction to Reinforcement Learning
Introduction to Deep Learning ~ Backpropagation ~
An amateur stumbled in Deep Learning from scratch Note: Chapter 1
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 5
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 2
An amateur stumbled in Deep Learning from scratch Note: Chapter 3
I tried hosting a TensorFlow deep learning model using TensorFlow Serving
An amateur stumbled in Deep Learning from scratch Note: Chapter 7
An amateur stumbled in Deep Learning from scratch Note: Chapter 5
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 7
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 1
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 4
An amateur stumbled in Deep Learning from scratch Note: Chapter 4
An amateur stumbled in Deep Learning from scratch Note: Chapter 2
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 6
Introduction to Deep Learning ~ Function Approximation ~
Introduction to Deep Learning ~ Coding Preparation ~
I tried reinforcement learning using PyBrain
Introduction to Deep Learning ~ Dropout Edition ~
Introduction to Deep Learning ~ Forward Propagation ~
Introduction to Deep Learning ~ CNN Experiment ~
Introduction to Deep Learning ~ Convolution and Pooling ~
An introduction to OpenCV for machine learning
Image recognition model using deep learning in 2016
Stock price forecast using deep learning (TensorFlow)
[Kaggle] I tried ensemble learning using LightGBM
I tried using the trained model VGG16 of the deep learning library Keras
[Python] When an amateur starts machine learning
I tried hosting Pytorch's deep learning model using TorchServe on Amazon SageMaker
An introduction to Python for machine learning
Deep Learning
I tried the common story of using Deep Learning to predict the Nikkei 225
Deep Learning beginners tried weather forecasting from meteorological satellite images using Keras
I tried the common story of predicting the Nikkei 225 using deep learning (backtest)
Introduction to Deep Learning (1) --Chainer is explained in an easy-to-understand manner for beginners-
[Python] Deep Learning: I tried to implement deep learning (DBN, SDA) without using a library.
I tried to extract a line art from an image with Deep Learning
An introduction to machine learning for bot developers
An introduction to Cython that doesn't go deep
Stock Price Forecast Using Deep Learning (TensorFlow) -Part 2-
Introduction to Deep Learning ~ Localization and Loss Function ~
[Causal search / causal reasoning] Execute causal search (SAM) using deep learning
Stock price forecast using deep learning [Data acquisition]
An introduction to Cython that doesn't go deep -2-
[Introduction] Reinforcement learning
Deep Learning Memorandum
Start Deep learning
Python Deep Learning
Deep learning × Python
[Pokemon Sword Shield] I tried to visualize the judgment basis of deep learning using the three family classification as an example.
Thinking about party attack-like growth tactics using deep learning