Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_2828\ in <module>


from tensorflow.keras.models import Sequential, Model
epochs = 1 # Define the number of epochs
for epoch in range(epochs):
history =, np.array(y_train), batch_size=64, epochs=1, validation_split=0.2)
Model = Model(inputs=dilated_cnn_input, outputs=output)
# Choose an image from the validation set for visualization
img_array = x_val[0:1]

# Get the Grad-CAM for the first convolutional layer
cam = get_grad_cam(model, img_array, 'conv2d')  # Replace 'conv2d' with the actual name of the convolutional layer

# Resize the CAM to the input image size
resized_cam = cv2.resize(cam, (img_array.shape[2], img_array.shape[1]))

# Superimpose the CAM on the original image
heatmap = cv2.applyColorMap(np.uint8(255 * resized_cam), cv2.COLORMAP_JET)
superimposed_img = cv2.addWeighted(img_array[0], 0.5, heatmap, 0.5, 0)

# Save or display the original image and the superimposed image
cv2.imwrite(f'grad_cam_epoch_{epoch}.jpg', np.hstack([img_array[0], superimposed_img])) 


  • Chris Harrold
    Chris Harrold Member, Administrator, Employee Posts: 169
    First Answer First Comment First Anniversary Ansys Employee

    @suleiman I realize this is a very old post, but was going through unanswered questions and saw it was out here. I hope you have gotten an answer, but if not here are some tips for getting someone to take a look:

    • you do not have any tags so there is no indication what language, product, or technology this refers to
    • the title of your post doesn't indicate what it refers to and is just your error message
    • your post doesn't have a question, explanation of the issue, or any other information except code

    If you want to tag this and give some extra context and information I can get someone to take a look and try and assist.