tf_cnnvis

InFoCusp

tf_cnnvis

tf_cnnvis is a CNN visualization library which you can use to better understand your own CNNs. We use the TensorFlow library at the backend and the generated images are displayed in TensorBoard. We have implemented 2 CNN visualization techniques so far:

1) Based on the paper Visualizing and Understanding Convolutional Networks by Matthew D. Zeiler and Rob Fergus. The goal here is to reconstruct the input image from the information contained in any given layers of the convolutional neural network. Here are a few examples

       

Figure 1: Original image and the reconstructed versions from maxpool layer 1,2 and 3 of Alexnet generated using tf_cnnvis.

2) CNN visualization based on Deep dream by Google. Here’s the relevant blog post explaining the technique. In essence, it attempts to construct an input image that maximizes the activation for a given output. We present some samples below:

       
Carbonara Ibex Elephant Ostrich
Cheese burger Tennis ball Fountain pen Clock tower
Cauliflower Baby Milk bottle Sea lion Dolphin

tensorboard.png

View Full size

Requirements:

If you are using pip you can install these with

pip install tensorflow numpy scipy h5py wget Pillow six scikit-image

Setup script

Clone the repository

#!bash

git clone https://github.com/InFoCusp/tf_cnnvis.git

And run

#!bash
sudo pip install setuptools
sudo python setup.py install
sudo python setup.py clean

API

tf_cnnvis.activation_visualization(graph_or_path, value_feed_dict, input_tensor=None, layers=’r’, path_logdir=’./Log’, path_outdir=’./Output’)

The function to generate the activation visualizations of the input image at the given layer.

Parameters

Returns

tf_cnnvis.deconv_visualization(graph_or_path, value_feed_dict, input_tensor=None, layers=’r’, path_logdir=’./Log’, path_outdir=’./Output’)

The function to generate the visualizations of the input image reconstructed from the feature maps of a given layer.

Parameters

Returns

tf_cnnvis.deepdream_visualization(graph_or_path, value_feed_dict, layer, classes, input_tensor=None, path_logdir=’./Log’, path_outdir=’./Output’)

The function to generate the visualizations of the input image reconstructed from the feature maps of a given layer.

Parameters

Returns

To visualize in TensorBoard

To start Tensorflow, run the following command on the console

#!bash

tensorboard --logdir=./Log

and on the TensorBoard homepage look under the Images tab

Additional helper functions

tf_cnnvis.utils.image_normalization(image, ubound=255.0, epsilon=1e-07)

Performs Min-Max image normalization. Transforms the pixel intensity values to range [0, ubound]

Parameters

Returns

tf_cnnvis.utils.convert_into_grid(Xs, padding=1, ubound=255.0)

Convert 4-D numpy array into a grid of images for display

Parameters

Returns