Lab 9

Deep Learning with Caffe

In this lab we'll explore Deep Neural Net (DNN) learning with the Caffe framework. We'll do three tutorials, the last two of which are very powerful, but which you should be able to apply to a new problem fairly easily:

* Object classification with a pre-trained model.

* From-scratch training of a small (handwritten digit) collection.

* Fine-tuning of a large model using a modest amount of training data.

Remember when you connect to your EC2 instance "don't do sudo yum update", it will break the graphics driver. If you already did it, YOU CAN'T FIX IT... Send us an e-mail please....

First, connect to your EC2 instance. You should do this assignment as ec-user (since you will be modifying files in /opt/caffe). You can login separately to browse the filesystem, but only one person in your group should execute the scripts. Its fine to work on this assignment with your group, but please all submit responses individually.

Object Classification

Caffe has a set of example notebooks in /opt/caffe/examples. Go to that directory and start an ipython notebook (not an IScala notebook). Follow the directions for Lab 8 on setting up your connection with ssh tunnels. Select 00-classification.ipynb and work through it.

MNIST Digit Recognition

Follow the tutorial on the LeNet network Links to an external site. which is in the 01-learning-lenet.ipynb notebook in the examples dir.

Notes (please read and follow):

  • Since the scripts use the same directory, only one member of your group should run them (as ec2-user).
  • To save resources, shut down each tutorial before starting the next. You do this from the Home window in Ipython.
  • Modify the path in the second cell to sys.path.insert(0, '/opt/caffe/python'). Otherwise the script will lose the path to caffe when it changes directories.
  • You dont need to execute the data download in the third code cell (slow). Its already on your disk. Read the tutorial carefully and then go ahead and train the network.

TODO: What was the final network accuracy? How does that compare with the kNN classifier from Lab 6? Save your response for the Lab 9 responses.

Fine-Tuning of Flickr Style

First, take a look at this web site Links to an external site. to get an idea of what "styles" were trained for this classifier.

The approach is described in this paper Links to an external site..

Start the Flickr style tutorial Links to an external site. which is in 03-fine-tuning.ipynb

Notes:

  • Set the path in the first cell like this: sys.path.insert(0, '/opt/caffe/python')

TODO: What accuracy did the classifier reach after 400 iterations?

When you're done, take a look at the Flickr style training data, which is in /opt/caffe/data/flickr_style. Notice that the train and test file consist of simple lines with a filename (an image) and a number (the class to which the image belongs). The images themselves are in a subdirectory.

Its very easy to create this structure with any new dataset that you might have, and then to run a (slightly modified) Flickr_style training recipe to train it. That way, you can build quite accurate classifiers for natural objects with a fraction of the training time of from-scratch training, and with much less labeled data.

Lab 9 Responses

Fill out the Lab 9 responses here.

If you Finish Early

Try the filter_visualization2.ipynb from /opt/caffe/examples which illustrates graphically what the various layers in a DNN are doing.

Aside: ImageNet Images

You probably dont want to use it, but the full ImageNet (ILSVRC2012 challenge, around 1 million images)  dataset is available on your instance's disk. The raw images are in /data/ImageNet/2012resized.tar.gz while the uncompressed images are in /opt/caffe/examples/imagenet as ilsvrc12_train_leveldb and ilsvrc12_val_leveldb.They allow you to train a full-accuracy DNN on the ImageNet data from scratch. But you shouldn't need to do anything close to that for your project. Together, they take up about half of your 512 GB main disk. If you need extra space for your project, feel free to delete them.

Shut it Down

Dont forget to shut down your instance when you're done.