Caffe Installation & Prerequisite Setup
** This gist will/may serve as a guide for people who are trying to do object detection with caffe framework mentioned at top **
** I will try to cover all the steps from the start. If i do miss addressing something please let me know **
** All the links that i will mention here are important. Please have a look at them for complete understanding of what you are doing **
** There are some steps where you may encounter missing package errors. You can fix them by simply doing a google search wiht package name and installing them with "pip" **
My Rig
Operating system : Windows 10, Ubuntu 16.04 (Dual-boot) Graphic hardware: 16GB RAM, Nvidia GTX 1070 (8GB Video Memory) Processor: Intel i7-7700HQ Storage: HHD + SSD
My system setup is quite basic for running complex deep learning applications. Better the configuration, lesser will be training time.
Operating System Setup
The reason to dualboot your system and install ubuntu is to stay away from horrible errors that you may encounter while setting up Caffe & Yolo on windows. Although the builds exist, the need to build using source code is a huge pain when working on windows.
I would highly suggest you to follow this link to set up your system. Awesomebytes has written excellent guide to dualboot your machine with ubuntu. Guide Link
-- Credit goes to Awesomebytes
Environment Setup
Caffe - Ubuntu
You could also follow official guide here. Guide Link
Below is a simplified version of how i did it. Make sure to update everything on your machine by running these 2 commands.
sudo apt-get update
sudo apt-get upgrade
OpenCV & Keras
OpenCV & Keras are needed. I installed it by following this awesome guide by Trung Tran. Guide Link
After installing OpenCV, try doing this below. If it succeeds and you see this message, you have successfully installed OpenCV.
python
>>> import cv2
>>> cv2.__version__
'3.0.0'
Necessary packages
Copy these commands and install using terminal.
sudo apt-get install build-essential cmake git pkg-config libjpeg8-dev \
libjasper-dev libpng12-dev libgtk2.0-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev gfortran
sudo apt-get install libtiff5-dev
sudo apt-get install libatlas-base-dev
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo pip install numpy
sudo apt-get install python2.7-dev
CUDA & cuDNN
Download CUDA 8.0 RC by following this link & selecting appropriate version. CUDA Link
Run the following command & follow prompts
sudo sh cuda_8.0.27_linux.run
As part of the CUDA environment, you should add the following in the ~/.bashrc file of your home folder.
export CUDA_HOME=/usr/local/cuda-8.0
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64
PATH=${CUDA_HOME}/bin:${PATH}
export PATH
Open a new terminal & check if CUDA is installed
nvcc –version
Download cuDNN 5.0 by following this link & selecting appropriate version. cuDNN Link
We are copying cuDNN files to CUDA folder. Fix paths if some path error pops up.
tar xvzf cudnn-8.0.tgz
cd cudnn
sudo cp include/cudnn.h /usr/local/cuda/include
sudo cp lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
** Installing Caffe **
Install these necessary packages
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev \
libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
sudo apt-get install -y --no-install-recommends libboost-all-dev
Get Caffe from github repository and open up makefile
git clone https://github.com/BVLC/caffe
cd caffe
cp Makefile.config.example Makefile.config
# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1
# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include
# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/
Finally run this command
make all & make test && make runtest && make pycaffe
Add Caffe to pythonpath
sudo vim ~/.bashrc
export PYTHONPATH=$HOME/Downloads/caffe/python:$PYTHONPATH
Use this command to make the changes effective
source ~/.bashrc
Now try this in terminal. If no error pops up, you have successfully installed Caffe
python
>>> import caffe
>>>