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: Perform prediction for a batch of inputs.
  
  :param x: Samples of shape NCHW or NHWC.
  :param batch_size: Batch size.
  :return: Predictions of format `List[Dict[str, np.ndarray]]`, 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.
           - scores [N]: the scores of each prediction.
docstr_tok: ["Perform","prediction","for","a","batch","of","inputs",".",":","param","x",":","Samples","of","shape","NCHW","or","NHWC",".",":","param","batch_size",":","Batch","size",".",":","return",":","Predictions","of","format","`","List","[","Dict","[","str",",","np.ndarray","]","]","`",",","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",".","-","scores","[","N","]",":","the","scores","of","each","prediction","."]
code: def predict(
      self, x: np.ndarray, batch_size: int = 128, **kwargs
  ) -> List[Dict[str, np.ndarray]]:
      """
      Perform prediction for a batch of inputs.
  
      :param x: Samples of shape NCHW or NHWC.
      :param batch_size: Batch size.
      :return: Predictions of format `List[Dict[str, np.ndarray]]`, 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.
               - scores [N]: the scores of each prediction.
      """
      import torch
      from torch.utils.data import TensorDataset, DataLoader
  
      # Set model to evaluation mode
      self._model.eval()
  
      # Apply preprocessing and convert to tensors
      x_preprocessed, _ = self._preprocess_and_convert_inputs(
          x=x, y=None, fit=False, no_grad=True
      )
  
      # Create dataloader
      dataset = TensorDataset(x_preprocessed)
      dataloader = DataLoader(
          dataset=dataset, batch_size=batch_size, shuffle=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]
  
      predictions: List[Dict[str, np.ndarray]] = []
      for (x_batch,) in dataloader:
          # Move inputs to device
          x_batch = x_batch.to(self._device)
  
          # Run prediction
          with torch.no_grad():
              predictions_xcycwh = self._model(x_batch)
  
          predictions_x1y1x2y2 = (
              translate_predictions_xcycwh_to_x1y1x2y2(
                  y_pred_xcycwh=predictions_xcycwh,
                  height=height,
                  width=width,
              )
          )
  
          for prediction_x1y1x2y2 in predictions_x1y1x2y2:
              prediction = {}
  
              prediction["boxes"] = (
                  prediction_x1y1x2y2["boxes"].detach().cpu().numpy()
              )
              prediction["labels"] = (
                  prediction_x1y1x2y2["labels"].detach().cpu().numpy()
              )
              prediction["scores"] = (
                  prediction_x1y1x2y2["scores"].detach().cpu().numpy()
              )
              if "masks" in prediction_x1y1x2y2:
                  prediction["masks"] = (
                      prediction_x1y1x2y2["masks"]
                      .detach()
                      .cpu()
                      .numpy()
                      .squeeze()
                  )
  
              predictions.append(prediction)
  
      return predictions
  
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 11 for calling the PyTorchYolo obj's underlying member method code with example usage: obj.predict(x, batch_size) and returns: predictions