Visualizations#
aitlas.visualizations.classification module#
Classes and methods for visualizations for classification tasks.
- plot_confusion_matrix(confusion_matrix, axes, class_label, class_names, fontsize=14)[source]#
Plots a confusion matrix.
- Parameters:
confusion_matrix (array-like of shape (n_classes, n_classes)) – The confusion matrix to plot.
axes (matplotlib.axes.Axes) – The matplotlib axes object to plot on.
class_label (str) – The label of the class for the confusion matrix.
fontsize (int, optional) – The fontsize for the plot, defaults to 14.
- plot_multilabel_confusion_matrix(cm_array, labels, dataset_name, output_file)[source]#
Plots multiple confusion matrices in a .pdf format for multilabel tasks.
- plot_multiclass_confusion_matrix(cm_array, labels, dataset_name, output_file)[source]#
Plots multiple confusion matrices .pdf format useful for multiclass tasks.
- class PrecisionRecallCurve(y_true, y_pred, y_prob, labels, file, **kwargs)[source]#
Bases:
BaseDetailedVisualization
- class ImageLabelsVisualization(y_true, y_pred, y_prob, labels, file, **kwargs)[source]#
Bases:
BaseDetailedVisualization
Class for visualising predictions for an image.
Initialize the ImageLabelsVisualization class.
- Parameters:
y_true (array-like of shape (n_samples,)) – Ground truth (correct) labels.
y_pred (array-like of shape (n_samples,)) – Predicted labels, as returned by a classifier.
file (str) – The file path to save the plot.
kwargs – Additional keyword arguments.
- plot()[source]#
Plots the image with the predictions.
- Returns:
matplotlib.figure.Figure object with the plot
- Return type:
aitlas.visualizations.eopatch module#
Method for visualising predictions in EOpatch format for multi-temporal data. Useful for croptype classification tasks.
- display_eopatch_predictions(eopatches_path, patch, y_pred, test_index, y_true, classmapping)[source]#
Displays the predictions of an EOPatch.
- Parameters:
eopatches_path (str) – The path to the directory containing EOPatches.
patch (str) – The specific patch to be displayed.
y_pred (array-like of shape (n_samples,)) – The predicted labels, as returned by a classifier.
test_index (pandas.DataFrame) – The indices of the test set.
y_true (array-like of shape (n_samples,)) – Ground truth (correct) labels.
classmapping (pandas.DataFrame) – A mapping from class labels to class names.
- Returns:
matplotlib.figure.Figure object with the plot
- Return type:
aitlas.visualizations.grad_cam module#
Classes and methods for GRAD-CAM visualizations, used for classification tasks.
Note
Based on the implementation at: jacobgil/pytorch-grad-cam
- class ActivationsAndGradients(model, target_layers, reshape_transform)[source]#
Bases:
object
Class for extracting activations and registering gradients from targetted intermediate layers.
- Parameters:
model – The model to be evaluated
target_layers – The target layers from which to extract activations and gradients
reshape_transform – A function to reshape the activation and gradient data
- save_activation(module, input, output)[source]#
Saves an activation.
- Parameters:
module – The module from which to save the activation
input – The input data to the module
output – The output data from the module
- show_cam_on_image(img, mask, use_rgb=False, colormap=2, image_weight=0.5)[source]#
This function overlays the cam mask on the image as an heatmap.
By default the heatmap is in BGR format. :param img: The base image in RGB or BGR format. :param mask: The cam mask. :param use_rgb: Whether to use an RGB or BGR heatmap, this should be set to True if ‘img’ is in RGB format. :param colormap: The OpenCV colormap to be used. :param image_weight: The final result is image_weight * img + (1-image_weight) * mask. :returns: The default image with the cam overlay.
- class BaseCAM(model, target_layers, use_cuda=False, reshape_transform=None, compute_input_gradient=False, uses_gradients=True)[source]#
Bases:
object
- Parameters:
- class GradCAM(model, target_layers, use_cuda=False, reshape_transform=None)[source]#
Bases:
BaseCAM
Gradient-weighted Class Activation Mapping (Grad-CAM) class.
- Parameters:
model – The model to be evaluated
target_layers – The target layers from which to extract activations and gradients
use_cuda – Whether to use CUDA for computation (default: False)
reshape_transform – A function to reshape the activation and gradient data (default: None)
aitlas.visualizations.segmentation module#
Classes and methods for visualizations for segmentation tasks.
- class ImageMaskPredictionVisualization(y_true, y_pred, y_prob, labels, file, **kwargs)[source]#
Bases:
BaseDetailedVisualization
Class for visualizing the image mask predictions.
Initialisation
- Parameters:
- display_image_segmentation(image, y_true, y_pred, y_prob, labels, file)[source]#
Displays the predicted segmentation masks for each label.
- Parameters:
image (array-like or PIL image) – The input image
y_true (array-like of shape (n_samples,)) – The ground truth labels
y_pred (array-like of shape (n_samples,)) – The predicted labels
file (str) – The output file path