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 ⭐ the project if this functionality benefits your research or projects.
Repo works fine with yolov5-v6.1
pip install -r requirements.txt
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
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
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
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}
}