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 that decides how many detections we should consider in forward pass. (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

You can install the latest release directly from PyPI:

pip install hotspotyolo

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',
    'conf_threshold': 0.2, 
    'ratio': 0.02, 
    'show_result': True, 
    'renormalize': True, 
    'task':'obb', 
    'img_size':640, 
    'save_metadata': True, 
}

model = yolo_heatmap(**params)
model(image_path, output_folder)

Results

OBB CAM

OBB CAM Example

Detection CAM

Detection CAM Example

Segmentation CAM

Segmentation CAM Example

Classification CAM

Classification CAM Example

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.

Important

Right now the pose model is not working.

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.1.tar.gz (10.3 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.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file hotspotyolo-0.1.1.tar.gz.

File metadata

  • Download URL: hotspotyolo-0.1.1.tar.gz
  • Upload date:
  • Size: 10.3 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.1.tar.gz
Algorithm Hash digest
SHA256 c16edeb84830566b2b3339e188399e60a58963c410184ee9cefeabc9a694793a
MD5 6ae0887d2e4b2928ef91722345b4ecee
BLAKE2b-256 837fe758af755a3bb4119b34733243135de5aaf6076d135e70036ad687afc386

See more details on using hashes here.

Provenance

The following attestation bundles were made for hotspotyolo-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: hotspotyolo-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4eb24e9fd75c10badfa4bdc045462d2b27593e3c75572241199861eb2b28a0c7
MD5 029f8c7d14c642e5be426e8c614c44ca
BLAKE2b-256 ec56fa5a1a09732990329958f078375b60644f5dade9323b74c7c0928b25605e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hotspotyolo-0.1.1-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