Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion monai/losses/barlow_twins.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BarlowTwinsLoss(_Loss):
def __init__(self, lambd: float = 5e-3) -> None:
"""
Args:
lamb: Can be any float to handle the informativeness and invariance trade-off. Ideally set to 5e-3.
lambd: Can be any float to handle the informativeness and invariance trade-off. Ideally set to 5e-3.

Raises:
ValueError: When an input of dimension length > 2 is passed
Expand Down
11 changes: 11 additions & 0 deletions monai/losses/ds_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ def get_loss(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
return self.loss(input, target) # type: ignore[no-any-return]

def forward(self, input: None | torch.Tensor | list[torch.Tensor], target: torch.Tensor) -> torch.Tensor:
"""
Args:
input: a single tensor or a list of tensors from deeply supervised network outputs.
target: the target tensor.

Returns:
torch.Tensor: the computed deep supervision loss.

Raises:
ValueError: if ``input`` is None.
"""
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if isinstance(input, (list, tuple)):
weights = self.get_weights(levels=len(input))
loss = torch.tensor(0, dtype=torch.float, device=target.device)
Expand Down
10 changes: 8 additions & 2 deletions monai/losses/multi_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ def __init__(
) -> None:
"""
Args:
loss: loss function to be wrapped
loss: loss function to be wrapped.
scales: list of scalars or None, if None, do not apply any scaling.
kernel: gaussian or cauchy.
kernel: type of smoothing kernel, either ``"gaussian"`` or ``"cauchy"``. Defaults to ``"gaussian"``.
reduction: specifies the reduction to apply to the output:
``"none"`` | ``"mean"`` | ``"sum"``. Defaults to ``"mean"``.

Raises:
ValueError: if ``kernel`` is not ``"gaussian"`` or ``"cauchy"``.
ValueError: if ``reduction`` is not ``"mean"``, ``"sum"``, or ``"none"``.
"""
Comment thread
coderabbitai[bot] marked this conversation as resolved.
super().__init__(reduction=LossReduction(reduction).value)
if kernel not in kernel_fn_dict:
Expand Down
12 changes: 9 additions & 3 deletions monai/losses/nacl_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ def __init__(
classes: number of classes
dim: dimension of data (supports 2d and 3d)
kernel_size: size of the spatial kernel
distance_type: l1/l2 distance between spatial kernel and predicted logits
alpha: weightage between cross entropy and logit constraint
sigma: sigma of gaussian
kernel_ops: type of spatial kernel, either ``"mean"`` or ``"gaussian"``. Defaults to ``"mean"``.
distance_type: l1/l2 distance between spatial kernel and predicted logits. Defaults to ``"l1"``.
alpha: weightage between cross entropy and logit constraint. Defaults to 0.1.
sigma: sigma of gaussian filter, used when ``kernel_ops="gaussian"``. Defaults to 1.0.

Raises:
ValueError: if ``kernel_ops`` is not ``"mean"`` or ``"gaussian"``.
ValueError: if ``dim`` is not 2 or 3.
ValueError: if ``distance_type`` is not ``"l1"`` or ``"l2"``.
"""

super().__init__()
Expand Down
6 changes: 6 additions & 0 deletions monai/losses/perceptual.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class PerceptualLoss(nn.Module):
Defaults to `None`.
channel_wise: if True, the loss is returned per channel. Otherwise the loss is averaged over the channels.
Defaults to ``False``.

Raises:
NotImplementedError: if ``spatial_dims`` is not 2 or 3.
ValueError: if a MedicalNet network is used with ``spatial_dims=2`` or ``is_fake_3d=True``.
ValueError: if ``channel_wise=True`` is used with a non-MedicalNet network.
ValueError: if ``network_type`` is not one of the supported options.
"""

def __init__(
Expand Down
Loading