Skip to main content

Principal Image Sections Mapping for PyTorch

Project description

PRISM - Principal Image Sections Mapping

PRISM logo

A novel tool that utilizes Principal Component Analysis to display discriminative featues detected by a given convolutional neural network. It complies with virtually all CNNs.

Demo

Simplest snippet of working code.

import sys
sys.path.insert(0, "../")
from torchprism import PRISM
from torchvision import models
from utils import load_images, draw_input_n_prism

# load images into batch
input_batch = load_images()

model = models.vgg11(pretrained=True)
model.eval()
PRISM.register_hooks(model)

model(input_batch)
prism_maps_batch = PRISM.get_maps()

drawable_input_batch = input_batch.permute(0, 2, 3, 1).detach().cpu().numpy()
drawable_prism_maps_batch = prism_maps_batch.permute(0, 2, 3, 1).detach().cpu().numpy()

draw_input_n_prism(drawable_input_batch, drawable_prism_maps_batch)

First we have to import PRISM and torch models., as well as functions for preparing input images as simple torch batch and function to draw batches. Next we have to load the model, in this case a pretrained vgg11 has been chosen and then we have to call the first PRISM method to register required hooks in the model. With such a prepared model we can perform the classification and, since the actual output is not needed, we can just ignore it. Model execution is followed by using the second PRISM method to calculate features maps for the processed batch. Finally we have to prepare both input and PRISM output so they can be drawn and as the last step we call a method that displays them using e.g. matplotlib.

Results

The results allow us to see the discriminative features found by the model. On the sample images below we can see wolves

Snippet result

We can notice that all wolves have similar colors - features, found on their bodies. Furthermore the coyote also shows almost identical characteristics except the mouth element. wolves have a black stain around their noses, while coyote does not.

Citation

Currently in the form of pre-print, but hope soon as publication.

@misc{szandala2021torchprism,
      title={TorchPRISM: Principal Image Sections Mapping, a novel method for Convolutional Neural Network features visualization},
      author={Tomasz Szandala},
      year={2021},
      eprint={2101.11266},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

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

torchprism-1.0.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

torchprism-1.0.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file torchprism-1.0.2.tar.gz.

File metadata

  • Download URL: torchprism-1.0.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for torchprism-1.0.2.tar.gz
Algorithm Hash digest
SHA256 803d3e128291a8d1b3376df8ada662126e7a76f131428881143259a332e107c6
MD5 799c6e621bd29b16f8aee5c5298c9a5e
BLAKE2b-256 7811e6d9f25fe2c9aeff8d55c455880b2164a9e3f8bcfdb26ac9f47f3b19eae2

See more details on using hashes here.

File details

Details for the file torchprism-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: torchprism-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for torchprism-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b01f56e627f2b205601004e66c3430b00e2abd02b26aef5e5b5f65fd8ec667bf
MD5 8c31441ace8e549c6a102d1399eb5c5a
BLAKE2b-256 a1aed3055af5d92de87c1809d3b2f8c4657bf54be5e643b40971b2b2f08a2567

See more details on using hashes here.

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