Skip to main content

Interpreting deep learning models in PyTorch.

Project description

Interpretable Deep Learning

Class Visualisations

A simple to use PyTorch library for interpreting your deep learning results.

Note: Repo under construction

Installation

Currently, install from GitHub:

pip install git+https://github.com/ttumiel/interpret

Dependencies

interpret requires a working installation of PyTorch.

Usage

interpret can be used for both visualisation and attribution. Here an example using a pretrained network is shown.

Visualisation

from interpret import OptVis, ImageParam, 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 = 'classifier/6'
neuron = 5

# Create an OptVis object from a PyTorch model
optvis = OptVis.from_layer(network, layer=layer, neuron=neuron)

# Parameterise input noise in colour decorrelated Fourier domain
img_param = ImageParam(224, fft=True, decorrelate=True)

# Create visualisation
optvis.vis(img_param, thresh=(250, 500), transform=True, lr=0.05, wd=0.9)

# Denormalise and return the final image
denorm(img_param())

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)

Project details


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.1.0.tar.gz (33.3 kB view hashes)

Uploaded Source

Built Distribution

interpret_pytorch-0.1.0-py3-none-any.whl (36.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page