Skip to main content

pytorch-sidu

size

SIDU: SImilarity Difference and Uniqueness method for explainable AI from the original paper

  • Pytorch implementation of the SIDU method.
  • Simple interface for loading pretrained models by specifying one of the following string name
  • Clear interface for generating saliency maps

Some examples made with VGG19 on Caltech-101 dataset:

img1 img7 img9

Installation

pip install pytorch-sidu

Usage

Load models from the pretrainde ones available in pytorch

import pytorch_sidu as sidu

model_name = 'ResNet34_Weights.IMAGENET1K_V1'
model = load_torch_model_by_string(model_name)

After instantianting your model, generate saliency maps from Dataloader

data_loader = <your dataloader>
target_layer = 'layer4.2.conv2'
image, _ = next(iter(data_loader))
saliency_maps = sidu.sidu(model, target_layer, image)

A complete example on CIFAR-10

import torch
import torchvision
from matplotlib import pyplot as plt
import pytorch_sidu as sidu


transform = torchvision.transforms.Compose([torchvision.transforms.Resize((224, 224)), torchvision.transforms.ToTensor()])
data_loader = torch.utils.data.DataLoader(
    torchvision.datasets.CIFAR10(root='./data', download=True, transform=transform), batch_size=2)

target_layer = 'layer4.2.conv2'
model_name = 'ResNet34_Weights.IMAGENET1K_V1'
model = sidu.load_torch_model_by_string(model_name)

for image, _ in data_loader:
    saliency_maps = sidu.sidu(model, target_layer, image)
    image, saliency_maps = image.cpu(), saliency_maps.cpu()

    for j in range(len(image)):
        plt.figure(figsize=(5, 2.5))
        plt.subplot(1, 2, 1)
        plt.imshow(image[j].permute(1, 2, 0))
        plt.axis('off')
        plt.subplot(1, 2, 2)
        plt.imshow(image[j].permute(1, 2, 0))
        plt.imshow(saliency_maps[j].squeeze().detach().numpy(), cmap='jet', alpha=0.4)
        plt.axis('off')
        plt.show()

upcoming features:

  • integration of xai metrics
  • make methods work on both single images and dataloaders
  • adding device flag to sidu function to allow device selection

Metadata

Release files for pytorch-sidu 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytorch-sidu 1.1.3
File Size Uploaded
pytorch-sidu-1.1.3.tar.gz 17.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytorch-sidu 1.1.3
File Interpreter ABI Platform
pytorch_sidu-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 35.2 kB

Release files / pytorch-sidu-1.1.3.tar.gz

Download URL pytorch-sidu-1.1.3.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
23aef4fb24c5ee81cba4723feb364ac915de869245326c37c6551ce743d78a93
BLAKE2b-256 checksum
How to use checksums
dd960783223825d6fc019a91bf0ce6be7785cf1b0487cb2e33e4afbada947874
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / pytorch_sidu-1.1.3-py3-none-any.whl

Download URL pytorch_sidu-1.1.3-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1c16242b80d4423c8cbbe77561c23c11730bf1ffa8a421c986387cc7e454a52
BLAKE2b-256 checksum
How to use checksums
35eae0a155f4dc484bb4c91d0a5a032551cf34b3839f9a0e67f09d5e20de126b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.2

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

1 release file

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.12

2 release files

0.0.6

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page