This repo contains an implementation of VisualBackProp for MXNet.
- Make sure to use Python 3 (the code creating the symbol for VisualBackProp should also work with Python2)
- Install MXNet as shown here. Make sure that you have at least
MXNet v0.10.0
! - Install further requirements by issuing
pip install -r requirements.txt
- 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)
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:
- start the script
show_progress.py
by issuingpython show_progress.py
- start the training of the network by issuing
python vis_backprop_test.py
- if you want to change some options you can get a list of all supported by options by adding
-h
to thepython
command.
Adding VisualBackProp to your own code ist quite easy. You have to perform the following steps:
- adapt your
symbol
definition, by adding a call toinsights.build_visual_backprop_symbol
after the activation of the convolutional layer you want to visualize. (see this line) - keep the returned visualization
symbol
for the visualization pass. - 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) - get one sample image where you want to visualize the convolution (see this line).
- add a new
batch_end_callback
to your model, by calling the methodget_callback
of the createdVisualBackpropPlotter
object (see this line). - start the
show_progress.py
tool, that you can find in theutils
directory, by issuing the following command:python show_progress.py
. (This tool is the visualization endpoint) - Sit back and enjoy!
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.
This code is licensed under the GPLv3 license.