Common Module
The signxai.common
module contains framework-agnostic utilities and functions used by both the PyTorch and TensorFlow implementations.
Visualization Tools
The visualization module provides utilities for visualizing and displaying explanation results.
- signxai.common.visualization.normalize_relevance_map(relevance_map, percentile=99)[source]
Normalizes a relevance map to a specified percentile range.
- Parameters:
relevance_map (numpy.ndarray) – The relevance map to normalize
percentile (int, optional) – The percentile value for upper/lower bounds normalization
- Returns:
Normalized relevance map with values in range [-1, 1]
- Return type:
- signxai.common.visualization.relevance_to_heatmap(relevance_map, cmap='seismic', clip_values=(-1, 1))[source]
Converts a relevance map to a heatmap visualization.
- Parameters:
relevance_map (numpy.ndarray) – The relevance map to visualize
cmap (str, optional) – The colormap to use for visualization (default: ‘seismic’)
clip_values (tuple, optional) – The lower and upper bounds for clipping the relevance values
- Returns:
RGB heatmap image
- Return type:
- signxai.common.visualization.overlay_heatmap(original_image, heatmap, alpha=0.5)[source]
Overlays a heatmap on an original image.
- Parameters:
original_image (numpy.ndarray) – The original input image
heatmap (numpy.ndarray) – The heatmap to overlay
alpha (float, optional) – The blending factor between original image and heatmap
- Returns:
Overlaid image
- Return type:
- signxai.common.visualization.aggregate_and_normalize_relevancemap_rgb(relevance_map)
Aggregates and normalizes a relevance map for RGB images.
- Parameters:
relevance_map (numpy.ndarray) – The relevance map to aggregate (with channels)
- Returns:
Aggregated and normalized relevance map
- Return type:
- signxai.common.visualization.visualize_comparison(original_image, relevance_maps, method_names, figsize=(15, 5), cmap='seismic')
Creates a side-by-side visualization of multiple relevance maps.
- Parameters:
original_image (numpy.ndarray) – The original input image
relevance_maps (list of numpy.ndarray) – List of relevance maps to visualize
method_names (list of str) – List of method names for the relevance maps
figsize (tuple, optional) – Figure size for the visualization
cmap (str, optional) – Colormap to use
- Returns:
Matplotlib figure
- Return type:
matplotlib.figure.Figure
Common Validation Functions
The validation module contains utility functions for validating inputs and ensuring compatibility between frameworks.
- signxai.common.validation.validate_model(model, backend=None)
Validates that a model is compatible with the specified backend.
- signxai.common.validation.validate_input(input_tensor, model, backend=None)
Validates that an input tensor is compatible with the model and backend.
- Parameters:
input_tensor – The input tensor to validate
model – The model to validate against
backend (str, optional) – The backend to validate against (‘tensorflow’ or ‘pytorch’)
- Returns:
Validated input tensor, possibly converted to the appropriate format
- Raises:
ValueError: If the input tensor is not valid for the model/backend
Framework Detection
The common module provides functions for detecting and handling different frameworks.