Generate CAMs of Yolo Models
Project description
hotspotyolo
Overview
The hotspotyolo is a Python package designed for generating heatmaps using the YOLOv8 - v11 model. It provides an easy-to-use interface for visualizing model predictions and understanding the decision-making process of the YOLOv8 architecture.
Parameters
The params dictionary configures how the heatmap is generated and visualized. Here’s a description of each parameter:
- weight (
str): Path to the YOLO model weights file (e.g.,"best.pt"). - device (
str): Device to run inference on. Use"cuda:0"for GPU or"cpu"for CPU. - method (
str): The XAI method to use for heatmap generation. Supported options include:"GradCAMPlusPlus","GradCAM","XGradCAM","EigenCAM","HiResCAM","LayerCAM","RandomCAM","EigenGradCAM","KPCA_CAM". - layer (
list[int]): List of layer indices to target for heatmap extraction. Example:[21]. - backward_type (
str): Specifies which outputs to use for backpropagation. Options depend on the task:detect:<class, box, all>segment:<class, box, segment, all>pose:<box, keypoint, all>obb:<box, angle, all>classify:<all>
- conf_threshold (
float): Confidence threshold for detections (e.g.,0.2). - ratio (
float): Ratio for filtering small objects (recommended range:0.02–0.1). - show_result (
bool): IfTrue, displays the result with heatmaps overlaid. Set toFalseto skip visualization. - renormalize (
bool): IfTrue, renormalizes the heatmap for better visualization. - task (
str): Task type. Supported values:"detect","segment","pose","obb","classify". - img_size (
int): Input image size for the model (e.g.,1280). - save_metadata (
bool): IfTrue, saves additional metadata in the output folder.
Adjust these parameters as needed for your specific use case and model.
Installation
To install the package, clone the repository and run the following command:
pip install -e .
If you already have requirements.txt then do this most of you will have it.
pip install . --no-deps
Usage
from hotspotyolo import yolo_heatmap
image_path = "sample.png"
model_weight = "best.pt"
output_folder = 'test_result'
params = {
'weight': model_weight,
'device': 'cuda:0',
'method': 'GradCAMPlusPlus',
'layer': [21],
'backward_type': 'all', # detect:<class, box, all> segment:<class, box, segment, all> pose:<box, keypoint, all> obb:<box, angle, all> classify:<all>
'conf_threshold': 0.2, # 0.2
'ratio': 0.02, # 0.02-0.1
'show_result': True, # Set to False if you do not need to draw results
'renormalize': True,
'task':'obb', # Task (detect, segment, pose, obb, classify)
'img_size':1280, # Image size
'save_metadata': True, # Save metadata in the output folder
}
model = yolo_heatmap(**params)
model(image_path, output_folder)
Testing
To run the tests, navigate to the tests directory and execute:
pytest
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for more 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 hotspotyolo-0.1.0.tar.gz.
File metadata
- Download URL: hotspotyolo-0.1.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1a12190fdfa2f4a16769318090f22a35afcb7a0bdaa9d6357bb9ad5c93ff184
|
|
| MD5 |
83245f0155e5f1c78841272d38314da7
|
|
| BLAKE2b-256 |
f4bbac2bc37e8da8a22fcbc39facb2c5b5f1e065d05566c220157cc9102230d9
|
Provenance
The following attestation bundles were made for hotspotyolo-0.1.0.tar.gz:
Publisher:
python-publish.yml on atharvahude/hotspotyolo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hotspotyolo-0.1.0.tar.gz -
Subject digest:
e1a12190fdfa2f4a16769318090f22a35afcb7a0bdaa9d6357bb9ad5c93ff184 - Sigstore transparency entry: 219870000
- Sigstore integration time:
-
Permalink:
atharvahude/hotspotyolo@e8ad0d56c704635e7d3134a4dd501599186232b5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/atharvahude
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e8ad0d56c704635e7d3134a4dd501599186232b5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hotspotyolo-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hotspotyolo-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8475225896ab41db5c2b0bc345c68d7e68d20d7845296211601bedfdb9738169
|
|
| MD5 |
86a9f9be68240a1abd1a6b44e40beca2
|
|
| BLAKE2b-256 |
4925458a86a9807a924728eff315d30ce8db87aabe90042442afde17c3ce6390
|
Provenance
The following attestation bundles were made for hotspotyolo-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on atharvahude/hotspotyolo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hotspotyolo-0.1.0-py3-none-any.whl -
Subject digest:
8475225896ab41db5c2b0bc345c68d7e68d20d7845296211601bedfdb9738169 - Sigstore transparency entry: 219870001
- Sigstore integration time:
-
Permalink:
atharvahude/hotspotyolo@e8ad0d56c704635e7d3134a4dd501599186232b5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/atharvahude
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e8ad0d56c704635e7d3134a4dd501599186232b5 -
Trigger Event:
release
-
Statement type: