Interpreting deep learning models in PyTorch.
Project description
Interpretable Deep Learning
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
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.1.0.tar.gz
(33.3 kB
view details)
Built Distribution
File details
Details for the file interpret-pytorch-0.1.0.tar.gz
.
File metadata
- Download URL: interpret-pytorch-0.1.0.tar.gz
- Upload date:
- Size: 33.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6df75fa0e4609a8e27bf6fe67550e2d253b6c7b744f8c019fe23176a66795cf0 |
|
MD5 | a2de971d2dedeff0820839b4b0d4f2e6 |
|
BLAKE2b-256 | 32302ebc24b59bc72c86b7e9a21706f39643470329854aeb18e3e4bd1c9822bb |
File details
Details for the file interpret_pytorch-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: interpret_pytorch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 848923fa5e17771cdcf7bad5a851f1e891427e85c48fb57c003c87bea6758407 |
|
MD5 | 3e2c635c73810bbe5c43da81400f2162 |
|
BLAKE2b-256 | 3b1cc7d932983bccafddc1a0a2f05ad2f2e9d4a5ab4b215ce4ed1460ff070d9e |