These days, I am in the middle of the configuration of Caffe in Ubuntu14.04 due to the need of a small project. Here I want to write down the steps to show how to install it.
If you follow the installation instructions of the official site, I think you will be crazy. The documents are not in order. I succeeded to install it according to a Chinese blog. Apart from simple translation, I will also add some contents.
The whole process is as follows:
Environments:
- Ubuntu 14.04 64bit
- 8G Memory
- GeForce GT 705 Graphics Card
- CUDA 7.5
- caffe from github
Steps:
- Install all the dependencies
- Install CUDA 7.5
- Install Atlas
- Install OpenCV
- Install Anaconda2
- Install Caffe
- Compile Python wrapper
- Test Caffe
Install all the dependencies
1 | sudo apt-get install build-essential # basic requirement |
Install CUDA 7.5
You can follow the office website instructions install it. Before you install the packages, you’d better check it whether the package is intact through md5.
1 | md5sum package_name |
After you finish the installation, please reboot the computer.
1 | sudo reboot |
Later, we need to configure the environmental variable for cuda.
1 | sudo gedit /etc/profile |
At the same time, we need to add the library path to /etc/ld.so.conf.d folder.
1 | cd /etc/ld.so.conf.d |
Now we install CUDA SAMPLE
1 | cd /usr/local/cuda/samples |
- ./deviceQuery Starting…
- CUDA Device Query (Runtime API) version (CUDART static linking)
- Detected 1 CUDA Capable device(s)
- Device 0: “GeForce GTX 670”
- CUDA Driver Version / Runtime Version 6.5 / 6.5
- CUDA Capability Major/Minor version number: 3.0
- Total amount of global memory: 4095 MBytes (4294246400 bytes)
- ( 7) Multiprocessors, (192) CUDA Cores/MP: 1344 CUDA Cores
- GPU Clock rate: 1098 MHz (1.10 GHz)
- Memory Clock rate: 3105 Mhz
- Memory Bus Width: 256-bit
- L2 Cache Size: 524288 bytes
- Maximum Texture Dimension Size (x,y,z) 1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
- Maximum Layered 1D Texture Size, (num) layers 1D=(16384), 2048 layers
- Maximum Layered 2D Texture Size, (num) layers 2D=(16384, 16384), 2048 layers
- Total amount of constant memory: 65536 bytes
- Total amount of shared memory per block: 49152 bytes
- Total number of registers available per block: 65536
- Warp size: 32
- Maximum number of threads per multiprocessor: 2048
- Maximum number of threads per block: 1024
- Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
- Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
- Maximum memory pitch: 2147483647 bytes
- Texture alignment: 512 bytes
- Concurrent copy and kernel execution: Yes with 1 copy engine(s)
- Run time limit on kernels: Yes
- Integrated GPU sharing Host Memory: No
- Support host page-locked memory mapping: Yes
- Alignment requirement for Surfaces: Yes
- Device has ECC support: Disabled
- Device supports Unified Addressing (UVA): Yes
- Device PCI Bus ID / PCI location ID: 1 / 0
- Compute Mode:
- < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
- deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 6.5, CUDA Runtime Version = 6.5, NumDevs = 1, Device0 = GeForce GTX 670
- Result = PASS
If you command window shows the similar result, that means your display card driver is installed successfully, otherwise there will be something wrong with your installation.
Install Atlas
1 | sudo apt-get install libatlas-base-dev |
Install OpenCV-2.4.10
- Download the installation script
- Go to the Install-OpenCV/Ubuntu/2.4 folder
1
sudo sh ./opencv2_4_10.sh
Install Anaconda2
Download Anaaconda2 from official website
Unzip and go to the folder
1
sudo sh ./Anaconda2-2.4.1-Linux-x86_64.sh
Add the Anaconda Library Path
1
2
3
4
5
6
7
8
9
10
11
12
13
14sudo vim /etc/ld.so.conf
# add the contents at the end of the file
/home/your_name/anaconda2/lib
# make the file into effect
sudo ldconfig
sudo vim ~/.bashrc
export LD_LIBARY_PATH="/home/your_username/anaconda2/lib:$LD_LIBRARY_PATH"
export PATH="/home/your_username/anaconda2/bin:$PATH"
source ~/.bashrc
#test python version
Install Caffe
Download Caffe from github
then we need to download python dependencies
1
2
3cd caffe-master/python
for req in $(cat requirements.txt);
do sudo pip install $req; donemake sure all the dependencies have installed properly, otherwise we will meet many issues when compiling caffe
Compile Caffe
1 | cd caffe-master |
We should make some changes to the configuration.
1 | # Comment out these lines |
1 | # make sure your current foler is caffe-master |
Compile Python Wrapper
1 | # make sure your current folder is caffe-master |
Ok, you do a very good job! Congratulations! You have finished all the steps to install caffe. Now let’s make a small test to feel the performance of caffe.
Test
We will use the mnist example to make a test. I also followed a Chinese blog
1 | sudo sh data/mnist/get_mnist.sh # get training data and testing data from the internet |
You will see four files in the folder of data/mnist
- train-images-idx3-ubyte (training samples)
- train-labels-idx1-ubyte (training samples’ labels)
- t10k-images-idx3-ubyte (testing samples)
- t10k-labels-idx1-ubyte (testing samples’ labels)
1 | sudo sh examples/mnist/create_mnist.sh # transfer the format of original datasets |