Skip to main content

A tool for generating class activation maps in deep learning models.

Project description

graddy: A Gradient-weighted Class Activation Mapping Package

Grad-CAM (Gradient-weighted Class Activation Mapping) is a technique used to visualize the importance of different regions of an input image for a specific classification decision made by a convolutional neural network (CNN).

When it comes to using Grad-CAM for segmentation, the main difference is that instead of generating a heatmap for a single class, we generate a heatmap for each pixel of the image, indicating its importance for segmentation. This requires modifying the implementation of Grad-CAM to calculate the gradients of the output segmentation mask with respect to the input image, rather than just the gradients of the output classification score with respect to the convolutional feature maps.

The modified implementation typically involves computing the gradient of the output segmentation mask with respect to the final convolutional layer, then using these gradients to weight the activation maps of this layer to generate a heatmap. The heatmap can then be overlaid on the input image to highlight the regions of the image that are most important for the segmentation.

Who's your graddy? 🌚

This package provides a simple implementation of Grad-CAM (Gradient-weighted Class Activation Mapping) for visualizing and interpreting the predictions of convolutional neural networks. Grad-CAM is a technique for generating heatmaps that indicate which regions of an input image are most important for the model's prediction. This can be helpful for understanding what features the model is using to make its decision.

graddy specialises in class activation map generation for classification and segmentation, as well as capturing them and your mom.

Refer test_gradcam.py to use the package.

Installation

You can install this package via pip:

pip install graddy

gradcam Class

The gradcam class in the package can be used to generate Grad-CAM heatmaps for a trained classification model. Here's an example:

import numpy as np
import matplotlib.pyplot as plt
from graddy import seg_gradcam

Load your model

model_path = "model_path.h5"
gradcam = seg_gradcam(model_path)

Load an example image

image_path = "example_image_path.jpeg"
image = Image.open(image_path)

Generate the heatmap overlay image

heatmap_image = gradcam.generate_heatmap_image(image_path)

Display the heatmap overlay image

plt.imshow(heatmap_image)
plt.axis("off")
plt.show()

Arguments for seg_gradcam class

The seg_gradcam class takes the following arguments:

  • model_path: the path to the saved Keras model file.
  • target_size (optional): the size to which images should be resized (height, width.Default is (512, 512).
  • preprocess_input (optional): a function that will be applied to the image before passing it to the model. Default is None.
  • colormap (optional): the colormap to use for the heatmap. Default is "jet".
  • alpha (optional): the transparency of the heatmap. Should be between 0 and 1. Default is 0.5.

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

graddy-0.0.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graddy-0.0.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file graddy-0.0.1.tar.gz.

File metadata

  • Download URL: graddy-0.0.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for graddy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9b54e8c70b056f2087a6c732558cab966901751bf5e83c28e98a88f90a36eaa6
MD5 f7357fee97bcfbe5e038e75ebbbfba49
BLAKE2b-256 3e6ce8be73ac0e5297d6f8b9e9c8696cc64811a347506b8080ccf094f1c13d1d

See more details on using hashes here.

File details

Details for the file graddy-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: graddy-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for graddy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7ee2f665dd6b8d0adfc9b7e07e1ea6ce182af0895a035b98529558944d6942ee
MD5 9001bc668ff2d7d0a8f5cc1fb6564ff0
BLAKE2b-256 b46d11c439a9c2463c5e064d3822ad2eb24cf634dfd99615bda5baa878c15733

See more details on using hashes here.

Supported by

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