VERY QUICK SETUP for Style Recognition by Pretrained CaffeNet (AlexNet) Using Nvidia-Docker 2.0 + Caffe

Sik-Ho Tsang
4 min readAug 3, 2018
Using Pretrained Network for Style Recognition

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

In this story, we will cover:

  1. Pretrained Network Concept
  2. Run the Docker and Jupyter Notebook
  3. Comparison between pretrained network and network trained from scratch

Here, It is assumed to be that we’ve already installed Ubuntu + GPU driver + Docker + Nvidia-Docker 2.0, and known how to run the Caffe Docker image. If you are interested about this part, please follow these stories:
VERY QUICK SETUP of CaffeNet (AlexNet) for Image Classification Using Nvidia-Docker 2.0+ CUDA + CuDNN + Jupyter Notebook + Caffe
and
VERY QUICK SETUP of LeNet-5 for Handwritten Digit Classification Using Nvidia-Docker 2.0 + CUDA + CuDNN + Jupyter Notebook + Caffe

1. Pretrained Network Concept

Network from scratch

To have a well-trained model, usually we would need to have huge amount of samples for training a deep learning network from scratch. This is because the weights are randomly initialized without any meaning. We need huge amount of samples to perform the backpropagation to train the weights.

Pretrained Network

To reduce the amount of samples needed, using a pretrained network for other tasks is a common practice since the weights are already well-trained. Or alternatively, the weights have already gotten feature extraction and enhancement abilities from the input. We only need to re-train the pretrained network for our own purpose — that is called fine-tuning.

2. Run the Docker and Jupyter Notebook

To learn about the fine-tuning, we can learn it from Caffe tutorial.

First, run the caffe Docker image:

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

Run the Jupyter Notebook:

pip install --upgrade pip
pip install jupyter
jupyter notebook --allow-root --ip=0.0.0.0

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

http://<container>:8888/?token=<token>

or

http://127.0.0.1:8888/?token=<token>

3. Comparison between pretrained network and network trained from scratch

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 a tutorial provided by Caffe. We can go to \opt\caffe\examples.

Then open the notebook file 02-fine-tuning.ipynb:

There are already many comments to describe the notebook. I don’t go through one by one. In brief, this notebook tutorial is to compare a network trained from scratch and a network pretrained by AlexNet. But there are some interesting findings:

3.1 The loss and accuracy for pretrained network and network from scratch

We can see that, during training, the loss didn’t go down and the accuracy didn’t go up for the network from scratch, while the loss had a tendency to go down and the accuracy had a tendency to go up for the fine-tuned pretrained network.

Since there was only 200 iterations for training, therefore the accuracy is not too high. If we continue the training, the results will be better.

3.2 An example

An example with actual label of Pastel

By using network from scratch, only 18% for Pastel, and the network thinks that it has a chance to be a HDR photo.

By fine-tuning a pretrained network, about 90% for Pastel. This is pretty cool, Right?

Of course, if we use the AlexNet which is originally for the imagenet competition, it can identify the things inside the photo like plate and soup bowl.

References

Paper:

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

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

To know more 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

To know more about loading Caffe Docker image:

VERY QUICK SETUP of CaffeNet (AlexNet) for Image Classification Using Nvidia-Docker 2.0 + CUDA + CuDNN + Jupyter Notebook + Caffe
VERY QUICK SETUP of LeNet-5 for Handwritten Digit Classification Using Nvidia-Docker 2.0 + CUDA + CuDNN + Jupyter Notebook + Caffe

--

--

Sik-Ho Tsang

PhD, Researcher. I share what I learn. :) Linktree: https://linktr.ee/shtsang for Twitter, LinkedIn, etc.