peal.global_utils¶
Cross-cutting helpers shared by the whole PEAL library.
Collected here are the utilities that do not belong to one subpackage: yaml
config loading (including the $PEAL_RUNS/$PEAL_DATA/<PEAL_BASE>
placeholders, recursive inclusion of nested yamls and the mapping of a config
onto its pydantic model), argparse integration for those configs, seed handling
and device moves, small module surgery such as replacing ReLUs or resetting
weights, the difference heatmaps and change masks used to visualise
counterfactuals, and a DINOv2-based evaluator for FID, Mahalanobis distance and
a LPIPS-style perceptual distance.
Functions
Add one command line argument per annotated config field. |
|
Print |
|
Creates a bar chart from a dictionary and saves it as a PNG image. |
|
Left-pad a number with zeros so that filenames sort lexicographically. |
|
Return the activation feeding the predictor's last layer. |
|
Import every module under |
|
Visualizes similarity of intermediate features. |
|
Blend the change heatmap onto a washed-out copy of the image. |
|
Highlight structural, rather than pixelwise, change in red. |
|
Find the pydantic config class that a raw config dict describes. |
|
Runs the model on input x and returns the activation tensor. |
|
Predict a whole dataset and write the labels to a csv file. |
|
Return the repository root, i.e. the directory containing |
|
Colour-code the change from an image to its counterfactual. |
|
Write one parsed command line value into a (possibly nested) config. |
|
Apply all parsed command line arguments to a config. |
|
Return |
|
Load a config file (or dict) into its pydantic model. |
|
Clone a tensor, or a list of tensors, onto |
|
One-hot encode a batch of class indices. |
|
Orthogonally initialise all weights and zero all biases. |
|
Copy the top-level seed into every nested config that has one. |
|
Replace every |
|
Replace every |
|
Ask on the console whether a value should be changed. |
|
Set |
|
Re-initialise a model by calling |
|
This function saves a config to a yaml file. |
|
Scale a reference batch size to the current resolution and GPU. |
|
Seed every random source PEAL uses and force deterministic cuDNN. |
|
Computes a simplified Structural Similarity Index Measure (SSIM) map between two images locally. |
Classes
Distribution metrics computed in a DINOv2 feature space. |
|
Smooth, everywhere non-zero gradient replacement for ReLU. |