Caffe Installation on Ubuntu 18.04 LTS (Python 2.7)

Caffe (Source)

#error — unsupported GNU version! gcc versions later than 6 are not supported!
# OpenCV
$ sudo apt install python-opencv
# Numpy
$ sudo apt-get install python-numpy
# BLAS
$ sudo apt-get install libatlas-base-dev # Atlas
or
$ sudo apt-get install libopenblas-dev # OpenBLAS
# Other dependencies
$ 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
$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
$ sudo pip install protobuf
$ sudo apt-get install the python-dev
$ git clone https://github.com/BVLC/caffe.git
$ cd caffe
$ cp Makefile.config.example Makefile.config
OPENCV_VERSION := 3 # if you are using OpenCV 3 or aboveCUDA_ARCH := 
# -gencode arch=compute_20,code=sm_20 \
# -gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
BLAS := atlas # if you’ve installed Atlas (default)
or
BLAS := open # if you’ve installed OpenBLAS
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
$ make all -j6       # 6 represents number of CPU Cores
$ make pycaffe -j6 # 6 represents number of CPU Cores
$ make clean
export PYTHONPATH=~/Downloads/caffe/python:$PYTHONPATH
$ source ~/.bashrc
$ python
>>> import caffe

Tested with Ubuntu 18.04 LTS, CUDA 9.0 and CuDnn 7.4

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store