Skip to main content

GradientVis

GradientVis is a Python library designed for visualizing neural network gradients, aimed at helping researchers and developers better interpret the inner workings of deep learning models. It includes various gradient visualization methods such as GradCAM, SmoothGrad, and Integrated Gradients making model interpretation easier.

Functions

  • GradCAM: Visualize the regions of an image that a CNN model is focusing on for a given class.
  • SmoothGrad: Reduce noise in gradient-based visualizations by adding noise to the input and averaging.
  • Integrated Gradients: A method for attributing the prediction of a neural network to its input features.
  • Postprocessing: Normalize and prepare visualizations for easier interpretation and presentation.

Installation

You can install gradientvis via pip directly from the repository:

pip install gradientvis

Usage

1. GradCAM Example

from gradientvis.methods.gradcam import GradCAM
from gradientvis.utils.preprocessing import preprocess_image

# Load your model (e.g., a CNN)
model = ...

# Preprocess your input image
image = preprocess_image("path_to_your_image.jpg")

# Generate GradCAM visualization
gradcam = GradCAM(model, model.layer4)  # Specify the target layer
cam = gradcam.generate(image, class_idx=0)

# Display the results
import matplotlib.pyplot as plt
plt.imshow(cam, cmap='jet')
plt.show()

2. SmoothGrad Example

from gradientvis.methods.smoothgrad import SmoothGrad
from gradientvis.utils.preprocessing import preprocess_image

# Load your model and image
model = ...
image = preprocess_image("path_to_your_image.jpg")

# Generate SmoothGrad visualization
smoothgrad = SmoothGrad(model)
grad = smoothgrad.generate(image, class_idx=0)

# Display the results
import matplotlib.pyplot as plt
plt.imshow(grad, cmap='jet')
plt.show()

3. Integrated Gradients Example

from gradientvis.methods.integrated_gradients import IntegratedGradients
from gradientvis.utils.preprocessing import preprocess_image

# Load your model and image
model = ...
image = preprocess_image("path_to_your_image.jpg")

# Generate Integrated Gradients visualization
integrated_gradients = IntegratedGradients(model)
integrated_grad = integrated_gradients.generate(image, class_idx=0)

# Display the results
import matplotlib.pyplot as plt
plt.imshow(integrated_grad, cmap='jet')
plt.show()

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for gradientvis 0.5.0

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

Source distribution (sdist)

Source distribution for gradientvis 0.5.0
File Size Uploaded
gradientvis-0.5.0.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gradientvis 0.5.0
File Interpreter ABI Platform
gradientvis-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / gradientvis-0.5.0.tar.gz

Download URL gradientvis-0.5.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5313983f140026b9d54759e56e204aa72944c84bab0200852614f7e598bd5fc8
BLAKE2b-256 checksum
How to use checksums
4a1bc078a8e9818dbb7cace03c88bf66b22d3430c6dcd4273155d4bacd96904f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / gradientvis-0.5.0-py3-none-any.whl

Download URL gradientvis-0.5.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
486c64cc9c7e954ab320be1553192749526ef0d73d29c7b623668bd6d97bb784
BLAKE2b-256 checksum
How to use checksums
7a0e6a7cbede9762c51e523b8252db76d64bed5dfd881d9d833b41c742ce5a79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.1.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