Caffe installation on Xavier

Can I get help in installing caffe on xavier board please?

Hi,

Here are the steps:

1. Setup

sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe 
sudo add-apt-repository multiverse

2. Install dependencies

sudo apt-get install libboost-dev libboost-all-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev libatlas-base-dev liblmdb-dev libblas-dev libatlas-base-dev libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler

3. hdf5

sudo ln -s libhdf5_serial.so libhdf5.so
sudo ln -s libhdf5_serial_hl.so libhdf5_hl.so

4. Get source

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

5. Apply changes

diff --git a/Makefile b/Makefile
index b7660e85..14538a38 100644
--- a/Makefile
+++ b/Makefile
@@ -178,7 +178,7 @@ ifneq ($(CPU_ONLY), 1)
        LIBRARIES := cudart cublas curand
 endif
 
-LIBRARIES += glog gflags protobuf boost_system boost_filesystem m
+LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
 
 # handle IO dependencies
 USE_LEVELDB ?= 1
diff --git a/Makefile.config.example b/Makefile.config.example
index 24ca6327..46b81f7b 100644
--- a/Makefile.config.example
+++ b/Makefile.config.example
@@ -2,7 +2,7 @@
 # Contributions simplifying and improving our build system are welcome!
 
 # cuDNN acceleration switch (uncomment to build with cuDNN).
-# USE_CUDNN := 1
+USE_CUDNN := 1
 
 # CPU-only switch (uncomment to build without GPU support).
 # CPU_ONLY := 1
@@ -20,7 +20,7 @@
 # ALLOW_LMDB_NOLOCK := 1
 
 # Uncomment if you're using OpenCV 3
-# OPENCV_VERSION := 3
+OPENCV_VERSION := 3
 
 # To customize your choice of compiler, uncomment and set the following.
 # N.B. the default for Linux is g++ and the default for OSX is clang++
@@ -36,15 +36,8 @@ CUDA_DIR := /usr/local/cuda
 # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
 # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
 # For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
-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
+CUDA_ARCH := -gencode arch=compute_72,code=sm_72 \
+               -gencode arch=compute_72,code=compute_72
 
 # BLAS choice:
 # atlas for ATLAS (default)
@@ -94,7 +87,7 @@ PYTHON_LIB := /usr/lib
 # WITH_PYTHON_LAYER := 1
 
 # Whatever else you find you need goes here.
-INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
+INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
 LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
 
 # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies

6. Build

cp Makefile.config.example Makefile.config
make -j8

Thanks.

Thank you for quick assistance.

Followed the steps. Getting hd5 library error -

/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status
Makefile:582: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0] Error 1
1 Like

I solved this error by creating symlink to hdf5 .so files

Also I had to set OPENCV=3 flag

Hi,

Thanks for your feedback.
Update the installation steps in comment #2.

To install caffe-ssd,

GitHub - weiliu89/caffe at ssd use this git repo

Add these to LIBRARIES

hdf5_serial_hl hdf5_serial

in makefile

And do other mentioned changes in Makefile.config.example

Also to install pycaffe, it requires to add caffe PATH to PYTHONPATH.

Thanks for your feedback : )

@@ -94,7 +87,7 @@ PYTHON_LIB := /usr/lib

WITH_PYTHON_LAYER := 1

Whatever else you find you need goes here.

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

Hi
Can I get steps to install caffe with python3?

Hi,

Just remember to build the python wrapper after C++ library is set:

...
make -j8
<b>make pycaffe</b>

Thanks.

Hi.
I met the same question, can you tell me more details about how you fixed it? MANY THANKS!!!

Can I know little more about issue?

If it is about creating symbolic links -

locate hdf5 libaries
those are under

/usr/lib/aarch64-linux-gnu/libhdf5_serial.so

and same do for _hl file

this may help

find . -type f -exec sed -i -e 's^"hdf5.h"^"hdf5/serial/hdf5.h"^g' -e 's^"hdf5_hl.h"^"hdf5/serial/hdf5_hl.h"^g' '{}' \;

https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide

Thanks for your reply, I just install caffe on my xavier, but I dont think it works, I wonder how do i know whether i installed caffe or not can you plz give me some suggestion? I’m new hand in caffe. Waiting for your reply! thanks!

oh I can run the test model.
So I think I have some problems in making pycaffe I just did as AastaLLL said “make pycaffe” I think its something wrong. I use python 3.6.7 when i import caffe, it shows:

Traceback (most recent call last):
File “”, line 1, in
File “/home/nvidia/caffe/python/caffe/init.py”, line 1, in
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File “/home/nvidia/caffe/python/caffe/pycaffe.py”, line 13, in
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver,
ImportError: dynamic module does not define module export function (PyInit__caffe)

I stucked here. could you plz give me some suggestion? thanks a lot

I came across the same issue while installing on other xavier board.

nvidia@jetson-0423418049563:~$ 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
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nvidia/caffe/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
  File "/home/nvidia/caffe/python/caffe/pycaffe.py", line 13, in <module>
    from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: dynamic module does not define module export function (PyInit__caffe)

Hi,

Please try to add the caffe path into PYTHONPATH:

export PYTHONPATH=~/caffe/python/:$PYTHONPATH

Thanks.

I couldn’t find the solution and the reason.
Looks like it was issue with paths in sys.path
I removed some of them including caffe path then again cloned caffe and did all the steps it worked.

Also,
sometimes it gives error while importing caffe module
after soing

source ~/.bahsrc

It works fine.
It’s not consistent issue. In the same terminal it may occur anytime

Thanks for the feedback.
This information helps other users who meet the same problem.

hi
I successfully installed pycaffe.
You should install your caffe on your python3, but default is python2 , I changed the Makefile.config,like:

around Line 75  
#PYTHON_LIBRARIES:= boost_python3 python3.6m
#PYTHON_INCLUDE:=/usr/include/python3.6m
                 /usr/lib/python3.6/dist-packages/numpy/core/include

You just need to uncomment the two lines, and make clean, make, make pycaffe. When I import caffe in python3.6, it occurred that “No module named scimage” I installed it, and I can import caffe now! You can try it , hope this can help you !