jacobgil / pytorch-grad-cam

Advanced AI Explainability for computer vision. Support for CNNs, Vision Transformers, Classification, Object detection, Segmentation, Image similarity and more.
https://jacobgil.github.io/pytorch-gradcam-book
MIT License
10.06k stars 1.52k forks source link

How to apply Grad-CAM on YOLOv5? #287

Closed Jonathan-CHJ closed 2 years ago

Jonathan-CHJ commented 2 years ago

Hi,

I am quite new to XAI. Is it possible to apply Grad-CAM instead of EigenCAM on YOLOv5? I have faced an error when I am trying to use Grad-CAM on YOLOv5.

This is the code: image

This is the error: image

jacobgil commented 2 years ago

Hi, Grad-CAM isn't supported for YOLO5 because the gradient computation isn't exposed there. Fortunately we can use gradient free methods, and have a tutorial exactly about this for YOLO5: https://github.com/jacobgil/pytorch-grad-cam/blob/master/tutorials/EigenCAM%20for%20YOLO5.ipynb

Jonathan-CHJ commented 2 years ago

Alright, thank you for your explanation.