focal.grad_cam module

This module defines the logic for displaying heatmaps for an image to view where the CNN model is focusing on.

class focal.grad_cam.GradCAM(model_path: str, image_folder: str, class_index: int | None = 0, backbone: str | None = None, conv_layer_name: str | None = None)[source]

Bases: object

compute_all_heatmaps(save_path: str) None[source]

Computes heatmaps for a number of images.

Parameters:

save_path – path to save the computed heatmap plot

compute_heatmap(image_path: str, title: str, fig_size: List[int]) None[source]

Computes the heatmap for a given image and parameter vector.

Parameters:
  • image (str) – The input image path.

  • title – Title of the plot

  • fig_size – size of each plotted figure

plot_heatmap(title: str, gradcam: Any, img_array: ndarray, fig_size: List[int]) None[source]

Plotting logic for individual heatmap. :param title: Title of indivdual plot :param gradcam: gradcam object :param img_array: array of pixels :param fig_size: size of individual plot