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.pyscript 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.pyby 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
-hto thepythoncommand.
Adding VisualBackProp to your own code ist quite easy. You have to perform the following steps:
- adapt your
symboldefinition, by adding a call toinsights.build_visual_backprop_symbolafter the activation of the convolutional layer you want to visualize. (see this line) - keep the returned visualization
symbolfor the visualization pass. - If you want to use VisualBackProp during the training, for each training step, you have to create an instance of the
VisualBackpropPlotterclass, 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_callbackto your model, by calling the methodget_callbackof the createdVisualBackpropPlotterobject (see this line). - start the
show_progress.pytool, that you can find in theutilsdirectory, 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.