peal.visualization.visualize_counterfactual_gradients

Debug grids for gradient-based counterfactual search.

While a counterfactual explainer optimises an image (or a generator latent) against the predictor, visualize_step() writes one labelled image grid per step showing the input, the encoded/decoded images, the pixel and latent gradients as heatmaps, the masks in play and the best counterfactual found so far. create_label_image() renders the row captions as image tensors so the whole grid can be saved with torchvision.utils.save_image.

Functions

create_label_image

Render a text caption as an image tensor of a given size.