Home

Awesome

Implementation of VisualBackProp for MXNet

This repo contains an implementation of VisualBackProp for MXNet.

Requirements

  1. Make sure to use Python 3 (the code creating the symbol for VisualBackProp should also work with Python2)
  2. Install MXNet as shown here. Make sure that you have at least MXNet v0.10.0!
  3. Install further requirements by issuing pip install -r requirements.txt
  4. If you want to use the show_progress.py script you also need to install tkinter (in case the script does not work right from the start)

Usage

The file vis_backprop_test.py contains a sample that trains MNIST and performs VisualBackprop on every forward pass. In order to use the script, you have to do the following:

  1. start the script show_progress.py by issuing python show_progress.py
  2. start the training of the network by issuing python vis_backprop_test.py

Adding VisualBackProp to your own code

Adding VisualBackProp to your own code ist quite easy. You have to perform the following steps:

  1. adapt your symbol definition, by adding a call to insights.build_visual_backprop_symbol after the activation of the convolutional layer you want to visualize. (see this line)
  2. keep the returned visualization symbol for the visualization pass.
  3. If you want to use VisualBackProp during the training, for each training step, you have to create an instance of the VisualBackpropPlotter class, providing an ip and port for the visualization endpoint. (see this line)
  4. get one sample image where you want to visualize the convolution (see this line).
  5. add a new batch_end_callback to your model, by calling the method get_callback of the created VisualBackpropPlotter object (see this line).
  6. start the show_progress.py tool, that you can find in the utils directory, by issuing the following command: python show_progress.py. (This tool is the visualization endpoint)
  7. Sit back and enjoy!

How does it work?

insights.build_visual_backprop_symbol adds a new subgraph to the computational graph that performs the necessary operations for VisualBackProp (see the paper for more details). During a forward pass MXNet calls the callback implemented in VisualBackpropPlotter. This callback copies the current params and performs a forward pass with the given input data. After this forward pass, the output generated by the VisualBackProp branch is extracted and converted into an image. Together with the original image, this image is send to the visualization endpoint.

You can also use this implementation during testing, by performing the exact same steps as the VisualBackpropPlotter you just don't need to send the resulting image to someone, but can save it to the disk.

License

This code is licensed under the GPLv3 license.