VERY QUICK SETUP of CaffeNet (AlexNet) for Image Classification Using Nvidia-Docker 2.0

Sik-Ho TsangCaffeNet (AlexNet) for Image Classification

In this story, we will have a VERY QUICK SETUP of a CaffeNet (AlexNet) for image classification using Nvidia-Docker 2.0 with GPU acceleration. (Sik-Ho Tsang @ Medium)

Originally, the installation of GPU, CUDA, CuDNN, Jupyter Notebook, and Caffe, which is very tedious and troublesome.

However, by using Nvidia-Docker 2.0, installation of CUDA + CuDNN +Jupyter Notebook + Caffe are much easier. Actually, we don’t need actual installation, instead, they are already well-installed in the docker image. We just need to pull the image from the repository.

Thus, one advantage of using Docker is that, we don’t need to process the tedious installation for CUDA, CuDNN, Caffe, in which the installation failure may occur due to the wrong step, hardware, or version compatibility problem.

Another advantage is to have numerous Docker working together within the same physical computer with different versions of software installed.

There are many choices for deep learning framework such as TensorFlow and PyTorch. And Caffe is the framework which is suitable to beginner. That’s the reason I choose Caffe in this tutorial.

In this story, we will cover:

  1. Running the Caffe Docker image Using the Nvidia-Docker 2.0
  2. Running the Jupyter Notebook
  3. Running the CaffeNet (AlexNet)

To use Nvidia-Docker 2.0, we need Ubuntu, GPU driver, Docker, Nvidia-Docker 2.0 installed. (There are other ways to have Nvidia-Docker 2.0, but I just describe my way here.)
If you already have installed all of the stuffs, please skip this prerequisites section and go to the next section.

1. Installation of Ubuntu

First of all, we need to install Ubuntu first. If you do not have Ubuntu installed, please follow the below story first:
Ubuntu 18.04 LTS Installation

2. Installation of GPU Driver

Then, we need to have GPU driver installed. It should be different for different display drivers. I am using GeForce GTX 1080Ti GPU. If you are using it as well, you can follow the below story:
GeForce GTX 1080Ti GPU NVIDIA Driver Installation in Ubuntu 18.04

3. Installation of Docker

Install the most basic Docker by following the story:
Docker Tutorial 1: Docker Installation in Ubuntu 18.04

4. Installation of Nvidia-Docker 2.0

Install Nvidia-Docker 2.0 by the following story:
Docker Tutorial 5: Nvidia-Docker 2.0 Installation in Ubuntu 18.04

CaffeNet is AlexNet indeed. The design of network architecture is nearly the same. The only main difference is that AlexNet using 2 GPUs for training while CaffeNet is the approximation of AlexNet using 1 GPU. Since often people would only have 1 GPU, they will use CaffeNet for experimental simulation instead of the 2-GPU AlexNet.

To run the latest Caffe Docker image:

sudo docker run –runtime=nvidia -it -p 8888:8888 bvlc/caffe:gpu bash

For the first time running the above command, pulling of the image will be appeared. We should at /workspace at the container now:

1.1 Check CUDA Version

We can check the CUDA version which is CUDA 8, not the latest 9.1. This is because BVLC not yet provide CUDA 9.1:

nvcc -version

1.2 Check CuDNN Version

The CuDNN version is 6.0. We can check the CuDNN version by:

cat /usr/include/x86_64-linux-gnu/cudnn-v*.h | grep CUDNN_MAJOR -A 2

2.1 At the container, upgrade pip first:

pip install –upgrade pip

2.2 Then install Jupyter Notebook:

pip install jupyter

2.3 Run the Jupyter Notebook:

jupyter notebook –allow-root –ip=

At the host, there is a HTTP path at the end, we can access the Jupyter Notebook at the host by:



Since running the jupyter notebook will hold the terminal, we can open another terminal accessing the same container by:

docker exec -it bash

At the host, we can launch the Firefox, and enter the above HTTP path with token to access the Jupyter Notebook. We should at root directory:

There is tutorial provided by Caffe. We can go to optcaffeexamples:

Then open the notebook file 00-classification.ipynb:

There are already many comments to describe the notebook. Thus, I don’t go through in details. In brief, this tutorial is to teach how to use a trained model. By going through the tutorial, we can know

3.1 How to Load the Trained CaffeNet Model for Image Classification:

31% for tabby cat (left) 97% for orangutan (right)

We can classify the cats, and even the cat types.

3.2 The Structure and Output of Each Layer in CaffeNet

Structure of each layer in CaffeNetOutput of each layer in CaffeNet

3.3 The Visualization of Filters (or Receptive Fields)

Though there are already CUDA, but the deep learning framework was not mature in the year of 2012. Number of layers are not as deep as those nowadays, but it is a really amazing deep learning network already.

That’s all for this story. Thanks. 🙂


[2012 NIPS] [AlexNet]
ImageNet Classification with Deep Convolutional Neural Networks

[2014 ACMMM] [Caffe]
Caffe: Convolutional Architecture for Fast Feature Embedding

To know more about Docker:

Docker Tutorial 1: Docker Installation in Ubuntu 18.04
Docker Tutorial 2: Pulling Image
Docker Tutorial 3: Running Image
Docker Tutorial 4: Exporting Container and Saving Image
Docker Tutorial 5: Nvidia-Docker 2.0 Installation in Ubuntu 18.04

Leave a Comment

Your email address will not be published. Required fields are marked *