How to Install Caffe on Ubuntu 16.04/17.04/18.04 Linux

This post will guide you how to install Caffe on your Ubuntu Linux server. How do I install Caffe for CPU-only or CUDA-only version with default package manager on Ubuntu 17.04 or 18.04 Linux. How to install Caffe for CPU-only version from source code on Ubuntu system 16.04/17.04/18.04.

What is Caffe?


Caffe  is a deep learning framework, originally developed at University of California, Berkeley. It is open source, under a BSD license. It is written in C++, with a Python interface.

install caffe ubuntu1

Installing Caffe for CPU-only Version from Default Repo on Ubuntu 17.04/18.04


Caffe package and all its dependency packages are alreay available on Ubuntu 17.04 and 18.04 Linux. So you just need to install Caffe with apt install command using the following command:

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install caffe-cpu

Outputs:

devops@devops-osetc:~$ sudo apt install caffe-cpu
[sudo] password for devops:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
augeas-lenses cpu-checker cryptsetup cryptsetup-bin db-util db5.3-util dmeventd extlinux hfsplus icoutils ipxe-qemu ipxe-qemu-256k-compat-efi-roms
ldmtool libafflib0v5 libaugeas0 libbfio1 libcacard0 libconfig9 libdate-manip-perl libdevmapper-event1.02.1 libewf2 libfdt1 libhfsp0 libhivex0
libintl-perl libintl-xs-perl libiscsi7 libldm-1.0-0 liblvm2app2.2 liblvm2cmd2.02 librados2 librbd1 libsdl1.2debian libspice-server1 libssl-doc
libstring-shellquote-perl libsys-virt-perl libtsk13 libusbredirparser1 libvirt0 libwin-hivex-perl libxen-4.9 libxenstore3.0 lsscsi lvm2 msr-tools
osinfo-db qemu-block-extra qemu-system-common qemu-system-x86 qemu-utils scrub seabios sgabios sleuthkit supermin zerofree
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
blt caffe-tools-cpu cython3 fonts-lyx gdal-data libaec0 libarmadillo8 libarpack2 libblas3 libblosc1 libcaffe-cpu1 libcharls1 libdap25 libdapclient6v5
libepsilon1 libfreexl1 libfyba0 libgdal20 libgdcm2.8 libgeos-3.6.2 libgeos-c1v5 libgeotiff2 libgflags2.2 libgfortran4 libgoogle-glog0v5 libhdf4-0-alt
libhdf5-100 libjs-jquery-ui libkmlbase1 libkmldom1 libkmlengine1 liblapack3 libleveldb1v5 liblmdb0 libminizip1 libmysqlclient20 libnetcdf13 libodbc1
libogdi3.2 libopencv-core3.2 libopencv-imgcodecs3.2 libopencv-imgproc3.2 libopenjp2-7 libpq5 libproj12 libqhull7 libsnappy1v5 libsocket++1
libspatialite7 libsuperlu5 libsz2 libtbb2 liburiparser1 libxerces-c3.2 odbcinst odbcinst1debian2 proj-bin proj-data python-matplotlib-data
python-tables-data python3-caffe-cpu python3-cycler python3-dateutil python3-decorator python3-gflags python3-h5py python3-ipython
python3-ipython-genutils python3-leveldb python3-matplotlib python3-networkx python3-nose python3-numexpr python3-numpy python3-pandas
python3-pandas-lib python3-pickleshare python3-prompt-toolkit python3-pygments python3-pywt python3-scipy python3-simplegeneric python3-skimage
python3-skimage-lib python3-tables python3-tables-lib python3-tk python3-traitlets python3-wcwidth tk8.6-blt2.5 ttf-bitstream-vera
Suggested packages:
blt-demo libcaffe-cpu-dev caffe-doc cython-doc geotiff-bin gdal-bin libgeotiff-epsg libhdf4-doc libhdf4-alt-dev hdf4-tools libjs-jquery-ui-docs
libmyodbc odbc-postgresql tdsodbc unixodbc-bin ogdi-bin python-cycler-doc python-h5py-doc dvipng ffmpeg inkscape ipython3 python-matplotlib-doc
python3-cairocffi python3-gobject python3-pyqt4 python3-sip python3-tornado texlive-extra-utils texlive-latex-extra ttf-staypuft python3-pydotplus
python-nose-doc gfortran python-numpy-doc python3-numpy-dbg python-pandas-doc python-scipy-doc python-skimage-doc python-tables-doc python3-netcdf4
vitables tix python3-tk-dbg
The following NEW packages will be installed:
blt caffe-cpu caffe-tools-cpu cython3 fonts-lyx gdal-data libaec0 libarmadillo8 libarpack2 libblas3 libblosc1 libcaffe-cpu1 libcharls1 libdap25
libdapclient6v5 libepsilon1 libfreexl1 libfyba0 libgdal20 libgdcm2.8 libgeos-3.6.2 libgeos-c1v5 libgeotiff2 libgflags2.2 libgfortran4
libgoogle-glog0v5 libhdf4-0-alt libhdf5-100 libjs-jquery-ui libkmlbase1 libkmldom1 libkmlengine1 liblapack3 libleveldb1v5 liblmdb0 libminizip1
libmysqlclient20 libnetcdf13 libodbc1 libogdi3.2 libopencv-core3.2 libopencv-imgcodecs3.2 libopencv-imgproc3.2 libopenjp2-7 libpq5 libproj12 libqhull7
libsnappy1v5 libsocket++1 libspatialite7 libsuperlu5 libsz2 libtbb2 liburiparser1 libxerces-c3.2 odbcinst odbcinst1debian2 proj-bin proj-data
python-matplotlib-data python-tables-data python3-caffe-cpu python3-cycler python3-dateutil python3-decorator python3-gflags python3-h5py
python3-ipython python3-ipython-genutils python3-leveldb python3-matplotlib python3-networkx python3-nose python3-numexpr python3-numpy python3-pandas
python3-pandas-lib python3-pickleshare python3-prompt-toolkit python3-pygments python3-pywt python3-scipy python3-simplegeneric python3-skimage
python3-skimage-lib python3-tables python3-tables-lib python3-tk python3-traitlets python3-wcwidth tk8.6-blt2.5 ttf-bitstream-vera
0 upgraded, 92 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,320 kB/79.7 MB of archives.
After this operation, 292 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://mirrors.aliyun.com/ubuntu bionic-updates/universe amd64 liblmdb0 amd64 0.9.21-1ubuntu0.1 [44.6 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic/universe amd64 libcaffe-cpu1 amd64 1.0.0-6 [798 kB]
Get:3 http://mirrors.aliyun.com/ubuntu bionic/universe amd64 caffe-tools-cpu amd64 1.0.0-6 [109 kB]
.......
Setting up python3-ipython (5.5.0-1) ...
Setting up liblapack3:amd64 (3.7.1-4ubuntu1) ...
update-alternatives: using /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3 to provide /usr/lib/x86_64-linux-gnu/liblapack.so.3 (liblapack.so.3-x86_64-linux-gnu) in auto mode
Setting up libsuperlu5:amd64 (5.2.1+dfsg1-3) ...
Setting up libkmlbase1:amd64 (1.3.0-5) ...
Setting up libleveldb1v5:amd64 (1.20-2) ...
Setting up libogdi3.2 (3.2.0+ds-2) ...
Setting up proj-bin (4.9.3-2) ...
Setting up python3-networkx (1.11-1ubuntu3) ...
Setting up libgeotiff2:amd64 (1.4.2-2build1) ...
Setting up libnetcdf13:amd64 (1:4.6.0-2build1) ...
Setting up libspatialite7:amd64 (4.3.0a-5build1) ...
Setting up libarpack2:amd64 (3.5.0+real-2) ...
Setting up libkmldom1:amd64 (1.3.0-5) ...
Setting up python3-tk:amd64 (3.6.7-1~18.04) ...
Setting up python3-leveldb (0~svn68-3build3) ...
Setting up python3-numpy (1:1.13.3-2ubuntu1) ...
Setting up python3-skimage-lib:amd64 (0.13.1-2) ...
Setting up python3-pandas-lib (0.22.0-4) ...
Setting up libarmadillo8 (1:8.400.0+dfsg-2) ...
Setting up libkmlengine1:amd64 (1.3.0-5) ...
Setting up python3-pywt (0.5.1-1.1ubuntu4) ...
Setting up python3-pandas (0.22.0-4) ...
Setting up python3-matplotlib (2.1.1-2ubuntu3) ...
Setting up python3-h5py (2.7.1-2) ...
Setting up python3-scipy (0.19.1-2ubuntu1) ...
Setting up python3-tables-lib (3.4.2-4) ...
Setting up python3-numexpr (2.6.4-1) ...
Setting up python3-tables (3.4.2-4) ...
Setting up python3-skimage (0.13.1-2) ...
Setting up odbcinst1debian2:amd64 (2.3.4-1.1ubuntu3) ...
Setting up odbcinst (2.3.4-1.1ubuntu3) ...
Setting up libgdal20 (2.2.3+dfsg-2) ...
Setting up libopencv-imgcodecs3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libcaffe-cpu1:amd64 (1.0.0-6) ...
Setting up caffe-tools-cpu (1.0.0-6) ...
Setting up python3-caffe-cpu (1.0.0-6) ...
Setting up caffe-cpu (1.0.0-6) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

After installed Caffe on your system, you can try to import it from python3 to check if caffe module can be imported, type:

$ python3

Outputs:

devops@devops-osetc:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>>

When you enter into python3 interpreter, you need to type import caffe command to import caffe module. If you do not get any error message, it indicates that caffe has been imported successfully.

Installing Caffe for CUDA Version from Default Repo on Ubuntu 17.04/18.04


If you want to install Caffe for CUDA Version on Ubuntu 17.04 or 18.04 Linux, you also need to use apt install command to install all packages, type:

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install caffe-cuda

Outputs:

devops@devops-osetc:~$ sudo apt install caffe-cuda
[sudo] password for devops:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
augeas-lenses cpu-checker cryptsetup cryptsetup-bin db-util db5.3-util dmeventd extlinux hfsplus icoutils ipxe-qemu ipxe-qemu-256k-compat-efi-roms
ldmtool libafflib0v5 libaugeas0 libbfio1 libcacard0 libconfig9 libdate-manip-perl libdevmapper-event1.02.1 libewf2 libfdt1 libhfsp0 libhivex0
libintl-perl libintl-xs-perl libiscsi7 libldm-1.0-0 liblvm2app2.2 liblvm2cmd2.02 librados2 librbd1 libsdl1.2debian libspice-server1 libssl-doc
libstring-shellquote-perl libsys-virt-perl libtsk13 libusbredirparser1 libvirt0 libwin-hivex-perl libxen-4.9 libxenstore3.0 lsscsi lvm2 msr-tools
osinfo-db qemu-block-extra qemu-system-common qemu-system-x86 qemu-utils scrub seabios sgabios sleuthkit supermin zerofree
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
caffe-tools-cuda libcaffe-cuda1 libcublas9.1 libcudart9.1 libcurand9.1 libnvidia-compute-390 python3-caffe-cuda
Suggested packages:
libcaffe-cuda-dev caffe-doc
The following packages will be REMOVED:
caffe-cpu caffe-tools-cpu libcaffe-cpu1 python3-caffe-cpu
The following NEW packages will be installed:
caffe-cuda caffe-tools-cuda libcaffe-cuda1 libcublas9.1 libcudart9.1 libcurand9.1 libnvidia-compute-390 python3-caffe-cuda
0 upgraded, 8 newly installed, 4 to remove and 0 not upgraded.
Need to get 87.0 MB of archives.
After this operation, 206 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
......
Get:5 http://mirrors.aliyun.com/ubuntu bionic/multiverse amd64 caffe-tools-cuda amd64 1.0.0-6build1 [105 kB]
Get:6 http://mirrors.aliyun.com/ubuntu bionic/multiverse amd64 python3-caffe-cuda amd64 1.0.0-6build1 [689 kB]
Get:7 http://mirrors.aliyun.com/ubuntu bionic/multiverse amd64 caffe-cuda amd64 1.0.0-6build1 [4,564 B]

Selecting previously unselected package libnvidia-compute-390:amd64.
Preparing to unpack .../7-libnvidia-compute-390_390.116-0ubuntu0.18.04.1_amd64.deb ...
Unpacking libnvidia-compute-390:amd64 (390.116-0ubuntu0.18.04.1) ...
Setting up libnvidia-compute-390:amd64 (390.116-0ubuntu0.18.04.1) ...
Setting up libcurand9.1:amd64 (9.1.85-3ubuntu1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Setting up libcublas9.1:amd64 (9.1.85-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up libcudart9.1:amd64 (9.1.85-3ubuntu1) ...
Setting up libcaffe-cuda1:amd64 (1.0.0-6build1) ...
Setting up python3-caffe-cuda (1.0.0-6build1) ...
Setting up caffe-tools-cuda (1.0.0-6build1) ...
Setting up caffe-cuda (1.0.0-6build1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

Installing Caffe for CPU-only Version from Source Code on Ubuntu 16.04/17.04/18.04


If you are using Ubuntu 16.04 Linux or other high versions of Ubuntu Linux, or you want to install the latest version of Caffe for CPU-only version on your Ubuntu system, you can install Caffe by compiling source code. Here are the steps:

#1 you need to install all of dependency package on your system with the following command:

$ sudo apt install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler python-dev libgflags-dev libgoogle-glog-dev liblmdb-dev libboost-all-dev libatlas-base-dev libopenblas-dev libopencv-dev python-opencv python-pip python-dev python-protobuf build-essential

The outputs are shown as below:

devops@devops-osetc:~$ sudo apt install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler python-dev libgflags-dev libgoogle-glog-dev liblmdb-dev libboost-all-dev libatlas-base-dev libopenblas-dev libopencv-dev python-opencv python-pip python-dev python-protobuf build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version (12.4ubuntu1).
python-dev is already the newest version (2.7.15~rc1-1).
libboost-all-dev is already the newest version (1.65.1.0ubuntu1).
python-pip is already the newest version (9.0.1-2.3~ubuntu1).

0 upgraded, 122 newly installed, 0 to remove and 0 not upgraded.
Need to get 25.1 MB/94.7 MB of archives.
After this operation, 552 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
....
Setting up libavformat-dev:amd64 (7:3.4.4-0ubuntu0.18.04.1) ...
Setting up libopencv-superres-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-highgui3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-objdetect3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-viz3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-highgui-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-features2d3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-features2d-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-calib3d3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-viz-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-stitching3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-calib3d-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-objdetect-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-videostab3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-stitching-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-contrib3.2:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-videostab-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-contrib-dev:amd64 (3.2.0+dfsg-4ubuntu0.1) ...
Setting up python-opencv (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv3.2-jni (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv3.2-java (3.2.0+dfsg-4ubuntu0.1) ...
Setting up libopencv-dev (3.2.0+dfsg-4ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

#2 you can start to get source code of Caffe from github with the following git command, type:

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

Outputs:

devops@devops-osetc:~$ git clone https://github.com/BVLC/caffe
Cloning into 'caffe'...
remote: Enumerating objects: 65066, done.
remote: Total 65066 (delta 0), reused 0 (delta 0), pack-reused 65066
Receiving objects: 100% (65066/65066), 72.61 MiB | 401.00 KiB/s, done.
Resolving deltas: 100% (41105/41105), done.

#3 After cloned caffe to your local disk, you can see that one directory called caffe is created on your current directory(/home/devops). Using the following command to list all files in caffe directory and then change the current directory to caffe:

$ ls ./caffe
$ cd ./caffe

Outputs:

devops@devops-osetc:~$ cd caffe/

devops@devops-osetc:~/caffe$ ls
build data INSTALL.md models
caffe.cloc distribute LICENSE python
cmake docker Makefile README.md
CMakeLists.txt docs Makefile.config scripts
CONTRIBUTING.md examples Makefile.config.example src
CONTRIBUTORS.md include matlab tools

#4 You need to create a makefile called Makefile.config in the caffe directory with vi/vim command, type:

$ sudo vi Makefile.config

Adding the following lines into it:

CPU_ONLY := 1
OPENCV_VERSION := 3
CUSTOM_CXX := g++
CUDA_DIR := /usr/local/cuda
CUDA_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
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include
PYTHON_LIB := /usr/lib
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
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
TEST_GPUID := 0
Q ?= @

Save and close this file.

#5 then you can execute the following command one after the other:

$ make all
$ make test
$ make run test

Outputs:

devops@devops-osetc:~/caffe$ make all
PROTOC src/caffe/proto/caffe.proto
CXX .build_release/src/caffe/proto/caffe.pb.cc
CXX src/caffe/solver.cpp
CXX src/caffe/parallel.cpp
CXX src/caffe/net.cpp
CXX src/caffe/layers/prelu_layer.cpp
CXX src/caffe/layers/contrastive_loss_layer.cpp
CXX src/caffe/layers/cudnn_lrn_layer.cpp
CXX src/caffe/layers/batch_norm_layer.cpp
CXX src/caffe/layers/threshold_layer.cpp
CXX src/caffe/layers/base_conv_layer.cpp
CXX src/caffe/layers/tanh_layer.cpp
CXX src/caffe/layers/inner_product_layer.cpp
CXX src/caffe/layers/flatten_layer.cpp
CXX src/caffe/layers/eltwise_layer.cpp
CXX src/caffe/layers/relu_layer.cpp
CXX src/caffe/layers/base_data_layer.cpp
......
CXX src/caffe/blob.cpp
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0
CXX tools/upgrade_solver_proto_text.cpp
CXX/LD -o .build_release/tools/upgrade_solver_proto_text.bin
CXX tools/upgrade_net_proto_binary.cpp
CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin
CXX tools/compute_image_mean.cpp
CXX/LD -o .build_release/tools/compute_image_mean.bin
CXX tools/convert_imageset.cpp
CXX/LD -o .build_release/tools/convert_imageset.bin
CXX tools/upgrade_net_proto_text.cpp
CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin
CXX tools/extract_features.cpp
CXX/LD -o .build_release/tools/extract_features.bin
CXX tools/caffe.cpp
CXX/LD -o .build_release/tools/caffe.bin
CXX examples/cifar10/convert_cifar_data.cpp
CXX/LD -o .build_release/examples/cifar10/convert_cifar_data.bin
CXX examples/cpp_classification/classification.cpp
CXX/LD -o .build_release/examples/cpp_classification/classification.bin
CXX examples/mnist/convert_mnist_data.cpp
CXX/LD -o .build_release/examples/mnist/convert_mnist_data.bin
CXX examples/siamese/convert_mnist_siamese_data.cpp
CXX/LD -o .build_release/examples/siamese/convert_mnist_siamese_data.bin

devops@devops-osetc:~/caffe$ echo $?
0


devops@devops-osetc:~/caffe$ make test
CXX src/caffe/test/test_reshape_layer.cpp
CXX src/caffe/test/test_blob.cpp
CXX src/caffe/test/test_euclidean_loss_layer.cpp
CXX src/caffe/test/test_db.cpp
CXX src/caffe/test/test_common.cpp
CXX src/caffe/test/test_rnn_layer.cpp
CXX src/caffe/test/test_hinge_loss_layer.cpp
CXX src/caffe/test/test_random_number_generator.cpp
CXX src/caffe/test/test_util_blas.cpp
CXX src/caffe/test/test_slice_layer.cpp
CXX src/caffe/test/test_argmax_layer.cpp
CXX src/caffe/test/test_contrastive_loss_layer.cpp
CXX src/caffe/test/test_gradient_based_solver.cpp
CXX src/caffe/test/test_dummy_data_layer.cpp
CXX src/caffe/test/test_bias_layer.cpp
CXX src/caffe/test/test_neuron_layer.cpp
......
LD .build_release/src/caffe/test/test_tanh_layer.o
LD .build_release/src/caffe/test/test_multinomial_logistic_loss_layer.o
LD .build_release/src/caffe/test/test_filler.o
LD .build_release/src/caffe/test/test_internal_thread.o
LD .build_release/src/caffe/test/test_tile_layer.o
LD .build_release/src/caffe/test/test_math_functions.o

devops@devops-osetc:~/caffe$ echo $?
0


$ make runtest
[----------] 5 tests from SPPLayerTest/0, where TypeParam = caffe::CPUDevice<float>
[ RUN ] SPPLayerTest/0.TestEqualOutputDims
[ OK ] SPPLayerTest/0.TestEqualOutputDims (1 ms)
[ RUN ] SPPLayerTest/0.TestForwardBackward
[ OK ] SPPLayerTest/0.TestForwardBackward (0 ms)
[ RUN ] SPPLayerTest/0.TestSetup
[ OK ] SPPLayerTest/0.TestSetup (0 ms)
[ RUN ] SPPLayerTest/0.TestEqualOutputDims2
[ OK ] SPPLayerTest/0.TestEqualOutputDims2 (0 ms)
[ RUN ] SPPLayerTest/0.TestGradient
[ OK ] SPPLayerTest/0.TestGradient (2822 ms)
[----------] 5 tests from SPPLayerTest/0 (2829 ms total)

[----------] Global test environment tear-down
[==========] 1162 tests from 152 test cases ran. (138945 ms total)
[ PASSED ] 1162 tests.

Note: you need to make sure these commands can run smmothly without any errors.

#6 Once all above commands can be executed without any errors, you can run the following command to build a python wrapper, and it will generate a python directory in the caffe directory.

$ make pycaffe

Outputs:

devops@devops-osetc:~/caffe$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
touch python/caffe/proto/__init__.py
PROTOC (python) src/caffe/proto/caffe.proto

devops@devops-osetc:~/caffe$ echo $?
0

#7 you still need to export PYTHONPATH variable as /home/devops/caffe/python (it created in the step 6), type:

$ export PYTHONPATH=/home/devops/caffe/python:$PYTHONPATH

#8 you can try to import caffe module in python terminal with import caffe command, type:

$ python

Outputs:

devops@devops-osetc:~/caffe$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/devops/caffe/python/caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "/home/devops/caffe/python/caffe/pycaffe.py", line 15, in <module>
import caffe.io
File "/home/devops/caffe/python/caffe/io.py", line 2, in <module>
import skimage.io
ImportError: No module named skimage.io
>>>

From the above outputs, you should see that there is one import error “ImportError: No module named skimage.io“. How to fix it. You need to install python-skimage package on your system, using the following command to install it:

$ sudo apt install python-skimage

After installed python-skimage package, you can retry to import caffe module in python terminal:

devops@devops-osetc:~/caffe$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>>

From the above outputs, you can see that the Caffe module has been imported.

Conclusion


You should know that how to install Caffe on Ubuntu 16.04 or 17.04 or 18.04 Linux from this guide, and you also know how to install Caffe for CPU-only version and GPU-only version  with the different methods on Ubuntu Linux server(default ubuntu repo,  Source code). If you want to see more information about Caffe, you can go the official web site of Caffe directly.

You might also like:

Sidebar



back to top