Caffe - Q-engineering
Go to content
Caffe on Jetson Nano

Install Caffe on a Jetson Nano.


This page will guide you through the installation of Caffe on a Jetson Nano with CUDA and cuDNN support. We only guide you through the basics, so in the end, you can build your application. For more information about the Caffe, see:
The Caffe framework has a few dependencies to other libraries. We assume you have already installed OpenCV on your Jetson Nano according to our guides. If not, better to do it first.
$ sudo apt-get install cmake git unzip
$ sudo apt-get install libgoogle-glog-dev libgflags-dev
$ sudo apt-get install libprotobuf-dev libleveldb-dev liblmdb-dev
$ sudo apt-get install libsnappy-dev libhdf5-serial-dev protobuf-compiler
$ sudo apt-get install --no-install-recommends libboost-all-dev
$ sudo apt-get install libatlas-base-dev libopenblas-dev
$ sudo apt-get install the python3-dev python3-skimage
$ sudo -H pip3 install pydot
$ sudo apt-get install graphviz

Download Caffe.

When all required libraries are installed, Caffe can be downloaded.
On our GitHub page, you will find the famous Caffe clone from WeiLui89. Unlike the original Caffe, this version supports SSD operations. WeiLui was one of the original developers of the  Single Shot MultiBox Detector. For detailed information, see his article.
We special adapted his fork for OpenCV 4.4, cuDNN 8.0 and Python3. Also, we added some additional Makefile scripts for Raspberry Pi, Jetson Nano and Ubuntu.
$ cd ~
$ wget -O
$ unzip
$ mv caffe-ssd caffe

cuDNN 8.0.

As of version 8.0, NVIDIA has dropped the support of some cuDNN API calls which Caffe depends.
The compilation now generates "CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT was not declared in this scope".
The cudnnGetConvolutionForwardAlgorithm, cudnnGetConvolutionBackwardDataAlgorithm can be replaced by other calls.
However, the cudnnGetConvolutionBackwardFilterAlgorithm has no longer a suitable alternative.
It leaves you with three options.
  • Downgrade to cuDNN version 7.6, which we strongly advise against. It can cause an avalanche of other dependency problems.
  • Compile Caffe without cuDNN acceleration. Save and with CUDA still working a not too bad option.
  • Use the fix in out GitHub Caffe repo. We have set the outcome of the cudnnGetConvolutionBackwardFilterAlgorithm to a constant. The routine searches for the fastest cuDNN solution given the layer topography. Using the general CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0 you may not have the optimal choice, but still, one that works. By the way, the fix works only for cuDNN release 8.0. An older cuDNN version will compile with the original code.

Build Caffe.

We have created a configuration file for the Jetson Nano. It should work without errors. If the build fails, see the Caffe configuration page.
$ cd ~/caffe
# select the configuration
$ cp Makefile.config.JetsonNano_example Makefile.config
# start the build
$ make clean
$ make all -j4
$ make test -j4
$ make runtest -j4
Hopefully, you will see the screen below after make runtest, indicating that everything went well. The whole test takes more than 5 minutes to complete. Compared to a Raspberry Pi 4, it takes much more time. There are two reasons. First, with CUDA and cuDNN enabled, more tests are run, 2301 versus 1266. Second, in some tests the CUDA acceleration will perform heuristic searches to find on forehand the fastest algorithm later to be used in the test. The test is done in a few milliseconds, while the preparations can take a few seconds.

Caffe test output

There is some additional software you may want to compile. First, there is pycaffe. You will need this interface if you like to run Caffe in Python 3. Otherwise, Caffe will only run from the command line or from within a C++ program. See the original Caffe documentation for more info.
You can also run Caffe inside MATLAB. This time you need to make matcaffe. However, some lines in the Makefile.config needs to be set before you can successfully build matcaffe. Again, the original documentation is your friend here. After the pytest, your screen looks like something like the one below.
# Assuming you're still in ~/caffe
$ make pycaffe
$ make pytest
Pytest output

Time for the last instructions and your Caffe installation is ready to run on a Jetson Nano.
You need to add Caffe to your PYTHONPATH. This can be done in ~/.bashrc or ~/.profile. We choose bashrc. Open the file with and add the line export PYTHONPATH="$PYTHONPATH:$HOME/caffe/python" at the very end of the file.  Save and close with Crtl+X, Y and Enter as usual.
In the end, you can import Caffe now from any location as can be seen in the screenshot.
$ cd ~
$ sudo nano ~/.bashrc
# at the end of the file add the next line
export PYTHONPATH="${PYTHONPATH}:$HOME/caffe/python"
# save and close with
Ctrl+X, Y, Enter

Caffe Rdy

If you run into any problems building Caffe on the Jetson Nano, please refer to the configuration page.
Back to content