class_docstr: A wrapper to make ``loss_fn`` available as a cumulative metric. That is, the loss values computed from
  mini-batches can be combined in the ``reduction`` mode across multiple iterations, as a quantitative measurement
  of a model.
  
  Example:
  
  .. code-block:: python
  
      import torch
      from monai.losses import DiceLoss
      from monai.metrics import LossMetric
  
      dice_loss = DiceLoss(include_background=True)
      loss_metric = LossMetric(loss_fn=dice_loss)
  
      # first iteration
      y_pred = torch.tensor([[[[1.0, 0.0], [0.0, 1.0]]]])  # shape [batch=1, channel=1, 2, 2]
      y = torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]])  # shape [batch=1, channel=1, 2, 2]
      loss_metric(y_pred, y)
  
      # second iteration
      y_pred = torch.tensor([[[[1.0, 0.0], [0.0, 0.0]]]])  # shape [batch=1, channel=1, 2, 2]
      y = torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]])  # shape [batch=1, channel=1, 2, 2]
      loss_metric(y_pred, y)
  
      # aggregate
      print(loss_metric.aggregate(reduction="none"))  # tensor([[0.2000], [0.5000]]) (shape [batch=2, channel=1])
  
      # reset
      loss_metric.reset()
      print(loss_metric.aggregate())
  
  
  Args:
      loss_fn: a callable function that takes ``y_pred`` and optionally ``y`` as input (in the "batch-first" format),
          returns a "batch-first" tensor of loss values.
      reduction: define mode of reduction to the metrics, will only apply reduction on `not-nan` values,
          available reduction modes: {``"none"``, ``"mean"``, ``"sum"``, ``"mean_batch"``, ``"sum_batch"``,
          ``"mean_channel"``, ``"sum_channel"``}, default to ``"mean"``. if "none", will not do reduction.
      get_not_nans: whether to return the `not_nans` count, if True, aggregate() returns (metric, not_nans).
          Here `not_nans` count the number of not nans for the metric, thus its shape equals to the shape of the metric.
class_docstr_tok: ["A","wrapper","to","make","``","loss_fn","``","available","as","a","cumulative","metric",".","That","is",",","the","loss","values","computed","from","mini-batches","can","be","combined","in","the","``","reduction","``","mode","across","multiple","iterations",",","as","a","quantitative","measurement","of","a","model",".","Example",":","..","code-block",":",":","python","import","torch","from","monai.losses","import","DiceLoss","from","monai.metrics","import","LossMetric","dice_loss","=","DiceLoss","(","include_background=True",")","loss_metric","=","LossMetric","(","loss_fn=dice_loss",")","#","first","iteration","y_pred","=","torch.tensor","(","[","[","[","[","1.0",",","0.0","]",",","[","0.0",",","1.0","]","]","]","]",")","#","shape","[","batch=1",",","channel=1",",","2",",","2","]","y","=","torch.tensor","(","[","[","[","[","1.0",",","0.0","]",",","[","1.0",",","1.0","]","]","]","]",")","#","shape","[","batch=1",",","channel=1",",","2",",","2","]","loss_metric","(","y_pred",",","y",")","#","second","iteration","y_pred","=","torch.tensor","(","[","[","[","[","1.0",",","0.0","]",",","[","0.0",",","0.0","]","]","]","]",")","#","shape","[","batch=1",",","channel=1",",","2",",","2","]","y","=","torch.tensor","(","[","[","[","[","1.0",",","0.0","]",",","[","1.0",",","1.0","]","]","]","]",")","#","shape","[","batch=1",",","channel=1",",","2",",","2","]","loss_metric","(","y_pred",",","y",")","#","aggregate","print","(","loss_metric.aggregate","(","reduction=","''","none","''",")",")","#","tensor","(","[","[","0.2000","]",",","[","0.5000","]","]",")","(","shape","[","batch=2",",","channel=1","]",")","#","reset","loss_metric.reset","(",")","print","(","loss_metric.aggregate","(",")",")","Args",":","loss_fn",":","a","callable","function","that","takes","``","y_pred","``","and","optionally","``","y","``","as","input","(","in","the","``","batch-first","''","format",")",",","returns","a","``","batch-first","''","tensor","of","loss","values",".","reduction",":","define","mode","of","reduction","to","the","metrics",",","will","only","apply","reduction","on","`","not-nan","`","values",",","available","reduction","modes",":","{","``","``","none","''","``",",","``","``","mean","''","``",",","``","``","sum","''","``",",","``","``","mean_batch","''","``",",","``","``","sum_batch","''","``",",","``","``","mean_channel","''","``",",","``","``","sum_channel","''","``","}",",","default","to","``","``","mean","''","``",".","if","``","none","''",",","will","not","do","reduction",".","get_not_nans",":","whether","to","return","the","`","not_nans","`","count",",","if","True",",","aggregate","(",")","returns","(","metric",",","not_nans",")",".","Here","`","not_nans","`","count","the","number","of","not","nans","for","the","metric",",","thus","its","shape","equals","to","the","shape","of","the","metric","."]
code: def __init__(
      self,
      loss_fn: _Loss,
      reduction: MetricReduction | str = MetricReduction.MEAN,
      get_not_nans: bool = False,
  ) -> None:
      super().__init__()
      self.loss_fn = loss_fn
      self.reduction = reduction
      self.get_not_nans = get_not_nans
  
file_path: MONAI/monai/metrics/loss_metric.py
imports: from __future__ import annotations
  from typing import Any
  import torch
  from torch.nn.modules.loss import _Loss
  from monai.metrics.utils import do_metric_reduction
  from monai.utils import MetricReduction
  from ..config import TensorOrList
  from .metric import CumulativeIterationMetric
label_desc: Use image node_id 1 to create a new LossMetric object from inherited base classes: CumulativeIterationMetric with example: obj = LossMetric(loss_fn, reduction, get_not_nans)