Install Caffe under Ubuntu 14.04

   Copyright statement: This article is the original article of the blogger and may not be reproduced without the permission of the blogger. https://blog.csdn.net/Gavin__Zhou/article/details/47363385

In the past few days, I saw something about Deep Learning and I also wanted to have fun. I chose Caffe from Theano, Torch7 and Caffe. The main reason is that the installation is relatively simple and there are many online tutorials.
Post an introduction to Caffe:
Caffe is a clear and efficient deep learning framework. Its author is Jia Yangqing who graduated from UC Berkeley with a Ph.D. and currently works at Google.
Caffe is a pure C++/CUDA architecture, supporting command line, Python and MATLAB interfaces; it can be seamlessly switched between CPU and GPU:

Advantages of Caffe

Quick start: The model and the corresponding optimization are given in the form of text instead of code.
Caffe gives the definition of the model, optimal settings and pre-training weights, which is convenient to get started immediately.
Fast speed: able to run the best model and massive data.
Caffe and cuDNN are used in combination to test the AlexNet model. It only takes 1 per image to process on K40.17ms.
Modularity: Easy to expand to new tasks and settings.
You can use the various layer types provided by Caffe to define your own model.
Openness: Open codes and reference models are used for reproduction.
Community is good: you can pass BSD-2 Participate in development and discussion.

So let's go to the Internet to find a bunch of them, not our focus this time, skip it. . . . .

I also found a bunch of tutorials on the Internet. There are simple and complex ones. Many of them are outdated and cannot be used. I also refer to many online blog materials. Please contact me if there is any infringement.


Let me talk about the configuration of my own machine, i5+Intel set display+4GB RAM, so GPU acceleration like CUDA is not available, but it is not a problem for just getting started. Caffe recommends installing it under Linux such as Ubuntu or CentOS. The official tutorials are also the same. It is really not recommended under Windows.
Caffe official websiteCaffe official guide
Start the installation process below:

(1) Install Ubuntu14.04

I won’t talk about it. If it doesn’t work, you can refer to this Ubuntu Installation

(2) Install CUDA

Although I don’t need my broken machine, I still install it, so that I don’t have to worry about any further business trips.
First, you need to download the CUDA installation package: CUDA download address, enter and select your own Ubuntu14.04 deb package to download.
Second, install the repository and CUDA:

$ sudo dpkg -i cuda-repo-ubuntu1410-7-0-local_7.0-28_amd64.deb
$ sudo apt-get update
$ sudo apt-get install -y cuda

Set environment variables:

$ export CUDA_HOME=/usr/local/cuda7
$ export LD_LIBRARY_PATH=${CUDA_HOME}/lib64
$ PATH=${CUDA_HOME}/bin:${PATH}
$ export PATH

(3) Install ipython environment##

The python system already comes with it. Python2.7 requires the installation of the ipython environment. Many Caffe programs require ipython. Someone on the Internet directly installs spyder. Once installed, it will automatically install ipython for you by default, or you can install it. EPD Download the script and install it. By default, it will help you install many libraries, including ipython, numpy, scipy, pandas, matplotlib, etc.; if it is troublesome, you can also search for spyder installation in the ubuntu software center. can.

(4) Install BLAS

BLAS chooses MKL, you can also choose ATLAS or OpenBLAS, MKL download address, you need to apply first before downloading, be sure to keep the installation serial number, which will be used later

$ tar zxvf parallel_studio_xe_2015.tar.gz 
$ chmod a+x parallel_studio_xe_2015 -R
$ sudo ./install_GUI.sh

In this way, you start the GUI installation, and it feels like the installation and software under windows, next all the way, and finally enter the serial number sent to you by the email before, and it will be OK.

(5) MKL environment settings##

Create a new MKL configuration file:

$ sudo gedit /etc/ld.so.conf.d/intel_mkl.conf

Write the following two sentences:

/opt/intel/lib/intel64
/opt/intel/mkl/lib/intel64

Create a new cuda configuration file:

$ sudo gedit /etc/ld.so.conf.d/cuda.conf

Write the following two sentences:

/usr/local/cuda/lib64
/lib

Finally complete the link:

$ sudo ldconfig -v

(6) Install OpenCV

Here we use the installation package provided by others to solve some dependency problems. Download link: OpenCV
Switch to the folder where the file is saved, and install the dependencies:

$ sudo sh Ubuntu/dependencies.sh

Change directory 3.0\ install OpenCV 3.0.0rc1:

$ sudo sh opencv3_0_0-rc1.sh

Network installation, just wait

(7) Install glog and other dependencies##

glog download address
installation:

$ tar zxvf glog-0.3.3.tar.gz
$ ./configure
$ make
$ sudo make install

Other dependencies:

$ sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev
$ sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
$ sudo apt-get install -y python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags Cython ipython
$ sudo apt-get install -y protobuf-c-compiler protobuf-compiler

(8) Install CUDNN

If you don’t need GPU acceleration in this step, you don’t need to install it. You can also run the CPU.


a. This modified version of caffe-master supports cudnn-6.5-linux-x64-v2 by default. If you use cudnn-6.5-linux-R1, an error will be reported. Please go to the official website to download the latest cuDNN before installation.

$ sudo cp cudnn.h /usr/local/include
$ sudo cp libcudnn.so /usr/local/lib
$ sudo cp libcudnn.so.6.5/usr/local/lib
$ sudo cp libcudnn.so.6.5.48/usr/local/lib

b. Link cuDNN library file

$ sudo ln -sf /usr/local/lib/libcudnn.so.6.5.48/usr/local/lib/libcudnn.so.6.5
$ sudo ln -sf /usr/local/lib/libcudnn.so.6.5/usr/local/lib/libcudnn.so
$ sudo ldconfig -v

c. Switch to the Caffe-master folder, generate the Makefile.config configuration file, and execute:

$ cp Makefile.config.example Makefile.config

d. Configure the Makefile.config file (only the modified part is listed)
<1>. Enable CUDNN, remove "#" (currently caffe-master still only supports R1 version)

USE_CUDNN :=1

<2>. Enable GPU, add comment "#"

 # CPU_ONLY :=1

<3>. Configure some reference files (the added part is mainly to solve the path problem of HDF5 under the new version)

INCLUDE_DIRS :=$(PYTHON_INCLUDE)/usr/local/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include
LIBRARY_DIRS :=$(PYTHON_LIB)/usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

<4>. Enable Intel Parallel Studio XE 2015 Professional Edition for C++ Linux

BLAS := mkl

<5>. Configure the path to realize caffe's support for Python and Matlab interfaces

PYTHON_LIB :=/usr/local/lib
MATLAB_DIR :=/usr/local/MATLAB/R2014a

<6>. Configure Makefile (to achieve support for OpenCV 3.x)
Find the section "Derive include and lib directories", modify the last line of "LIBRARIES +=", add opencv_imgcodecs

opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs

(9) Compile caffe

caffe source code download address
Compile:

$ make all -j8
$ make test -j8
$ make runtest -j8
$ make pycaffe -j8
$ make matcaffe -j8

This should be fine, and I will write about how to use Caffe to run my own things in the next blog.

Reference:
(1) [OuXinYU's blog] (https://ouxinyu.github.io/Blogs/20140723001.html)
(2) [CSDN's Caffe introduction] (http://www.csdn.net/article/2015-01-22/2823663)
(3) [Other] (http://blog.csdn.net/kuaitoukid/article/details/40395617)

Recommended Posts

Install Caffe under Ubuntu 14.04
Install apache+PHP under Ubuntu
Install node.js under Ubuntu
Install python3.6 under Ubuntu 16.04
Install mysql under Ubuntu 16.04
Install Thrift under ubuntu 14.10
Install OpenJDK10 under Ubuntu
2018-09-11 Install arduino under Ubuntu
Install ROS under ROS Ubuntu 18.04[2]
Install MySQL under Ubuntu
Install Yarm-PM2 under Ubuntu
ubuntu16.04 install caffe cpu version
Install server-side Shadowsocks under Ubuntu 16.04
Install rgl package under Ubuntu
Install 3 single-cell R packages under Ubuntu
Install and deploy Gerrit under Ubuntu
Install MySQL under Ubuntu 18.04 (graphic tutorial)
Install JDK1.8 original under Ubuntu Kylin
Small tool: install screenshot tool under ubuntu
Install nodejs and npm under Ubuntu 16.04
How to install Audacious under Ubuntu
How to install Tensorflow under ubuntu 16.04
Compile and install QEMU under Ubuntu
ubuntu18.04 install python2
ubuntu18.04 install docker
ubuntu12.04 install python3
Ubuntu install guide
ubuntu install nodejs
ubuntu 16 install asp.net
ubuntu install leanote
ubuntu install Jenkins
docker install ubuntu
ubuntu install elasticsearch
ubuntu16.0.1 install pagoda
ubuntu18.04 install python
ubuntu 18.04 install teamviewer
ubuntu install sendmail
Install linux (ubuntu) dual system under windows system
Install YouCompleteMe plugin for vim under Ubuntu
Install PyTesser under ubuntu 14.04 for OCR recognition
Install Ubuntu with Parallels Desktop under Mac
Three ways to install software under Ubuntu
Install utility software collection under Ubuntu system
install vscode on ubuntu18
How to install vim editor under Linux (Ubuntu 18.04)
Install mysql-pytho in Ubuntu
ubuntu install zsh terminal
Install Redis on Ubuntu
Install R4 on ubuntu20
Install nvtop on Ubuntu 18.04
Install docker on Ubuntu
Install mysql5.7 under CentOS7
Ubuntu18.04 install opencv 3.2.0 solution
Install ActiveMQ under Centos7
Python MySQLd under Ubuntu
Install the CPU version of Caffe on Ubuntu
Install Docker on ubuntu18.04
Start working under ubuntu
Install nodejs10 on Ubuntu16
Install PostgreSQL12 under CentOS7
Install the old version of seurat under Ubuntu