Click4Ai

490.

Hard

Grad-CAM

In this problem, you will be implementing a function to generate Grad-CAM heatmaps from a given input image and a pre-trained model. Grad-CAM is a technique used to visualize the importance of different regions of the input image for a specific class. Your function should take in an input image, a pre-trained model, and a class index, and return a heatmap representation of the Grad-CAM scores.

Example:

Suppose we have an input image x, a pre-trained model model, and a class index class_idx. The function should return a heatmap with the Grad-CAM scores plotted.

Constraints:

* The input image should be a 3D numpy array with shape (height, width, channels).

* The pre-trained model should be a Keras model.

* The class index should be an integer.

Test Cases

Test Case 1
Input: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Expected: Heatmap of Grad-CAM scores
Test Case 2
Input: [[10, 20, 30], [40, 50, 60], [70, 80, 90]]
Expected: Heatmap of Grad-CAM scores
+ 3 hidden test cases