visualizing what convnets learn respect to the class under consideration for instancegiven an image fed into dogsversus-cats convnetcam visualization allows you to generate heatmap for the class "cat,indicating how cat-like different parts of the image areand also heatmap for the class "dog,indicating how dog-like parts of the image are the specific implementation you'll use is the one described in "grad-camvisual explanations from deep networks via gradient-based localization " it' very simpleit consists of taking the output feature map of convolution layergiven an input imageand weighing every channel in that feature map by the gradient of the class with respect to the channel intuitivelyone way to understand this trick is that you're weighting spatial map of "how intensely the input image activates different channelsby "how important each channel is with regard to the class,resulting in spatial map of "how intensely the input image activates the class we'll demonstrate this technique using the pretrained vgg network again listing loading he vgg net work wit pret rained weight from keras applications vgg import vgg model vgg (weights='imagenet'note that you include the densely connected classifier on topin all previous casesyou discarded it consider the image of two african elephants shown in figure (under creative commons license)possibly mother and her calfstrolling on the savanna let' convert this image into something the vgg model can readthe model was trained on images of size preprocessed according to few rules that are packaged in the utility function keras applications vgg preprocess_input so you need to load the imageresize it to convert it to numpy float tensorand apply these preprocessing rules figure test pict ure of african elephant ramprasaath selvaraju et al arxiv ( )licensed to