class_docstr: Add an additional `masking` process before `DiceLoss`, accept a binary mask ([0, 1]) indicating a region,
  `input` and `target` will be masked by the region: region with mask `1` will keep the original value,
  region with `0` mask will be converted to `0`. Then feed `input` and `target` to normal `DiceLoss` computation.
  This has the effect of ensuring only the masked region contributes to the loss computation and
  hence gradient calculation.
class_docstr_tok: ["Add","an","additional","`","masking","`","process","before","`","DiceLoss","`",",","accept","a","binary","mask","(","[","0",",","1","]",")","indicating","a","region",",","`","input","`","and","`","target","`","will","be","masked","by","the","region",":","region","with","mask","`","1","`","will","keep","the","original","value",",","region","with","`","0","`","mask","will","be","converted","to","`","0","`",".","Then","feed","`","input","`","and","`","target","`","to","normal","`","DiceLoss","`","computation",".","This","has","the","effect","of","ensuring","only","the","masked","region","contributes","to","the","loss","computation","and","hence","gradient","calculation","."]
docstr: Args:
      input: the shape should be BNH[WD].
      target: the shape should be BNH[WD].
      mask: the shape should B1H[WD] or 11H[WD].
docstr_tok: ["Args",":","input",":","the","shape","should","be","BNH","[","WD","]",".","target",":","the","shape","should","be","BNH","[","WD","]",".","mask",":","the","shape","should","B1H","[","WD","]","or","11H","[","WD","]","."]
code: def forward(
      self,
      input: torch.Tensor,
      target: torch.Tensor,
      mask: torch.Tensor | None = None,
  ) -> torch.Tensor:
      """
      Args:
          input: the shape should be BNH[WD].
          target: the shape should be BNH[WD].
          mask: the shape should B1H[WD] or 11H[WD].
      """
      return self.spatial_weighted(
          input=input, target=target, mask=mask
      )
  
imports: from __future__ import annotations
  import warnings
  from collections.abc import Callable, Sequence
  from typing import Any
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.modules.loss import _Loss
  from monai.losses.focal_loss import FocalLoss
  from monai.losses.spatial_mask import MaskedLoss
  from monai.networks import one_hot
  from monai.utils import DiceCEReduction, LossReduction, Weight, deprecated_arg, look_up_option, pytorch_after
label_desc: Use image node_id 2 for calling the MaskedDiceLoss obj's underlying member method code with example usage: obj.forward(input, target, mask) and returns: self