quantus.helpers.asserts module
This module holds a collection of asserts functionality that is used across the Quantus library to avoid undefined behaviour.
- quantus.helpers.asserts.assert_attributions(x_batch: array, a_batch: array) None
Asserts on attributions, assumes channel first layout.
- Parameters:
- x_batch: np.ndarray
The batch of input to compare the shape of the attributions with.
- a_batch: np.ndarray
The batch of attributions.
- Returns:
- None
- quantus.helpers.asserts.assert_attributions_order(order: str) None
Assert that order is in pre-defined list.
- Parameters:
- order: string
The different orders that attributions could be ranked in.
- Returns:
- None
- quantus.helpers.asserts.assert_explain_func(explain_func: Callable) None
Asser thta the explanation function is a callable.
- Parameters:
- explain_func: callable
An plot function input, asusmed to be a Callable.
- Returns:
- None
- quantus.helpers.asserts.assert_features_in_step(features_in_step: int, input_shape: Tuple[int, ...]) None
Assert that features in step is compatible with the image size.
- Parameters:
- features_in_step: integer
The number of features e.g., pixels included in each iteration.
- input_shape: Tuple[int…]
The shape of the input.
- Returns:
- None
- quantus.helpers.asserts.assert_indexed_axes(arr: array, indexed_axes: Sequence[int]) None
Checks that indexed_axes fits the given array.
- Parameters:
- arr: np.ndarray
A given array that we want to check indexed_axes against.
- indexed_axes: sequence
The sequence with indices, with axes.
- Returns:
- None
- quantus.helpers.asserts.assert_layer_order(layer_order: str) None
Assert that layer order is in pre-defined list.
- Parameters:
- layer_order: string
The various ways that a model’s weights of a layer can be randomised.
- Returns:
- None
- quantus.helpers.asserts.assert_nr_segments(nr_segments: int) None
Assert that the number of segments given the segmentation algorithm is more than one.
- Parameters:
- nr_segments: integer
The number of segments that the segmentaito algorithm produced.
- Returns:
- None
- quantus.helpers.asserts.assert_patch_size(patch_size: int | tuple, shape: Tuple[int, ...]) None
Assert that patch size is compatible with given image shape.
- Parameters:
- patch_size: integer
The size of the patch_size, assumed to tbe squared.
- input_shape: Tuple[int…]
the shape of the input.
- Returns:
- None
- quantus.helpers.asserts.assert_plot_func(plot_func: Callable) None
Assert that the plot function is a callable.
- Parameters:
- plot_func: callable
An plot function input, asusmed to be a Callable.
- Returns:
- None
- quantus.helpers.asserts.assert_segmentations(x_batch: array, s_batch: array) None
Asserts on segmentations, assumes channel first layout.
- Parameters:
- x_batch: np.ndarray
The batch of input to compare the shape of the attributions with.
- s_batch: np.ndarray
The batch of segmentations.
- Returns:
- None
- quantus.helpers.asserts.assert_value_smaller_than_input_size(x: ndarray, value: int, value_name: str) None
Checks if value is smaller than input size, assumes batch and channel first dimension.
- Parameters:
- x: np.ndarray
The input to check the value against.
- value: integer
The value that must be smaller than input size.
- value_name: string
The hyperparameter to check, e.g., “k” for TopKIntersection.
- Returns:
- None