Interpreting deep learning models in PyTorch.
Project description
Interpretable Deep Learning
A simple to use PyTorch library for interpreting your deep learning results. Inspired by TensorFlow Lucid.
Installation
Install from PyPI:
pip install interpret-pytorch
Or, install the latest code from GitHub:
pip install git+https://github.com/ttumiel/interpret
Dependencies
interpret
requires a working installation of PyTorch.
Tutorials
Run the tutorials in the browser using Google Colab.
Tutorial | Link |
---|---|
Introduction to interpret |
|
Visualisation Tutorial |
Usage
interpret
can be used for both visualisation and attribution. Here an example using a pretrained network is shown.
Visualisation
from interpret import OptVis, denorm
import torchvision
# Get the PyTorch neural network
network = torchvision.models.vgg11(pretrained=True)
# Select a layer from the network. Use get_layer_names()
# to see a list of layer names and sizes.
layer = 'features/18'
channel = 12
# Create an OptVis object from a PyTorch model
optvis = OptVis.from_layer(network, layer=layer, channel=channel)
# Create visualisation
optvis.vis()
Attribution
from interpret import Gradcam, norm
from PIL import Image
import torchvision
network = torchvision.models.vgg11(pretrained=True)
input_img = Image.open('image.jpg')
# Normalise the input image and turn it into a tensor
input_data = norm(input_img)
# Select the class that we are attributing to
class_number = 207
# Choose a layer for Grad-CAM
layer = 'features/20'
# Generate a Grad-CAM attribution map
saliency_map = Gradcam(network, input_data, im_class=class_number, layer=layer)
saliency_map.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
interpret-pytorch-0.2.0.tar.gz
(35.7 kB
view hashes)
Built Distribution
Close
Hashes for interpret_pytorch-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7be6b864a4e485dc05a49bc355256c009e4f6cb740f558e3b1ecf2cdf04beea3 |
|
MD5 | 89485fed8fbecccbbd28bee9669c272d |
|
BLAKE2b-256 | 57bb6ce5c943873d912be6b9fad2b2072fa1ca2b99a41c55cdb00b250737b490 |