Visualization toolkit for neural networks in PyTorch! Demo -->
The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:
A Python visualization toolkit, built with PyTorch, for neural networks in PyTorch.
Neural networks are often described as "black box". The lack of understanding on how neural networks make predictions enables unpredictable/biased models, causing real harm to society and a loss of trust in AI-assisted systems.
Feature visualization is an area of research, which aims to understand how neural networks perceive images. However, implementing such techniques is often complicated.
FlashTorch was created to solve this problem!
It is compatible with pre-trained models that come with torchvision, and seamlessly integrates with other custom models built in PyTorch.
Take a look at the quick 3min intro/demo to FlashTorch below!
Head over to example notebooks on Colab!
If you are installing FlashTorch for the first time:
$ pip install flashtorch
Or if you are upgrading it:
$ pip install flashtorch -U
These are currently available modules.
flashtorch.utils: some useful utility functions for data handling & transformation
ImageNetIndexclass for easy-ish retrieval of class index
Backpropclass for calculating gradients
GradientAscentclass for activation maximization
You can inspect each module with Python built-in function
help. The output of that is available on Quick API Guide for your convenience.
Below, you can find simple demos to get you started, as well as links to some handy notebooks showing additional examples of using FlashTorch.
Saliency in human visual perception is a subjective quality that makes certain things within the field of view stand out from the rest and grabs our attention.
Saliency maps in computer vision provide indications of the most salient regions within images. By creating a saliency map for neural networks, we can gain some intuition on "where the network is paying the most attention to" in an input image.
flashtorch.saliencymodule, let's visualize image-specific class saliency maps of AlexNet pre-trained on ImageNet classification tasks.
The network is focusing on the sunken eyes and the round head for this owl.
Activation maximization is one form of feature visualization that allows us to visualize what CNN filters are "looking for", by applying each filter to an input image and updating the input image so as to maximize the activation of the filter of interest (i.e. treating it as a gradient ascent task with filter activation values as the loss).
flashtorch.activmaxmodule, let's visualize images optimized with filters from VGG16 pre-trained on ImageNet classification tasks.
Concepts such as 'eyes' (filter 45) and 'entrances (?)' (filter 271) seem to appear in the conv5_1 layer of VGG16.
Visit the notebook above to see what earlier layers do!
Here is how to setup a dev environment for FlashTorch.
From the project root:
Create a conda environment.
$ conda env create -f environment.yml
Activate the environment.
$ conda activate flashtorch
Install FlashTorch in a development mode.
$ pip install -e .
Run the linter & test suit.
$ flake8 flashtorch tests && pytest
Add a kernel to Jupyter notebook.
$ python -m ipykernel install --user --name flashtorch \ --display-name
Launch Jupyter notebook
$ jupyter notebook
Open a notebook in the
From the top menu,
From the top menu,
If the test suit runs and all the cells in the notebook execute - congratulations, you're good to go!
If you encounter any problem setting up the dev environment, please open an issue.
Thanks for your interest in contributing!
Please first head over to the Code of Conduct, which helps set the ground rules for participation in communities and helps build a culture of respect.
Next, please make sure that you have a dev environment set up (see the Develop FlashTorch section above).
Still here? Great! There are many ways to contribute to this project. Get started here.
Introduction and overview of feature visualization: Feature Visualization
The latest development in feature visualization: Exploring Neural Networks with Activation Atlases
Using backpropagation for gradient visualization: Deep Inside Convolutional Networks: Visualising Image Classification Models and Saliency Maps
Guided backprobagation: Striving for Simplicity: The All Convolutional Net
Activation maximization: Visualizing Higher-Layer Features of a Deep Network
Misa Ogura, & Ravi Jain. (2020, January 2). MisaOgura/flashtorch: 0.1.2 (Version v0.1.2). Zenodo. http://doi.org/10.5281/zenodo.3596650