import numpy as np
import tensorflow as tf
from tensorflow import keras
# Displayfrom IPython.display import Image
import matplotlib.pyplot as plt
import matplotlib.cm as cm
# Configurable parameters# You can change these to another model.# To get the values for last_conv_layer_name and classifier_layer_names, use model.summary() to see the names of all layers in the model.
model_builder = keras.applications.xception.Xception
img_size =(299,299)
preprocess_input = keras.applications.xception.preprocess_input
decode_predictions = keras.applications.xception.decode_predictions
last_conv_layer_name ="block14_sepconv2_act"
classifier_layer_names =["avg_pool","predictions",]# The local path to our target image
img_path = keras.utils.get_file("african_elephant.jpg"," https://i.imgur.com/Bvro0YD.png")
display(Image(img_path))
# The Grad-CAM algorithm
defget_img_array(img_path, size):# `img` is a PIL image of size 299x299
img = keras.preprocessing.image.load_img(img_path