detoxai.visualization
Submodules
detoxai.visualization.DataVisualizer submodule
- class detoxai.visualization.DataVisualizer.DataVisualizer(data_loader: DetoxaiDataLoader, plot_config: dict = {}, draw_rectangles: bool = False, rectangle_config: dict = {})[source]
Bases:
ImageVisualizer- visualize_batch(batch_num: int, max_images: int | None = 36, batch_preds: Tensor | None = None, show_labels: bool = True) None[source]
- Parameters:
batch_num – int:
max_images – int | None: (Default value = 36)
batch_preds – torch.Tensor | None: (Default value = None)
show_labels – bool: (Default value = True)
Returns:
detoxai.visualization.HeatmapVisualizer submodule
- class detoxai.visualization.HeatmapVisualizer.HeatmapVisualizer(data_loader: DetoxaiDataLoader | DataLoader, model: Module, lrp_object: LRPHandler = None, plot_config: dict = {}, draw_rectangles: bool = False, rectangle_config: dict = {})[source]
Bases:
ImageVisualizer- visualize_batch(batch_num: int, condition_on: ConditionOn = ConditionOn.PROPER_LABEL, show_cbar: bool = True, max_images: int | None = 36, return_fig: bool = False) None[source]
- Parameters:
batch_num – int:
condition_on – ConditionOn: (Default value = ConditionOn.PROPER_LABEL)
show_cbar – bool: (Default value = True)
max_images – int | None: (Default value = 36)
return_fig – bool: (Default value = False)
Returns:
- visualize_agg(batch_num: int, condition_on: ConditionOn = ConditionOn.PROPER_LABEL) None[source]
- Parameters:
batch_num – int:
condition_on – ConditionOn: (Default value = ConditionOn.PROPER_LABEL)
Returns:
detoxai.visualization.ImageVisualizer submodule
- class detoxai.visualization.ImageVisualizer.ImageVisualizer[source]
Bases:
Visualizer,ABC- init_rectangle_painter(draw_rectangles: bool, rectangle_config: dict)[source]
Initialize the rectangle painter.
- Parameters:
draw_rectangles (bool) – Whether to draw rectangles on the image.
rectangle_config (dict) – The configuration for the rectangles.
Should contain the following keys: rect (tuple): The rectangle coordinates in the form (x, y, width, height). Mandatory. color (str): The color of the rectangle. Default is “black”. linewidth (int): The width of the rectangle’s border. Default is 2.
draw_rectangles: bool: rectangle_config: dict:
Returns:
detoxai.visualization.LRPHandler submodule
- class detoxai.visualization.LRPHandler.LRPHandler(attributor_name: str = 'Gradient', composite_name: str = 'EpsilonPlus', canonizers: list[str] = [], n_classes: int | None = None, **kwargs)[source]
Bases:
objectLRPHandler is a class that handles the calculation of input image attributions for a given model and dataset.
- calculate(model: Module, data_loader: object, batch_num: int | None, max_images: int | None = None) Tensor[source]
Calculate LRP attribution
- Parameters:
model – nn
data_loader – WrappedDataLoader | torch Dataloader
batch_num – int
attribution – is calculated for the entire datset
model – nn.Module:
data_loader – object:
batch_num – int | None:
max_images – int | None: (Default value = None)
- Returns:
torch.Tensor of size (L, N, IMG_w, IMG_h), where N is the number of samples, L is the class on which
LRP was conditioned, IMG_w and IMG_h are the width and height of the image.
detoxai.visualization.MetricsVisualizer submodule
- class detoxai.visualization.MetricsVisualizer.MetricsVisualizer[source]
Bases:
Visualizer,ABC- metrics_config: dict | None = None
detoxai.visualization.SSVisualizer submodule
- class detoxai.visualization.SSVisualizer.SSVisualizer(data_loader: DetoxaiDataLoader | DataLoader, model: Module, lrp_object: LRPHandler = None, plot_config: dict = {}, draw_rectangles: bool = False, rectangle_config: dict = {})[source]
Bases:
ImageVisualizerSS - Side by Side visualizer for Heatmaps and Data
- visualize_batch(batch_num: int, lrp_condition_on: ConditionOn = ConditionOn.PROPER_LABEL, lrp_show_cbar: bool = True, max_images: int | None = 36, show_labels: bool = True) None[source]
- Parameters:
batch_num – int:
lrp_condition_on – ConditionOn: (Default value = ConditionOn.PROPER_LABEL)
lrp_show_cbar – bool: (Default value = True)
max_images – int | None: (Default value = 36)
show_labels – bool: (Default value = True)
Returns:
detoxai.visualization.ScatterVisualizer submodule
- class detoxai.visualization.ScatterVisualizer.ScatterVisualizer(plots_config: dict = {})[source]
Bases:
Visualizer- create_plot(results: DataFrame | dict[str, CorrectionResult], rows: list[str] = ['Accuracy', 'GMean', 'F1'], cols: list[str] = ['Equalized_odds', 'Demographic_parity', 'Equal_opportunity', 'Accuracy_parity'], ticks_x: int = 4, ticks_y: int = 4, round_to: int = 3)[source]
- Parameters:
results – pd.DataFrame | dict[str, CorrectionResult]
rows – list[str]: (Default value = [“Accuracy”)
"GMean"
"F1"]
cols – list[str]: (Default value = [“Equalized_odds”)
"Demographic_parity"
"Equal_opportunity"
"Accuracy_parity"
]
ticks_x – int: (Default value = 4)
ticks_y – int: (Default value = 4)
round_to – int: (Default value = 3)
Returns:
detoxai.visualization.TableVisualizer submodule
- class detoxai.visualization.TableVisualizer.TableVisualizer(results: dict, metrics_config: dict)[source]
Bases:
MetricsVisualizer- create_table(*args, **kwargs)
detoxai.visualization.Visualizer submodule
- class detoxai.visualization.Visualizer.Visualizer[source]
Bases:
ABCBase class for visualizers with plotting and logging capabilities.
This class provides basic functionality for creating, displaying, saving, and logging plots using matplotlib. It can be used with an ExperimentLogger for experiment tracking.
- set_up_plots_configuration(config: dict) None[source]
Configure plotting parameters from a configuration dictionary.
- Parameters:
config – Dictionary containing plot configuration parameters: - plt_save_kwargs: Dict of kwargs for plt.savefig (default: {}) - plot_style: Matplotlib style to use (default: ‘ggplot’) - shape_multiplier: Multiplier for plot dimensions (default: 1) - fontsize: Base font size for plots (default: 12)
- attach_logger(logger: ExperimentLogger) None[source]
Attach a logger to the visualizer, enabling logging of plots
- Parameters:
logger – ExperimentLogger:
- show_plot() None[source]
Display the current figure using matplotlib’s show method.
This method displays the figure stored in self.figure.
- show() None[source]
Display all current matplotlib figures.
This method shows all active matplotlib figures using plt.show().
- close_plot() None[source]
Close the current figure.
This method closes the figure stored in self.figure to free up memory.
- get_canvas(rows: int = 1, cols: int = 1, shape: tuple[int, int] = (10, 10)) tuple[Figure, Axes][source]
Create and return an empty matplotlib canvas for plotting.
- Parameters:
rows – Number of subplot rows (default: 1)
cols – Number of subplot columns (default: 1)
shape – Tuple of (width, height) in inches for the figure size (default: (10, 10))
- Returns:
- A tuple containing:
matplotlib.figure.Figure: The created figure
matplotlib.axes.Axes or array of Axes: The created subplot(s)
- Return type:
tuple
- log(name: str, step: int = None)[source]
Log the current figure using the attached logger.
- Parameters:
name – Name of the logged figure
step – Optional step or iteration number for the logged figure
- Raises:
AssertionError – If no logger is attached to the visualizer
- log_image(name: str, step: int = None)[source]
Log the current figure as an image using the attached logger.
This method is an alias for the log() method.
- Parameters:
name – Name of the logged image
step – Optional step or iteration number for the logged image
- Raises:
AssertionError – If no logger is attached to the visualizer
- log_table(table: dict, name: str, step: int = None)[source]
Log a dictionary as a table using the attached logger.
- Parameters:
table – Dictionary containing the table data
name – Name of the logged table
step – Optional step or iteration number for the logged table
- Raises:
AssertionError – If no logger is attached to the visualizer