Skip to main content

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.020.1).
  • show_result (bool): If True, displays the result with heatmaps overlaid. Set to False to skip visualization.
  • renormalize (bool): If True, 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): If True, 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hotspotyolo-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

hotspotyolo-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

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

Hashes for hotspotyolo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e1a12190fdfa2f4a16769318090f22a35afcb7a0bdaa9d6357bb9ad5c93ff184
MD5 83245f0155e5f1c78841272d38314da7
BLAKE2b-256 f4bbac2bc37e8da8a22fcbc39facb2c5b5f1e065d05566c220157cc9102230d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for hotspotyolo-0.1.0.tar.gz:

Publisher: python-publish.yml on atharvahude/hotspotyolo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for hotspotyolo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8475225896ab41db5c2b0bc345c68d7e68d20d7845296211601bedfdb9738169
MD5 86a9f9be68240a1abd1a6b44e40beca2
BLAKE2b-256 4925458a86a9807a924728eff315d30ce8db87aabe90042442afde17c3ce6390

See more details on using hashes here.

Provenance

The following attestation bundles were made for hotspotyolo-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on atharvahude/hotspotyolo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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