brails.utils.plot_tools module

This module defines utilities for creating visually-appealing figures.

class brails.utils.plot_tools.PlotTools

Bases: object

A utility class for generating visually-appealing image grids.

The PlotTools class provides static methods to visualize model predictions alongside images, enabling intuitive and structured displays for both qualitative evaluation and presentation purposes. It is designed to support image sets managed through the ImageSet class and prediction outputs from classification models.

Methods:
show_predictions(

images: ImageSet, predictions: Dict[str, Union[int, str]], attribute_name: str, num_samples: Union[int, str] = ‘all’, crop_image: bool = True

) -> None:

Display a grid of images annotated with model predictions. Images are optionally cropped and resized for consistent presentation.

static show_predictions(images: ImageSet, predictions: Dict[str, int | float | str], attribute_name: str, num_samples: int | str = 'all', crop_image: bool = True) None

Display a set of images along with their corresponding predictions.

This method randomly samples a specified number of images from the provided images object, optionally crops the images, resizes them, and then displays them in a grid with the associated predictions.

Args:
images (ImageSet):

A custom object that holds image paths and metadata. It should have an attribute ‘images’ (a list of image objects) and ‘dir_path’ (a string representing the directory path where images are located).

predictions (dict):

A dictionary where the keys are image identifiers (e.g., file names or unique keys) and the values are the predicted labels (e.g., binary or categorical values).

attribute_name (str):

The name of the attribute being predicted, which is displayed in the title for each image.

num_samples (int or str, optional)

The number of images to display. If set to ‘all’, all images in the set will be displayed. Defaults to ‘all’.

crop_image (bool, optional):

If set to True, the images will be cropped (top 1/6 and bottom 1/4 removed). If set to False, the images will be displayed without cropping. Defaults to True.

Returns:
None

This method directly displays the plot of images and their predictions, and does not return any value.

Notes: - The images are resized to fit the grid, adjusting for the maximum

image height.

  • Axes are hidden for a cleaner presentation, and the prediction value is displayed as the title for each image.

  • The method handles both cropping and resizing while maintaining the image aspect ratio.

Example: show_predictions(images=my_image_set, predictions=my_predictions,

attribute_name=’Class’, num_samples=5, crop_image=True)