peal.global_utils.DINOEvaluator¶
- class peal.global_utils.DINOEvaluator[source]¶
Bases:
objectDistribution metrics computed in a DINOv2 feature space.
Instead of the usual Inception features, the CLS embedding of a DINOv2 model is used, which is cheap to run locally and works on non-natural images as well. After
fit()has stored mean and covariance of a reference (real) distribution, the evaluator provides a FID-style score for a set of generated images, a per-sample Mahalanobis distance that says how far one counterfactual left the data manifold, and a LPIPS-style cosine distance between two batches.- Parameters:
- Variables:
Methods
Calculates FID score between the fitted real distribution and the provided fake inputs.
Calculates Mahalanobis distance for specific samples against the real distribution.
Step 1: Precompute statistics for the Real (Training) distribution.
- __init__(model_name='facebook/dinov2-small', device='cuda')[source]¶
Load the DINOv2 backbone and its processor in eval mode.
- fit(real_dataloader, save_path=None)[source]¶
Step 1: Precompute statistics for the Real (Training) distribution. Run this once at the beginning. The fitted state is written to
save_pathonly when one is given; the old default, a relativedino_evaluation_state.pt, landed in the working directory (the read-only checkout in the web demo container).
- compute_fid(fake_inputs)[source]¶
Calculates FID score between the fitted real distribution and the provided fake inputs.
- compute_mahalanobis(single_image_or_batch)[source]¶
Calculates Mahalanobis distance for specific samples against the real distribution. Returns a tensor of distances (one per image).
- compute_lpips(x1, x2)¶
Calculates LPIPS perceptual distance using DINOv2 feature representations between two image batches x1 and x2.