class_docstr: Class for metrics that should be computed on the entire output history of a model.
  Model's output and targets are restricted to be of shape ``(batch_size, n_targets)``. Output
  datatype should be `float32`. Target datatype should be `long` for classification and `float` for regression.
  
  .. warning::
  
      Current implementation stores all input data (output and target) in as tensors before computing a metric.
      This can potentially lead to a memory error if the input data is larger than available RAM.
  
      In distributed configuration, all stored data (output and target) is mutually collected across all processes
      using all gather collective operation. This can potentially lead to a memory error.
      Compute method executes ``compute_fn`` on zero rank process only and final result is broadcasted to
      all processes.
  
  - ``update`` must receive output of the form ``(y_pred, y)``.
  
  Args:
      compute_fn: a callable which receives two tensors as the `predictions` and `targets`
          and returns a scalar. Input tensors will be on specified ``device`` (see arg below).
      output_transform: a callable that is used to transform the
          :class:`~ignite.engine.engine.Engine`'s ``process_function``'s output into the
          form expected by the metric. This can be useful if, for example, you have a multi-output model and
          you want to compute the metric with respect to one of the outputs.
      check_compute_fn: if True, ``compute_fn`` is run on the first batch of data to ensure there are no
          issues. If issues exist, user is warned that there might be an issue with the ``compute_fn``.
          Default, True.
      device: optional device specification for internal storage.
  
  Example:
  
      For more information on how metric works with :class:`~ignite.engine.engine.Engine`, visit :ref:`attach-engine`.
  
      .. include:: defaults.rst
          :start-after: :orphan:
  
      .. testcode::
  
          def mse_fn(y_preds, y_targets):
              return torch.mean(((y_preds - y_targets.type_as(y_preds)) ** 2)).item()
  
          metric = EpochMetric(mse_fn)
          metric.attach(default_evaluator, "mse")
          y_true = torch.tensor([0, 1, 2, 3, 4, 5])
          y_pred = y_true * 0.75
          state = default_evaluator.run([[y_pred, y_true]])
          print(state.metrics["mse"])
  
      .. testoutput::
  
          0.5729...
  
  Warnings:
      EpochMetricWarning: User is warned that there are issues with ``compute_fn`` on a batch of data processed.
      To disable the warning, set ``check_compute_fn=False``.
class_docstr_tok: ["Class","for","metrics","that","should","be","computed","on","the","entire","output","history","of","a","model",".","Model","'s","output","and","targets","are","restricted","to","be","of","shape","``","(","batch_size",",","n_targets",")","``",".","Output","datatype","should","be","`","float32","`",".","Target","datatype","should","be","`","long","`","for","classification","and","`","float","`","for","regression",".","..","warning",":",":","Current","implementation","stores","all","input","data","(","output","and","target",")","in","as","tensors","before","computing","a","metric",".","This","can","potentially","lead","to","a","memory","error","if","the","input","data","is","larger","than","available","RAM",".","In","distributed","configuration",",","all","stored","data","(","output","and","target",")","is","mutually","collected","across","all","processes","using","all","gather","collective","operation",".","This","can","potentially","lead","to","a","memory","error",".","Compute","method","executes","``","compute_fn","``","on","zero","rank","process","only","and","final","result","is","broadcasted","to","all","processes",".","-","``","update","``","must","receive","output","of","the","form","``","(","y_pred",",","y",")","``",".","Args",":","compute_fn",":","a","callable","which","receives","two","tensors","as","the","`","predictions","`","and","`","targets","`","and","returns","a","scalar",".","Input","tensors","will","be","on","specified","``","device","``","(","see","arg","below",")",".","output_transform",":","a","callable","that","is","used","to","transform","the",":","class",":","`","~ignite.engine.engine.Engine","`","'s","``","process_function","``","'s","output","into","the","form","expected","by","the","metric",".","This","can","be","useful","if",",","for","example",",","you","have","a","multi-output","model","and","you","want","to","compute","the","metric","with","respect","to","one","of","the","outputs",".","check_compute_fn",":","if","True",",","``","compute_fn","``","is","run","on","the","first","batch","of","data","to","ensure","there","are","no","issues",".","If","issues","exist",",","user","is","warned","that","there","might","be","an","issue","with","the","``","compute_fn","``",".","Default",",","True",".","device",":","optional","device","specification","for","internal","storage",".","Example",":","For","more","information","on","how","metric","works","with",":","class",":","`","~ignite.engine.engine.Engine","`",",","visit",":","ref",":","`","attach-engine","`",".","..","include",":",":","defaults.rst",":","start-after",":",":","orphan",":","..","testcode",":",":","def","mse_fn","(","y_preds",",","y_targets",")",":","return","torch.mean","(","(","(","y_preds","-","y_targets.type_as","(","y_preds",")",")","*","*","2",")",")",".item","(",")","metric","=","EpochMetric","(","mse_fn",")","metric.attach","(","default_evaluator",",","``","mse","''",")","y_true","=","torch.tensor","(","[","0",",","1",",","2",",","3",",","4",",","5","]",")","y_pred","=","y_true","*","0.75","state","=","default_evaluator.run","(","[","[","y_pred",",","y_true","]","]",")","print","(","state.metrics","[","``","mse","''","]",")","..","testoutput",":",":","0.5729","...","Warnings",":","EpochMetricWarning",":","User","is","warned","that","there","are","issues","with","``","compute_fn","``","on","a","batch","of","data","processed",".","To","disable","the","warning",",","set","``","check_compute_fn=False","``","."]
code: def __init__(
      self,
      compute_fn: Callable[[torch.Tensor, torch.Tensor], float],
      output_transform: Callable = lambda x: x,
      check_compute_fn: bool = True,
      device: Union[str, torch.device] = torch.device("cpu"),
  ) -> None:
      if not callable(compute_fn):
          raise TypeError("Argument compute_fn should be callable.")
  
      self.compute_fn = compute_fn
      self._check_compute_fn = check_compute_fn
  
      super(EpochMetric, self).__init__(
          output_transform=output_transform, device=device
      )
  
file_path: ignite/ignite/metrics/epoch_metric.py
imports: import warnings
  from typing import Callable, cast, List, Optional, Tuple, Union
  import torch
  import ignite.distributed
  from ignite.exceptions import NotComputableError
  from ignite.metrics.metric import Metric, reinit__is_reduced
label_desc: Use image node_id 1 to create a new EpochMetric object from inherited base classes: Metric with example: obj = EpochMetric(compute_fn, output_transform, check_compute_fn, device)