[Experimental core] Python reproduces the Grad-Cam algorithm and saves the class activation map.

foreword

  The author assumes that the students who read this blog post know the principle of Grad-Cam. If you are not very clear about Grad-Cam, then I suggest that you read the paper corresponding to CAM first, then read the paper corresponding to Grad-Cam, and finally combine the formulas in the Grad-Cam paper to learn and apply the following code.

  Taking a step back, if you don’t want to understand and just want to use Grad-Cam, then it’s no problem to directly copy the code below, and you hardly need to make much changes!

1. Calculate the Grad-Cam corresponding to the different label components of the input image according to the logits and feature maps output by the network

  It is recommended that you save the following code as aops.py file. Among them, the cal_grad_cam function calculates the Grad-Cam of the corresponding feature map of the input image according to the logits output by the network and the intermediate feature map . Grad-Cam can be understood as an importance matrix of the corresponding feature map of the input image, and the normalized Grad-Cam&#x

Guess you like

Origin blog.csdn.net/qq_40968179/article/details/129650976