YOLO-V5 GRADCAM
I constantly desired to know to which part of an object the object-detection models pay more attention. So I searched for it, but I didn't find any for Yolov5.
Here is my implementation of Grad-cam for YOLO-v5. To load the model I used the yolov5's main codes, and for computing GradCam I used the codes from the gradcam_plus_plus-pytorch repository.
Please follow my GitHub account and star
Update:
Repo works fine with yolov5-v6.1
Installation
pip install -r requirements.txt
Infer
python main.py --model-path yolov5s.pt --img-path images/cat-dog.jpg --output-dir outputs
NOTE: If you don't have any weights and just want to test, don't change the model-path argument. The yolov5s model will be automatically downloaded thanks to the download function from yolov5.
NOTE: For more input arguments, check out the main.py or run the following command:
python main.py -h
Custom Name
To pass in your custom model you might want to pass in your custom names as well, which be done as below:
python main.py --model-path cutom-model-path.pt --img-path img-path.jpg --output-dir outputs --names obj1,obj2,obj3
Examples
Note
I checked the code, but I couldn't find an explanation for why the truck's heatmap does not show anything. Please inform me or create a pull request if you find the reason.
This problem is solved in version 6.1
TO Do
- Add GradCam++
- Add ScoreCam
- Add the functionality to the deep_utils library
References
- https://github.com/1Konny/gradcam_plus_plus-pytorch
- https://github.com/ultralytics/yolov5
- https://github.com/pooya-mohammadi/deep_utils
Citation
Please cite yolov5-gradcam if it helps your research. You can use the following BibTeX entry:
@misc{deep_utils,
title = {yolov5-gradcam},
author = {Mohammadi Kazaj, Pooya},
howpublished = {\url{github.com/pooya-mohammadi/yolov5-gradcam}},
year = {2021}
}