class_docstr: Helper handler to log engine's output and/or metrics
class_docstr_tok: ["Helper","handler","to","log","engine","'s","output","and\/or","metrics"]
docstr: Helper method to setup metrics and state attributes to log
docstr_tok: ["Helper","method","to","setup","metrics","and","state","attributes","to","log"]
code: def _setup_output_metrics_state_attrs(
      self,
      engine: Engine,
      log_text: Optional[bool] = False,
      key_tuple: Optional[bool] = True,
  ) -> Dict[Any, Any]:
      """Helper method to setup metrics and state attributes to log"""
      metrics_state_attrs = OrderedDict()
      if self.metric_names is not None:
          if (
              isinstance(self.metric_names, str)
              and self.metric_names == "all"
          ):
              metrics_state_attrs = OrderedDict(engine.state.metrics)
          else:
              for name in self.metric_names:
                  if name not in engine.state.metrics:
                      warnings.warn(
                          f"Provided metric name '{name}' is missing "
                          f"in engine's state metrics: {list(engine.state.metrics.keys())}"
                      )
                      continue
                  metrics_state_attrs[name] = engine.state.metrics[name]
  
      if self.output_transform is not None:
          output_dict = self.output_transform(engine.state.output)
  
          if not isinstance(output_dict, dict):
              output_dict = {"output": output_dict}
  
          metrics_state_attrs.update(output_dict)
  
      if self.state_attributes is not None:
          metrics_state_attrs.update(
              {
                  name: getattr(engine.state, name, None)
                  for name in self.state_attributes
              }
          )
  
      metrics_state_attrs_dict: Dict[
          Any, Union[str, float, numbers.Number]
      ] = OrderedDict()
  
      def key_tuple_tf(
          tag: str, name: str, *args: str
      ) -> Tuple[str, ...]:
          return (tag, name) + args
  
      def key_str_tf(tag: str, name: str, *args: str) -> str:
          return "/".join((tag, name) + args)
  
      key_tf = key_tuple_tf if key_tuple else key_str_tf
  
      for name, value in metrics_state_attrs.items():
          if isinstance(value, numbers.Number):
              metrics_state_attrs_dict[key_tf(self.tag, name)] = value
          elif (
              isinstance(value, torch.Tensor)
              and value.ndimension() == 0
          ):
              metrics_state_attrs_dict[
                  key_tf(self.tag, name)
              ] = value.item()
          elif (
              isinstance(value, torch.Tensor)
              and value.ndimension() == 1
          ):
              for i, v in enumerate(value):
                  metrics_state_attrs_dict[
                      key_tf(self.tag, name, str(i))
                  ] = v.item()
          else:
              if isinstance(value, str) and log_text:
                  metrics_state_attrs_dict[
                      key_tf(self.tag, name)
                  ] = value
              else:
                  warnings.warn(
                      f"Logger output_handler can not log metrics value type {type(value)}"
                  )
      return metrics_state_attrs_dict
  
imports: import numbers
  import warnings
  from abc import ABCMeta, abstractmethod
  from collections import OrderedDict
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  import torch.nn
  from torch.optim import Optimizer
  from ignite.engine import Engine, Events, EventsList, State
  from ignite.engine.events import CallableEventWithFilter, RemovableEventHandle
label_desc: Use image node_id 2 for calling the BaseOutputHandler obj's underlying member method code with example usage: obj._setup_output_metrics_state_attrs(engine, log_text, key_tuple) and returns: metrics_state_attrs_dict, unknown, str