A library for visualizing neural network gradients
Project description
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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gradientvis-0.5.0.tar.gz.
File metadata
- Download URL: gradientvis-0.5.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5313983f140026b9d54759e56e204aa72944c84bab0200852614f7e598bd5fc8
|
|
| MD5 |
0569e25d5556176c2b4ecc7a42e8ca3b
|
|
| BLAKE2b-256 |
4a1bc078a8e9818dbb7cace03c88bf66b22d3430c6dcd4273155d4bacd96904f
|
File details
Details for the file gradientvis-0.5.0-py3-none-any.whl.
File metadata
- Download URL: gradientvis-0.5.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
486c64cc9c7e954ab320be1553192749526ef0d73d29c7b623668bd6d97bb784
|
|
| MD5 |
561f6308c4a1dd3506fea78fe07d87bc
|
|
| BLAKE2b-256 |
7a0e6a7cbede9762c51e523b8252db76d64bed5dfd881d9d833b41c742ce5a79
|