class_docstr: This module implements the model- and task specific estimator for YOLO v3, v5 object detector models in PyTorch.
  
  | Paper link: https://arxiv.org/abs/1804.02767
class_docstr_tok: ["This","module","implements","the","model-","and","task","specific","estimator","for","YOLO","v3",",","v5","object","detector","models","in","PyTorch",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1804.02767"]
docstr: Get the loss tensor output of the model including all preprocessing.
  
  :param x: Samples of shape NCHW or NHWC.
  :param y: Target values of format `List[Dict[str, Union[np.ndarray, torch.Tensor]]]`, one for each input image.
            The fields of the Dict are as follows:
  
            - boxes [N, 4]: the boxes in [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and 0 <= y1 < y2 <= H.
            - labels [N]: the labels for each image.
  :return: Loss components and gradients of the input `x`.
docstr_tok: ["Get","the","loss","tensor","output","of","the","model","including","all","preprocessing",".",":","param","x",":","Samples","of","shape","NCHW","or","NHWC",".",":","param","y",":","Target","values","of","format","`","List","[","Dict","[","str",",","Union","[","np.ndarray",",","torch.Tensor","]","]","]","`",",","one","for","each","input","image",".","The","fields","of","the","Dict","are","as","follows",":","-","boxes","[","N",",","4","]",":","the","boxes","in","[","x1",",","y1",",","x2",",","y2","]","format",",","with","0","<","=","x1","<","x2","<","=","W","and","0","<","=","y1","<","y2","<","=","H.","-","labels","[","N","]",":","the","labels","for","each","image",".",":","return",":","Loss","components","and","gradients","of","the","input","`","x","`","."]
code: def _get_losses(
      self,
      x: Union[np.ndarray, "torch.Tensor"],
      y: List[Dict[str, Union[np.ndarray, "torch.Tensor"]]],
  ) -> Tuple[Dict[str, "torch.Tensor"], "torch.Tensor"]:
      """
      Get the loss tensor output of the model including all preprocessing.
  
      :param x: Samples of shape NCHW or NHWC.
      :param y: Target values of format `List[Dict[str, Union[np.ndarray, torch.Tensor]]]`, one for each input image.
                The fields of the Dict are as follows:
  
                - boxes [N, 4]: the boxes in [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and 0 <= y1 < y2 <= H.
                - labels [N]: the labels for each image.
      :return: Loss components and gradients of the input `x`.
      """
      self._model.train()
  
      # Apply preprocessing and convert to tensors
      (
          x_preprocessed,
          y_preprocessed,
      ) = self._preprocess_and_convert_inputs(
          x=x, y=y, fit=False, no_grad=False
      )
  
      # Extract height and width
      if self.channels_first:
          height = self.input_shape[1]
          width = self.input_shape[2]
      else:
          height = self.input_shape[0]
          width = self.input_shape[1]
  
      # Convert labels to YOLO format
      y_preprocessed_yolo = translate_labels_x1y1x2y2_to_xcycwh(
          labels_x1y1x2y2=y_preprocessed, height=height, width=width
      )
  
      # Move inputs to device
      x_preprocessed = x_preprocessed.to(self.device)
      y_preprocessed_yolo = y_preprocessed_yolo.to(self.device)
  
      # Set gradients again after inputs are moved to another device
      if x_preprocessed.is_leaf:
          x_preprocessed.requires_grad = True
      else:
          x_preprocessed.retain_grad()
  
      # Calculate loss components
      loss_components = self._model(x_preprocessed, y_preprocessed_yolo)
  
      return loss_components, x_preprocessed
  
imports: import logging
  from typing import List, Dict, Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  from art.estimators.object_detection.object_detector import ObjectDetectorMixin
  from art.estimators.object_detection.utils import cast_inputs_to_pt
  from art.estimators.pytorch import PyTorchEstimator
label_desc: Use image node_id 9 for calling the PyTorchYolo obj's underlying member method code with example usage: obj._get_losses(x, y) and returns: loss_components,  x_preprocessed