morphoclass.xai.grad_cam_on_models module¶
Explain model layers using GradCam.
-
morphoclass.xai.grad_cam_on_models.get_edges_colors_based_on_barcode_colors(tree, colors)¶ Collect colors for edges based on barcode colors.
- Parameters
tree (tmd.Tree.Tree) – Morphology tree used to create barcode.
colors (list_like) – List of barcode colors.
- Returns
color_edges – List of edge colors.
- Return type
list_like
-
morphoclass.xai.grad_cam_on_models.grad_cam_cnn_model(model, dataset, sample_id)¶ Explain CNN model.
Plot with feature maps after each feature extractor layer. Starting from original image to the last feature extractor layer. Only one morphology sample is visualized.
- Parameters
model (morphoclass.models.cnnet.CNNet) – Model that will be explained.
dataset (morphoclass.data.morphology_dataset.MorphologyDataset) – Dataset containing embeddings and morphologies.
sample_id (int) – The id of embedding in the dataset.
- Returns
fig – Figure with explainable plots.
- Return type
matplotlib.figure.Figure
-
morphoclass.xai.grad_cam_on_models.grad_cam_gnn_model(model, dataset, sample_id)¶ Explain GNN model.
Plot with two rows:
Original graph and graph with GradCam values within the nodes.
Heatmap of the original graph (zero-values) and heatmap of the GradCam values on the graph.
Only one morphology sample is visualized.
- Parameters
model (morphoclass.models.man_net.ManNet) – Model that will be explained.
dataset (morphoclass.data.morphology_dataset.MorphologyDataset) – Dataset containing morphologies.
sample_id (int) – The id of morphology in the dataset.
- Returns
fig – Figure with explainable plots.
- Return type
matplotlib.figure.Figure
-
morphoclass.xai.grad_cam_on_models.grad_cam_perslay_model(model, dataset, sample_id)¶ Explain PersLay model.
Plot with 3 rows:
Barcodes: The original barcode and GradCam weighted barcode (colored bar) after each feature extraction layer.
Persistence diagrams: The original PD and GradCam weighted PD (colored dot) after each feature extraction layer.
Graph: The original graph and GradCam weighted graph (colored edge) after each feature extraction layer.
- Parameters
model (morphoclass.models.coriander_net.CorianderNet) – Model that will be explained.
dataset (morphoclass.data.morphology_dataset.MorphologyDataset) – Dataset containing embeddings and morphologies.
sample_id (int) – The id of embedding in the dataset.
- Returns
fig – Figure with explainable plots.
- Return type
matplotlib.figure.Figure