module

GS::Loss

Constants

SSIM_C1 = 0.01_f32 ** 2

Constants for SSIM

SSIM_C2 = 0.03_f32 ** 2

Instance methods

combined(pred : Tensor, target : Tensor, lambda_ssim : Float32 = 0.2_f32) : Float32
Source
combined_with_grad(pred : Tensor, target : Tensor, lambda_ssim : Float32 = 0.2_f32) : Tuple(Float32, Tensor)
Source
l1(pred : Tensor, target : Tensor) : Float32
Source
l1_with_grad(pred : Tensor, target : Tensor) : Tuple(Float32, Tensor)

L1 loss with gradient

Source
mse(pred : Tensor, target : Tensor) : Float32
Source
mse_with_grad(pred : Tensor, target : Tensor) : Tuple(Float32, Tensor)
Source
psnr(pred : Tensor, target : Tensor, max_val : Float32 = 1.0_f32) : Float32
Source
ssim(pred : Tensor, target : Tensor, window_size : Int32 = 11) : Float32

Compute SSIM between two images Input: [H, W, C] tensors

Source
ssim_loss(pred : Tensor, target : Tensor, window_size : Int32 = 11) : Float32

SSIM loss (1 - SSIM, so lower is better)

Source
ssim_loss_with_grad(pred : Tensor, target : Tensor, window_size : Int32 = 11) : Tuple(Float32, Tensor)

SSIM with gradient (approximate - using finite differences for now)

Source