code: def _parse_losses(losses: Dict[str, Tensor]) -> Dict[str, Tensor]:
      log_vars = OrderedDict()
      for loss_name, loss_value in losses.items():
          if isinstance(loss_value, torch.Tensor):
              log_vars[loss_name] = loss_value.mean()
          elif isinstance(loss_value, list):
              log_vars[loss_name] = sum(
                  _loss.mean() for _loss in loss_value
              )
          else:
              raise TypeError(
                  f"{loss_name} is not a tensor or list of tensors"
              )
  
          if "loss" not in loss_name:
              # put metrics to storage; don't return them
              storage = get_event_storage()
              value = log_vars.pop(loss_name).cpu().item()
              storage.put_scalar(loss_name, value)
      return log_vars
  
imports: import itertools
  import logging
  import numpy
  from collections import OrderedDict
  from collections.abc import Mapping
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from omegaconf import DictConfig, OmegaConf
  from torch import Tensor, nn
  from detectron2.layers import ShapeSpec
  from detectron2.structures import BitMasks, Boxes, ImageList, Instances
  from detectron2.utils.events import get_event_storage
  from .backbone import Backbone
label_desc: Use image node_id 3 for calling a global function with example usage: _parse_losses(losses) and returns: log_vars