diffengine.models.losses.snr_l2_loss¶
Module Contents¶
Classes¶
SNR weighting gamma L2 loss. |
- class diffengine.models.losses.snr_l2_loss.SNRL2Loss(loss_weight=1.0, snr_gamma=5.0, reduction='mean', loss_name='snrl2')[source]¶
Bases:
diffengine.models.losses.base.BaseLossSNR weighting gamma L2 loss.
https://arxiv.org/abs/2303.09556
Args:¶
- loss_weight (float): Weight of this loss item.
Defaults to
1..- snr_gamma (float): SNR weighting gamma to be used if re balancing the
loss. “More details here: https://arxiv.org/abs/2303.09556.” Defaults to
5..- reduction: (str): The reduction method for the loss.
Defaults to ‘mean’.
- loss_name (str, optional): Name of the loss item. If you want this loss
item to be included into the backward graph, loss_ must be the prefix of the name. Defaults to ‘l2’.
- forward(pred, gt, timesteps, alphas_cumprod, prediction_type, weight=None)[source]¶
Forward function.
Args:¶
pred (torch.Tensor): The predicted tensor. gt (torch.Tensor): The ground truth tensor. timesteps (torch.Tensor): The timestep tensor. alphas_cumprod (torch.Tensor): The alphas_cumprod from the
scheduler.
prediction_type (str): The prediction type from scheduler. weight (torch.Tensor | None, optional): The loss weight.
Defaults to None.
Returns:¶
torch.Tensor: loss
- Parameters:
pred (torch.Tensor) –
gt (torch.Tensor) –
timesteps (torch.Tensor) –
alphas_cumprod (torch.Tensor) –
prediction_type (str) –
weight (torch.Tensor | None) –
- Return type:
torch.Tensor
- Parameters:
loss_weight (float) –
snr_gamma (float) –
reduction (str) –
loss_name (str) –