metrics
This script contains the functions/classes to compute loss and metrics used to train and evaluate the performance of the model.
RunningPSNR
#
This class allows to compute the running PSNR during validation step in training. In this way it is possible to compute the PSNR on the entire validation set one batch at the time.
Source code in src/careamics/lvae_training/metrics.py
get()
#
The get the actual PSNR value given the running statistics.
Source code in src/careamics/lvae_training/metrics.py
reset()
#
Used to reset the running PSNR (usually called at the end of each epoch).
update(rec, tar)
#
Given a batch of reconstructed and target images, it updates the MSE and.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rec | Tensor | Batch of reconstructed images (B, H, W). | required |
tar | Tensor | Batch of target images (B, H, W). | required |
Source code in src/careamics/lvae_training/metrics.py
PSNR(gt, pred, range_=None)
#
Compute PSNR.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt | Ground truth image. | required | |
pred | Predicted image. | required |
Source code in src/careamics/lvae_training/metrics.py
RangeInvariantPsnr(gt, pred)
#
NOTE: Works only for grayscale images. Adapted from https://github.com/juglab/ScaleInvPSNR/blob/master/psnr.py It rescales the prediction to ensure that the prediction has the same range as the ground truth.
Source code in src/careamics/lvae_training/metrics.py
compute_multiscale_ssim(gt_, pred_, range_invariant=True)
#
Computes multiscale ssim for each channel. Args: gt_: ground truth image with shape (N, H, W, C) pred_: predicted image with shape (N, H, W, C) range_invariant: whether to use range invariant multiscale ssim
Source code in src/careamics/lvae_training/metrics.py
range_invariant_multiscale_ssim(gt_, pred_)
#
Computes range invariant multiscale ssim for one channel. This has the benefit that it is invariant to scalar multiplications in the prediction.