Visualization toolkit for neural networks in PyTorch! Demo -->

Overview

FlashTorch

PyPI - Python Version Build Status PyPI PyPI - License DOI Say Thanks!

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!

You can apply feature visualization techniques (such as saliency maps and activation maximization) on your model, with as little as a few lines of code.

It is compatible with pre-trained models that come with torchvision, and seamlessly integrates with other custom models built in PyTorch.

Interested?

Take a look at the quick 3min intro/demo to FlashTorch below!

FlashTorch demo

Want to try?

Head over to example notebooks on Colab!

  • Saliency maps: Saliency map demo

  • Activation maximization: Activation maximization demo

Overview

Installation

If you are installing FlashTorch for the first time:

$ pip install flashtorch

Or if you are upgrading it:

$ pip install flashtorch -U

API guide

These are currently available modules.

  • flashtorch.utils: some useful utility functions for data handling & transformation
  • flashtorch.utils.imagenet: ImageNetIndex class for easy-ish retrieval of class index
  • flashtorch.saliency.backprop: Backprop class for calculating gradients
  • flashtorch.activmax.gradient_ascent: GradientAscent class 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.

Quickstart

Use FlashTorch

Below, you can find simple demos to get you started, as well as links to some handy notebooks showing additional examples of using FlashTorch.

Image handling (flashtorch.utils)

Saliency maps (flashtorch.saliency)

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.

Using flashtorch.saliency module, let's visualize image-specific class saliency maps of AlexNet pre-trained on ImageNet classification tasks.

Saliency map of great grey owl in Alexnet

The network is focusing on the sunken eyes and the round head for this owl.

Activation maximization (flashtorch.activmax)

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).

Using flashtorch.activmax module, let's visualize images optimized with filters from VGG16 pre-trained on ImageNet classification tasks.

VGG16 conv5_1 filters

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!

Develop FlashTorch

Here is how to setup a dev environment for FlashTorch.

From the project root:

  1. Create a conda environment.

    $ conda env create -f environment.yml
    
  2. Activate the environment.

    $ conda activate flashtorch
    
  3. Install FlashTorch in a development mode.

    $ pip install -e .
    
  4. Run the linter & test suit.

    $ flake8 flashtorch tests && pytest
    
  5. Add a kernel to Jupyter notebook.

    $ python -m ipykernel install --user --name flashtorch \
      --display-name <e.g. flashtorch-dev>
    
  6. Launch Jupyter notebook

    $ jupyter notebook
    
  7. Open a notebook in the ./examples directory.

  8. From the top menu, Kernel -> Change kernel -> flashtorch-dev

  9. From the top menu, Cell -> Run All

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.

How to contribute

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.

Resources

Talks & blog posts

Reading

Inspiration

Citation

Misa Ogura, & Ravi Jain. (2020, January 2).
MisaOgura/flashtorch: 0.1.2 (Version v0.1.2).
Zenodo. http://doi.org/10.5281/zenodo.3596650

Author

Misa Ogura

Medium | twitter | LinkedIn

R&D Software Engineer @ BBC

Co-founder of Women Driven Development

Comments
  • Gradient Bug in backprop.visualize

    Gradient Bug in backprop.visualize

    I tried generating a saliency map using the following code:

    backprop = Backprop(net)
    target_class = 4
    backprop.visualize(image, target_class, guided=True)
    

    My net is a standard PyTorch neural network, and the image is a (1,3,84,84) image. However, I get the following error:

    File "visualizations.py", line 89, in test backprop.visualize(image, target_class, guided=True) File "/home/user/.local/lib/python3.6/site-packages/flashtorch/saliency/backprop.py", line 168, in visualize guided=guided) File "/home/user/.local/lib/python3.6/site-packages/flashtorch/saliency/backprop.py", line 120, in calculate_gradients output.backward(gradient=target) File "/home/user/.local/lib/python3.6/site-packages/torch/tensor.py", line 150, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph) File "/home/user/.local/lib/python3.6/site-packages/torch/autograd/init.py", line 99, in backward allow_unreachable=True) # allow_unreachable flag File "/home/user/.local/lib/python3.6/site-packages/flashtorch/saliency/backprop.py", line 214, in _record_gradients if self.gradients.shape == grad_in[0].shape: AttributeError: 'NoneType' object has no attribute 'shape'

    Do I need to turn the image into a parameter with requires_grad = True? Is this usually done by the load_image function? I found that this function was re-sizing my image to 224x224. Thanks for your help!

    bug 
    opened by goldblum 7
  • RuntimeError: size mismatch, m1: [1 x 588], m2: [12 x 10] at /pytorch/aten/src/THC/generic/THCTensorMathBlas.cu:268

    RuntimeError: size mismatch, m1: [1 x 588], m2: [12 x 10] at /pytorch/aten/src/THC/generic/THCTensorMathBlas.cu:268

    hello, does flashtorch work on ensemble model, I passed output of one neural network to another, and got error.

    I used g_ascent.visualize(model.encoder[0], title='conv');

    opened by vainaixr 5
  • backprop.visualize does not display anything

    backprop.visualize does not display anything

    I followed the tutorial on the README page, and the visualizations are not displaying. I am using a pretrained model, and I use a tensor with requires_grad=True as the image. My code doesn't run in to any errors. My code is below:

    backprop = Backprop(net) backprop.visualize(image, target_class, guided = True)

    bug 
    opened by goldblum 4
  • CUDA/CPU transfer error

    CUDA/CPU transfer error

    Hi, I was interested in visualizing a CNN I created. I was following the example provided but when I try to use my model instead of a pretrained model from torchvision I get:

    File "cnn_layer_visualization.py", line 82, in <module>
        gradients = backprop.calculate_gradients(input_, target_class)
      File "C:\Users\Mike\Anaconda3\lib\site-packages\flashtorch\saliency\backprop.py", line 106, in calculate_gradients
        output.backward(gradient=target)
      File "C:\Users\Mike\Anaconda3\lib\site-packages\torch\tensor.py", line 107, in backward
        torch.autograd.backward(self, gradient, retain_graph, create_graph)
      File "C:\Users\Mike\Anaconda3\lib\site-packages\torch\autograd\__init__.py", line 93, in backward
        allow_unreachable=True)  # allow_unreachable flag
    RuntimeError: invalid gradient at index 0 - expected type torch.cuda.FloatTensor but got torch.FloatTensor
    

    I looked through the source code a bit and saw that Backprop moves the network to cuda (if available) regardless if I move it there myself or not. Is this possibly a bug? I've had a bit of trouble with CUDA in the past so it might be a problem on my end.

    Thanks for your time, if there's any other information I can provide please let me know. Cheers.

    opened by rotobash 4
  • [REQUEST]

    [REQUEST]

    Problem Faced: Backprop visualize doesn't consider models with grayscale input.

    Description: Refer to this line: https://github.com/MisaOgura/flashtorch/blob/ba5e3db3911afee583180bead9150ce4c392e09e/flashtorch/saliency/backprop.py#L222 In this line we add a check for 3 channels which results in skipping grayscale inputs to the conv layer

    My current workaround: I have a copy of the backprop class with the in_channels set to 1 for my grayscale image use case.

    Possible Fix: Would it make sense to remove the in_channels == 3 check since the first conv would be where the input image is supplied and should be good to register the hook at or am I missing something important here?

    improvement 
    opened by surajpaib 3
  • Models galore

    Models galore

    Hello, The current example for guided backpropogation only supports Alexnet which is a quite old. I've added an example to allow loading any supported model from the pytorch zoo and visualizing the output of guided backpropagation on it. Please review and merge it. Specific enhancements:

    • The visualize method assumes normalization parameters of imagenet & doesn't support changing this. Edited the class interface to allow these to be specified. However it defaults to imagenet values so it does not affect past behavior.
    • The examples queries the tochvision.models module for supported models and allows user to visualize backdrop output on the pre-trained models from pytorch repo.

    enjoy, nav

    opened by navneeth 3
  • How to handle multi label multiclass?

    How to handle multi label multiclass?

    My network does binary classifcation for detection of 11 different classes. E.G. It predicts if or if not there are apples, oranges, pineapple, and pears in the image I give it. So the output is a binary vector of length 11.

    Can I use this project with out modifying it? I have checked and top_label will always be 9, so what I put for target_label will be ignored. I get the error

    The predicted class index 9 does notequal the target class index 3. Calculatingthe gradient w.r.t. the predicted class. 'the gradient w.r.t. the predicted class.'

    So in my example, if the network outputs a binary vector of length 4 corresponding to whether or not apple, orange, pineapple, and pear are in the image, how can I make it so that when I set target = 3 the code will show the gradient corresponding to the task of detecting pineapples?

    Also, I am using modified ResNet-18 (transfer learned).

    opened by rrags 3
  • [BUG] Backprop.calculate_gradients gives rise to

    [BUG] Backprop.calculate_gradients gives rise to " AttributeError: 'NoneType' object has no attribute 'shape' " error

    Describe the bug When testing the visualization tool using a custom pre-trained CNN that performs Binary Classification, the error "AttributeError: 'NoneType' object has no attribute 'shape'" crops up when trying to visualize an image that from the dataset used to train the model.

    To Reproduce Steps to reproduce the behavior: Load image using custom transformation: transform = transforms.Compose([ transforms.RandomHorizontalFlip(), transforms.RandomRotation(20), transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) ]) that pertains to the CNN model developed. Load the image and apply the transformation: from flashtorch.utils import load_image from flashtorch.saliency import Backprop backprop=Backprop(n) image =load_image("img0042.png") i = transform(image) i = torch.unsqueeze(i,0) target_class=0 gradients=backprop.calculate_gradients(i,0) (general summary of the code)

    Error message

    AttributeError Traceback (most recent call last) in 1 from torch.autograd import Variable ----> 2 gradients=backprop.calculate_gradients(i,0)

    ~\Anaconda3\lib\site-packages\flashtorch\saliency\backprop.py in calculate_gradients(self, input_, target_class, take_max, guided, use_gpu) 118 # Calculate gradients of the target class output w.r.t. input_ 119 --> 120 output.backward(gradient=target) 121 122 # Detach the gradients from the graph and move to cpu

    ~\Anaconda3\lib\site-packages\torch\tensor.py in backward(self, gradient, retain_graph, create_graph) 164 products. Defaults to False. 165 """ --> 166 torch.autograd.backward(self, gradient, retain_graph, create_graph) 167 168 def register_hook(self, hook):

    ~\Anaconda3\lib\site-packages\torch\autograd_init_.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables) 97 Variable._execution_engine.run_backward( 98 tensors, grad_tensors, retain_graph, create_graph, ---> 99 allow_unreachable=True) # allow_unreachable flag 100 101

    ~\Anaconda3\lib\site-packages\flashtorch\saliency\backprop.py in _record_gradients(module, grad_in, grad_out) 212 def _register_conv_hook(self): 213 def _record_gradients(module, grad_in, grad_out): --> 214 if self.gradients.shape == grad_in[0].shape: 215 self.gradients = grad_in[0] 216

    AttributeError: 'NoneType' object has no attribute 'shape'

    Environment (please complete the following information):

    • OS: [Windows 10 1909 version: 18363.476]
    • Python version: [3.7..4]
    • FlashTorch version: [0.1.1]
    bug 
    opened by narbhar 3
  • [BUG]UnicodeDecodeError: 'gbk' codec can't decode byte 0x9d in position 5424: illegal multibyte sequence

    [BUG]UnicodeDecodeError: 'gbk' codec can't decode byte 0x9d in position 5424: illegal multibyte sequence

    Describe the bug Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "C:\Users\HUAJI0~1\AppData\Local\Temp\pip-install-uc9zsivx\flashtorch\setup.py", line 5, in long_description = fh.read()

    UnicodeDecodeError: 'gbk' codec can't decode byte 0x9d in position 5424: illegal multibyte sequence

    To Reproduce pip install flashtorch

    Environment (please complete the following information):

    • OS: windows10
    • Python version: 3.7
    • FlashTorch version: 0.1.0

    fix readme.md line 101 “see” fix to "see"

    bug 
    opened by koke2c95 3
  • use of custom model throws an error

    use of custom model throws an error

    Hi, Thanks for your work. I am trying to use "Activation maximization" notebook with my own custom model. The difference is that my model takes an input of (56,56,24). The gradient ascent function accepts my model without an error. I perform my own transformation on a random generated input and the input shape is torch.Size([1, 24, 56, 56]).

    When I call visualize function giving it any intermediate layer and filter, it throws below error:


    TypeError Traceback (most recent call last) in ----> 1 g_ascent.visualize(layer2_0_conv2, title='layer1_0_conv2')

    ~/.local/lib/python3.6/site-packages/flashtorch/activmax/gradient_ascent.py in visualize(self, layer, filter_idxs, lr, num_iter, num_subplots, figsize, title, return_output) 210 num_iter, 211 len(filter_idxs), --> 212 title=title) 213 214 if return_output:

    ~/.local/lib/python3.6/site-packages/flashtorch/activmax/gradient_ascent.py in _visualize_filters(self, layer, filter_idxs, num_iter, num_subplots, title) 347 standardize_and_clip(output[-1], 348 saturation=0.15, --> 349 brightness=0.7))) 350 351 plt.subplots_adjust(wspace=0, hspace=0); # noqa

    ~/.local/lib/python3.6/site-packages/matplotlib/init.py in inner(ax, data, *args, **kwargs) 1563 def inner(ax, *args, data=None, **kwargs): 1564 if data is None: -> 1565 return func(ax, *map(sanitize_sequence, args), **kwargs) 1566 1567 bound = new_sig.bind(ax, *args, **kwargs)

    ~/.local/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py in wrapper(*args, **kwargs) 356 f"%(removal)s. If any parameter follows {name!r}, they " 357 f"should be pass as keyword, not positionally.") --> 358 return func(*args, **kwargs) 359 360 return wrapper

    ~/.local/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py in wrapper(*args, **kwargs) 356 f"%(removal)s. If any parameter follows {name!r}, they " 357 f"should be pass as keyword, not positionally.") --> 358 return func(*args, **kwargs) 359 360 return wrapper

    ~/.local/lib/python3.6/site-packages/matplotlib/axes/_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs) 5624 resample=resample, **kwargs) 5625 -> 5626 im.set_data(X) 5627 im.set_alpha(alpha) 5628 if im.get_clip_path() is None:

    ~/.local/lib/python3.6/site-packages/matplotlib/image.py in set_data(self, A) 697 or self._A.ndim == 3 and self._A.shape[-1] in [3, 4]): 698 raise TypeError("Invalid shape {} for image data" --> 699 .format(self._A.shape)) 700 701 if self._A.ndim == 3:

    TypeError: Invalid shape (56, 56, 24) for image data

    Can anyone help me with this please.

    opened by SarfarazHabib 2
  • Custom Pytorch Model error

    Custom Pytorch Model error

    I am using a custom pretrained fully connected Pytorch model which was trained on CIFAR10 using GPU. While trying to use the backprop.visualize, I am getting the following error.

    ---------------------------------------------------------------------------
    RuntimeError                              Traceback (most recent call last)
    <ipython-input-24-554f7ff5427b> in <module>()
          8 # Ready to roll!
          9 
    ---> 10 backprop.visualize(owl, target_class, guided=True, use_gpu=True)
    
    8 frames
    /usr/local/lib/python3.6/dist-packages/flashtorch/saliency/backprop.py in visualize(self, input_, target_class, guided, use_gpu, figsize, cmap, alpha, return_output)
        166         gradients = self.calculate_gradients(input_,
        167                                              target_class,
    --> 168                                              guided=guided)
        169         max_gradients = self.calculate_gradients(input_,
        170                                                  target_class,
    
    /usr/local/lib/python3.6/dist-packages/flashtorch/saliency/backprop.py in calculate_gradients(self, input_, target_class, take_max, guided, use_gpu)
         87         # Get a raw prediction value (logit) from the last linear layer
         88 
    ---> 89         output = self.model(input_)
         90 
         91         # Don't set the gradient target if the model is a binary classifier
    
    /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
        539             result = self._slow_forward(*input, **kwargs)
        540         else:
    --> 541             result = self.forward(*input, **kwargs)
        542         for hook in self._forward_hooks.values():
        543             hook_result = hook(self, input, result)
    
    /content/archs/cifar10/fc1.py in forward(self, x)
         18     def forward(self, x):
         19         x = torch.flatten(x, 1)
    ---> 20         x = self.classifier(x)
         21         return x
         22 #====================================
    
    /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
        539             result = self._slow_forward(*input, **kwargs)
        540         else:
    --> 541             result = self.forward(*input, **kwargs)
        542         for hook in self._forward_hooks.values():
        543             hook_result = hook(self, input, result)
    
    /usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py in forward(self, input)
         90     def forward(self, input):
         91         for module in self._modules.values():
    ---> 92             input = module(input)
         93         return input
         94 
    
    /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
        539             result = self._slow_forward(*input, **kwargs)
        540         else:
    --> 541             result = self.forward(*input, **kwargs)
        542         for hook in self._forward_hooks.values():
        543             hook_result = hook(self, input, result)
    
    /usr/local/lib/python3.6/dist-packages/torch/nn/modules/linear.py in forward(self, input)
         85 
         86     def forward(self, input):
    ---> 87         return F.linear(input, self.weight, self.bias)
         88 
         89     def extra_repr(self):
    
    /usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in linear(input, weight, bias)
       1368     if input.dim() == 2 and bias is not None:
       1369         # fused op is marginally faster
    -> 1370         ret = torch.addmm(bias, input, weight.t())
       1371     else:
       1372         output = input.matmul(weight.t())
    
    RuntimeError: Expected object of device type cuda but got device type cpu for argument #2 'mat1' in call to _th_addmm
    

    My model :

    class fc1(nn.Module):
    
        def __init__(self, num_classes=10, hidden=300):
            super(fc1, self).__init__()
            self.classifier = nn.Sequential(
                nn.Linear(3*32*32, hidden),
                nn.ReLU(inplace=True),
                nn.Linear(hidden, 100),
                nn.ReLU(inplace=True),
                nn.Linear(100, num_classes),
            )
    
        def forward(self, x):
            x = torch.flatten(x, 1)
            x = self.classifier(x)
            return x
    

    Loaded the model using the following lines :

    from archs.cifar10 import fc1
    
    import torch
    model = torch.load("/content/epoch_198.pth.tar")
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    
    model = model.to(device)
    
    opened by rahulvigneswaran 2
  • [REQUEST] calculate gradients for customized inputs

    [REQUEST] calculate gradients for customized inputs

    Thanks a lot for developing fantastic package FlashTorch!

    I have a question about the inputs. My inputs contains two parts:

    • the image
    • additional information of image (one node)

    The additional node is inputed in the middle layers with torch.cat.

    In such case, can I use FlashTorch to obtain my saliency maps? Thanks a lot!

    opened by LiJiaqi96 0
  • RuntimeError

    RuntimeError

    RuntimeError Traceback (most recent call last) in 9 # Ready to roll! 10 ---> 11 backprop.visualize(owl, target_class, guided=True)

    ~\Downloads\flashtorch-master\flashtorch\saliency\backprop.py in visualize(self, input_, target_class, guided, use_gpu, figsize, cmap, alpha, return_output) 180 # (title, [(image1, cmap, alpha), (image2, cmap, alpha)]) 181 ('Input image', --> 182 [(format_for_plotting(denormalize(input_)), None, None)]), 183 ('Gradients across RGB channels', 184 [(format_for_plotting(standardize_and_clip(gradients)),

    ~\Downloads\flashtorch-master\flashtorch\utils_init_.py in denormalize(tensor) 117 118 for channel, mean, std in zip(denormalized[0], means, stds): --> 119 channel.mul_(std).add_(mean) 120 121 return denormalized

    RuntimeError: Output 0 of UnbindBackward is a view and is being modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.

    opened by YOU-TO-BE 1
  • Google Colab version not running [BUG]

    Google Colab version not running [BUG]

    Describe the bug When running the google colab version Part 4. Visualize Saliency Maps throws up the following error


    RuntimeError Traceback (most recent call last) in () 9 # Ready to roll! 10 ---> 11 backprop.visualize(owl, target_class, guided=True, use_gpu=True)

    1 frames /usr/local/lib/python3.6/dist-packages/flashtorch/utils/init.py in denormalize(tensor) 117 118 for channel, mean, std in zip(denormalized[0], means, stds): --> 119 channel.mul_(std).add_(mean) 120 121 return denormalized

    RuntimeError: Output 0 of UnbindBackward is a view and is being modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.

    To Reproduce Steps to reproduce the behavior:

    1. Go to https://colab.research.google.com/github/MisaOgura/flashtorch/blob/master/examples/visualize_saliency_with_backprop_colab.ipynb
    2. Click on 'Run all'
    3. Scroll down to 'Section 4'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Environment (please complete the following information):

    • OS: [e.g. iOS]
    • Python version: [e.g. 3.6]
    • FlashTorch version: [e.g. 0.1.0]

    Additional context Add any other context about the problem here.

    bug 
    opened by ShaneGilroy 7
  • [BUG] Colab demo for saliency maps: Gradient images are blank

    [BUG] Colab demo for saliency maps: Gradient images are blank

    Thanks so much for sharing your work and make it so easy...in theory...to use. Although I haven't been able to get it to work by running your Colab example(s).

    Describe the bug The two middle images involving gradients for each example, "Gradients across RGB channels" and "Max Gradients", appear as uniform color. The RGB is all grey and the Max is all purple.

    To Reproduce Steps to reproduce the behavior:

    1. Go to the README page for this repo, scroll down to "Want to try?"
    2. Next to "Saliency maps:", click on the "Open in Colab" badge.
    3. Save a copy of the notebook to Drive (or not; this step is not essential to produce the error)
    4. Edit > Notebook Settings, select GPU
    5. Runtime > Restart and run all
    6. Scroll down and observe that only the leftmost and right most images for owl, peacock and toucan are visible, the middle two images are "blank"

    Expected behavior Gradient images should show content, such as colored pixels around the owl's eyes as in your Medium post. That is not what running the Colab demo gives me. See my sample screenshot below.

    Screenshots Screenshot from 2020-09-29 00-20-16

    Environment (please complete the following information): Colab. Whatever OS that's running. Brand new installation of FlashTorch via the !pip install flashtorch in the notebook. Looks like (0.1.3) Looks like Torch 1.6

    Additional context From pip (after I re-ran it a second time):

    Collecting flashtorch
      Downloading https://files.pythonhosted.org/packages/de/cb/482274e95812c9a17bd156956bef80a8e2683a2b198a505fb922f1c01a71/flashtorch-0.1.3.tar.gz
    Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (from flashtorch) (3.2.2)
    Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from flashtorch) (1.18.5)
    Requirement already satisfied: Pillow in /usr/local/lib/python3.6/dist-packages (from flashtorch) (7.0.0)
    Requirement already satisfied: torch in /usr/local/lib/python3.6/dist-packages (from flashtorch) (1.6.0+cu101)
    Requirement already satisfied: torchvision in /usr/local/lib/python3.6/dist-packages (from flashtorch) (0.7.0+cu101)
    Collecting importlib_resources
      Downloading https://files.pythonhosted.org/packages/ba/03/0f9595c0c2ef12590877f3c47e5f579759ce5caf817f8256d5dcbd8a1177/importlib_resources-3.0.0-py2.py3-none-any.whl
    Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib->flashtorch) (0.10.0)
    Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->flashtorch) (2.4.7)
    Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->flashtorch) (2.8.1)
    Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->flashtorch) (1.2.0)
    Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from torch->flashtorch) (0.16.0)
    Requirement already satisfied: zipp>=0.4; python_version < "3.8" in /usr/local/lib/python3.6/dist-packages (from importlib_resources->flashtorch) (3.1.0)
    Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from cycler>=0.10->matplotlib->flashtorch) (1.15.0)
    Building wheels for collected packages: flashtorch
      Building wheel for flashtorch (setup.py) ... done
      Created wheel for flashtorch: filename=flashtorch-0.1.3-cp36-none-any.whl size=26248 sha256=95cdabc7c3dbc87e25d0795eb47d01971668600bdc58cd558b670c5e7ce0b725
      Stored in directory: /root/.cache/pip/wheels/03/6d/b1/2d3c5987b69e900fcceceeef39d3ed92dfe46ba1359b9c79f8
    Successfully built flashtorch
    Installing collected packages: importlib-resources, flashtorch
    Successfully installed flashtorch-0.1.3 importlib-resources-3.0.0
    
    bug 
    opened by drscotthawley 2
  • When  I test my demo.jpg[BUG]

    When I test my demo.jpg[BUG]

    AttributeError Traceback (most recent call last) in () 4 input_=apply_transforms(image) 5 target_class=24 ----> 6 backprop.visualize(input,target_class,guided=True)

    1 frames /usr/local/lib/python3.6/dist-packages/flashtorch/saliency/backprop.py in calculate_gradients(self, input_, target_class, take_max, guided, use_gpu) 84 self.model.zero_grad() 85 ---> 86 self.gradients = torch.zeros(input_.shape) 87 88 # Get a raw prediction value (logit) from the last linear layer

    AttributeError: 'function' object has no attribute 'shape'

    how to fix it?

    bug 
    opened by cymqqqq 0
Releases(v0.1.3)
  • v0.1.3(May 29, 2020)

    Install steps

    • pip install flashtorch

    Upgrade steps

    • pip install flashtorch -U

    Breaking changes

    • None

    New features

    • None

    Bug fixes

    • None

    Improvements

    • Requested improvement: #30
      • Implemented by #31
      • Quick summary: flashtorch.saliency.Backprop can now handle models with mono-channel/grayscale input images

    Other changes

    • None
    Source code(tar.gz)
    Source code(zip)
  • v0.1.2(Jan 2, 2020)

    Install steps

    • pip install flashtorch

    Upgrade steps

    • pip install flashtorch -U

    Breaking changes

    • None

    New features

    • None

    Bug fixes

    • Reported bug: #18
      • Fixed by: #25
      • Quick summary: flashtorch.saliency.Backprop.visualize now correctly passes use_gpu flag down to the calculate_gradient.

    Improvements

    • None

    Other changes

    • None
    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Sep 26, 2019)

    Install steps

    • pip install flashtorch

    Upgrade steps

    • pip install flashtorch -U

    Breaking changes

    • None

    New features

    • None

    Bug fixes

    • Removes a dependency on README.md in setup.py: this is to avoid getting unicode decoding error (reported by #14). setup.py now gets the long_description from its docstring.

    Improvements

    • None

    Other changes

    • None
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Sep 9, 2019)

    Install steps

    • pip install flashtorch

    Upgrade steps

    • pip install flashtorch -U

    Breaking changes

    • flashtorch.utils.visualize: This functionality was specific for creating saliency maps, and therefore has been moved as a class method for flashtorch.saliency.Backprop

    Refer to the notebooks below for details and how to use it:

    New features

    • flashtorch.activmax.GradientAscent: This is a new API which implements activation maximization via gradient ascent. It has three public facing APIs:

      • GradientAscent.optimize: Generates an image that maximally activates the target filter.
      • GradientAscent.visualize: Optimizes for the target layer/filter and visualizes the output.
      • GradientAscent.deepdream: Creates DeepDream.

    Refer to the notebooks below for details and how to use it:

    Bug fixes

    • None

    Improvements

    • flashtorch.utils.standardize_and_clip: Users can optionally set the saturation and brightness.

    Other changes

    • None
    Source code(tar.gz)
    Source code(zip)
  • v0.0.8(Jul 8, 2019)

    Install steps

    • pip install flashtorch

    Upgrade steps

    • pip install flashtorch -U

    Breaking changes

    • None

    New features

    • None

    Bug fixes

    • Fixes #2

    Improvements

    • Users can explicitly set a device to use when calculating gradients when using an instance of Backprop, by setting use_gpu=True. If it's True and torch.cuda.is_available, the computation will be moved to GPU. It defaults to False if not provided.

      from flashtorch.saliency import Backprop
      
      ... # Prepare input and target_class
      
      model = model()
      backprop = Backprop(model)
      gradients = backprop. calculate_gradients(input, target_class, use_gpu=True)
      

    Other changes

    • setup.py has better indications of supported Python versions
    Source code(tar.gz)
    Source code(zip)
Owner
Misa Ogura
Research Software Engineer | Published Scientist | Co-founder of @womendrivendev
Misa Ogura
Quickly and easily create / train a custom DeepDream model

Dream-Creator This project aims to simplify the process of creating a custom DeepDream model by using pretrained GoogleNet models and custom image dat

56 Jan 03, 2023
A library for debugging/inspecting machine learning classifiers and explaining their predictions

ELI5 ELI5 is a Python package which helps to debug machine learning classifiers and explain their predictions. It provides support for the following m

2.6k Dec 30, 2022
Visual analysis and diagnostic tools to facilitate machine learning model selection.

Yellowbrick Visual analysis and diagnostic tools to facilitate machine learning model selection. What is Yellowbrick? Yellowbrick is a suite of visual

District Data Labs 3.9k Dec 30, 2022
Pytorch Feature Map Extractor

MapExtrackt Convolutional Neural Networks Are Beautiful We all take our eyes for granted, we glance at an object for an instant and our brains can ide

Lewis Morris 40 Dec 07, 2022
FairML - is a python toolbox auditing the machine learning models for bias.

======== FairML: Auditing Black-Box Predictive Models FairML is a python toolbox auditing the machine learning models for bias. Description Predictive

Julius Adebayo 338 Nov 09, 2022
pytorch implementation of "Distilling a Neural Network Into a Soft Decision Tree"

Soft-Decision-Tree Soft-Decision-Tree is the pytorch implementation of Distilling a Neural Network Into a Soft Decision Tree, paper recently published

Kim Heecheol 262 Dec 04, 2022
GNNLens2 is an interactive visualization tool for graph neural networks (GNN).

GNNLens2 is an interactive visualization tool for graph neural networks (GNN).

Distributed (Deep) Machine Learning Community 143 Jan 07, 2023
Pytorch implementation of convolutional neural network visualization techniques

Convolutional Neural Network Visualizations This repository contains a number of convolutional neural network visualization techniques implemented in

Utku Ozbulak 7k Jan 03, 2023
Model analysis tools for TensorFlow

TensorFlow Model Analysis TensorFlow Model Analysis (TFMA) is a library for evaluating TensorFlow models. It allows users to evaluate their models on

1.2k Dec 26, 2022
A game theoretic approach to explain the output of any machine learning model.

SHAP (SHapley Additive exPlanations) is a game theoretic approach to explain the output of any machine learning model. It connects optimal credit allo

Scott Lundberg 18.3k Jan 08, 2023
A python library for decision tree visualization and model interpretation.

dtreeviz : Decision Tree Visualization Description A python library for decision tree visualization and model interpretation. Currently supports sciki

Terence Parr 2.4k Jan 02, 2023
Visual Computing Group (Ulm University) 99 Nov 30, 2022
Auralisation of learned features in CNN (for audio)

AuralisationCNN This repo is for an example of auralisastion of CNNs that is demonstrated on ISMIR 2015. Files auralise.py: includes all required func

Keunwoo Choi 39 Nov 19, 2022
Algorithms for monitoring and explaining machine learning models

Alibi is an open source Python library aimed at machine learning model inspection and interpretation. The focus of the library is to provide high-qual

Seldon 1.9k Dec 30, 2022
JittorVis - Visual understanding of deep learning model.

JittorVis - Visual understanding of deep learning model.

182 Jan 06, 2023
Code for "High-Precision Model-Agnostic Explanations" paper

Anchor This repository has code for the paper High-Precision Model-Agnostic Explanations. An anchor explanation is a rule that sufficiently “anchors”

Marco Tulio Correia Ribeiro 735 Jan 05, 2023
Using / reproducing ACD from the paper "Hierarchical interpretations for neural network predictions" 🧠 (ICLR 2019)

Hierarchical neural-net interpretations (ACD) 🧠 Produces hierarchical interpretations for a single prediction made by a pytorch neural network. Offic

Chandan Singh 111 Jan 03, 2023
Delve is a Python package for analyzing the inference dynamics of your PyTorch model.

Delve is a Python package for analyzing the inference dynamics of your PyTorch model.

Delve 73 Dec 12, 2022
A library that implements fairness-aware machine learning algorithms

Themis ML themis-ml is a Python library built on top of pandas and sklearnthat implements fairness-aware machine learning algorithms. Fairness-aware M

Niels Bantilan 105 Dec 30, 2022
Visualize a molecule and its conformations in Jupyter notebooks/lab using py3dmol

Mol Viewer This is a simple package wrapping py3dmol for a single command visualization of a RDKit molecule and its conformations (embed as Conformer

Benoît BAILLIF 1 Feb 11, 2022