Skip to content

Fine-tune and analyze a deep neural network for visual recognition (AlexNet) with TensorFlow

Notifications You must be signed in to change notification settings

orlyliba/Fine_Tune_Analyze_Neural_Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fine tune and analyze deep-learning neural networks

Fine-tune and analyze a deep neural network for visual recognition (AlexNet) with TensorFlow.

This is a beginner-level project that starts with a pre-trained neural network and then fine-tunes it for a task of your choosing. It also includes code for analyzing the network, such as: visualizing the weights and layer activations, occlusion analysis, t-SNE and image with highest probability in class.

Code and weights for AlexNet in TensorFlow are from here (Thank you!)

Recommended steps:

  1. Install Python (+ numpy, matplotlib, scipy, sklearn...), Tensorflow and Jupyter Notebook. I've found that no matter what I did, Tensorflow did not work on Windows (as of Oct. 2016), therefore I used Linux (Ubuntu). I also recommend looking at other libraries for deep learning (such as Caffe, Torch, Theano...), because Tensorflow is not the only option and it's not perfect for every use. That said, TensorFlow is great for beginners who use Python.
  2. Run AlexNet pre-trained on ImageNet (weights and biases can be found here), and test out the classification (link).
  3. Visualize the behaviour of the network: look at the weights and activations of the different layers (link).
  4. Define the next task you would like the network to work on. As an example, I defined a task for classifying between dogs, cats and flowers. This code will download images based on a Google search. Then you'll need to crop or resize them to match the size expected by AlexNet (227x227x3) using this code. This project distinguishes between three classes, and you can change the number of classes in your task by updating the size of the fc8 layer in the network (search for n_classes).
  5. Fine-tune AlexNet. You can define or loop over different values of learning rates, drop-out, tuning depth (which layers will be fine-tuned), etc (link).
  6. Save your network (link).
  7. Find the images with the highest probability in each class (link).
  8. Visualize your network's behavior by plotting your images on a scatter plot using t-SNE (link). This was done in collaboration with Tanya Glozman.
  9. Occlusion analysis is a nice way of visializing which regions in your image are significant for your network's decision (link).

Occlusion analysis

Probability map for correctly classifying the cat, as function of the location of an occluding square in the image. The probability for classifying the cat correctly reduces when the cat's face is occluded.

t-SNE visualization

A 2-dimensional representation of the output of the network, showing the separation between images of different classes (cats, dogs and flowers).

Recommended reading:

About

Fine-tune and analyze a deep neural network for visual recognition (AlexNet) with TensorFlow

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published