code: def check_training_targets(
      input_images: list[Tensor] | Tensor,
      targets: list[dict[str, Tensor]] | None,
      spatial_dims: int,
      target_label_key: str,
      target_box_key: str,
  ) -> list[dict[str, Tensor]]:
      """
      Validate the input images/targets during training (raise a `ValueError` if invalid).
  
      Args:
          input_images: It can be 1) a tensor sized (B, C, H, W) or  (B, C, H, W, D),
              or 2) a list of image tensors, each image i may have different size (C, H_i, W_i) or  (C, H_i, W_i, D_i).
          targets: a list of dict. Each dict with two keys: target_box_key and target_label_key,
              ground-truth boxes present in the image.
          spatial_dims: number of spatial dimensions of the images, 2 or 3.
          target_label_key: the expected key of target labels.
          target_box_key: the expected key of target boxes.
      """
      if targets is None:
          raise ValueError(
              "Please provide ground truth targets during training."
          )
  
      if len(input_images) != len(targets):
          raise ValueError(
              f"len(input_images) should equal to len(targets), got {len(input_images)}, {len(targets)}."
          )
  
      for i in range(len(targets)):
          target = targets[i]
          if (target_label_key not in target.keys()) or (
              target_box_key not in target.keys()
          ):
              raise ValueError(
                  f"{target_label_key} and {target_box_key} are expected keys in targets. Got {target.keys()}."
              )
  
          boxes = target[target_box_key]
          if not isinstance(boxes, torch.Tensor):
              raise ValueError(
                  f"Expected target boxes to be of type Tensor, got {type(boxes)}."
              )
          if (
              len(boxes.shape) != 2
              or boxes.shape[-1] != 2 * spatial_dims
          ):
              if boxes.numel() == 0:
                  warnings.warn(
                      f"Warning: Given target boxes has shape of {boxes.shape}. "
                      f"The detector reshaped it with boxes = torch.reshape(boxes, [0, {2* spatial_dims}])."
                  )
              else:
                  raise ValueError(
                      f"Expected target boxes to be a tensor of shape [N, {2* spatial_dims}], got {boxes.shape}.)."
                  )
          if not torch.is_floating_point(boxes):
              raise ValueError(
                  f"Expected target boxes to be a float tensor, got {boxes.dtype}."
              )
          targets[i][target_box_key] = standardize_empty_box(boxes, spatial_dims=spatial_dims)  # type: ignore
  
          labels = target[target_label_key]
          if torch.is_floating_point(labels):
              warnings.warn(
                  f"Warning: Given target labels is {labels.dtype}. The detector converted it to torch.long."
              )
              targets[i][target_label_key] = labels.long()
      return targets
  
file_path: MONAI/monai/apps/detection/utils/detector_utils.py
imports: from __future__ import annotations
  import warnings
  from collections.abc import Sequence
  from typing import Any
  import torch
  import torch.nn.functional
  from torch import Tensor
  from monai.data.box_utils import standardize_empty_box
  from monai.transforms.croppad.array import SpatialPad
  from monai.transforms.utils import compute_divisible_spatial_size, convert_pad_mode
  from monai.utils import PytorchPadMode, ensure_tuple_rep
label_desc: Use image node_id 2 for calling a global function with example usage: check_training_targets(input_images, targets, spatial_dims, target_label_key, target_box_key) and returns: targets