Skip to content

Wanna know what your model sees? Here's a package for applying EigenCAM (like GradCAM) and generating heatmap from the new YOLO models

License

Notifications You must be signed in to change notification settings

rigvedrs/YOLO-26-CAM

Repository files navigation

EigenCAM for YOLO 26 Interpretability

A package for applying EigenCAM (it is like GradCAM) and generating heatmaps for YOLO models. Simply clone the package and import the modules to get started.

The basic structure is close to Jacob Gil's package for AI explainability and modified to be used for YOLO models.

Use Cases

It can be used on YOLO classification, segmentation and object detection models. Now supports YOLO 26, YOLO V12, YOLO V11, YOLO V8, and older models - all you have to do is just pass the model and see it work automatically. Example notebooks for V8, V11, and V26 provided.

You can also send pull request for adding more functions to it.

What is EigenCAM

EigenCAM is a technique that involves computing the first principle component of the 2D activations in a neural network, without taking class discrimination into account, and has been found to produce effective results.

Image:

puppies

GrayScale Heatmaps:

Object Detection Classification Segmentation
od3.png cls3.png seg3.png

Combined

Object Detection Classification Segmentation
od1.png cls1.png cls1.png

Object Detection model

od2.png

Classification model

cls2.png

Segmentation model

seg2.png

Getting Started

Simply clone this repository or just download the yolo_cam folder. You must have the yolo_cam folder in the same location as your notebook

Import the libraries first:

from yolo_cam.eigen_cam import EigenCAM
from yolo_cam.utils.image import show_cam_on_image, scale_cam_image

Call the function and print the image (tasks supported = 'od', 'cls' and 'seg')

cam = EigenCAM(model, target_layers,task='cls')
grayscale_cam = cam(rgb_img)[0, :, :]
cam_image = show_cam_on_image(img, grayscale_cam, use_rgb=True)
plt.imshow(cam_image)
plt.show()

For the Object Detection Task, just change the task to 'od' and the rest is same.

cam = EigenCAM(model, target_layers,task='od')

The default task is 'od' so it is fine even if you don't specify the task then

Check out the Jupyter Notebooks (YOLO V8n EigenCAM, YOLO V11 EigenCAM, and YOLO V26 EigenCAM) to understand it better and also handle any issues.

Supported YOLO Versions

YOLO 26 - Latest model with full support for classification, object detection, and segmentation
YOLO V12 - Full support
YOLO V11 - Full support
YOLO V8 - Full support
Older YOLO versions - Should work with most models

ToDo:

See the open issues for a list of proposed features (and known issues).

  • Solve the issue with having to re-run the cells
  • Add support for segmentation model
  • Add support for YOLO 26 models
  • Add support for pose detection model
  • Solve pending issues

Contributing

The open source community thrives on contributions, making it an incredible space for learning, inspiration, and creativity. Please feel free to share any contributions you have for this project.

  • Create your Feature Branch (git checkout -b feature/CoolFeature)
  • Commit your Changes (git commit -m 'Add some CoolFeature')
  • Push to the Branch (git push origin feature/CoolFeature)
  • Open a Pull Request

Star History

Star History Chart

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Gmail

LinkedIn

About

Wanna know what your model sees? Here's a package for applying EigenCAM (like GradCAM) and generating heatmap from the new YOLO models

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7