class_docstr: This module implements the task- and model-specific estimator for PyTorch GOTURN (object tracking).
class_docstr_tok: ["This","module","implements","the","task-","and","model-specific","estimator","for","PyTorch","GOTURN","(","object","tracking",")","."]
docstr: Perform prediction for a batch of inputs.
  
  :param x: Samples of shape (nb_samples, nb_frames, height, width, nb_channels).
  :param batch_size: Batch size.
  
  :Keyword Arguments:
      * *y_init* (``np.ndarray``) --
        Initial box around object to be tracked as [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and
        0 <= y1 < y2 <= H.
  
  :return: Predictions of format `List[Dict[str, np.ndarray]]`, one dictionary for each input image. The keys of
           the dictionary are:
  
            - boxes [N_FRAMES, 4]: the boxes in [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and
                                   0 <= y1 < y2 <= H.
            - labels [N_FRAMES]: the labels for each image, default 0.
            - scores [N_FRAMES]: the scores or each prediction, default 1.
docstr_tok: ["Perform","prediction","for","a","batch","of","inputs",".",":","param","x",":","Samples","of","shape","(","nb_samples",",","nb_frames",",","height",",","width",",","nb_channels",")",".",":","param","batch_size",":","Batch","size",".",":","Keyword","Arguments",":","*","*","y_init","*","(","``","np.ndarray","``",")","--","Initial","box","around","object","to","be","tracked","as","[","x1",",","y1",",","x2",",","y2","]","format",",","with","0","<","=","x1","<","x2","<","=","W","and","0","<","=","y1","<","y2","<","=","H.",":","return",":","Predictions","of","format","`","List","[","Dict","[","str",",","np.ndarray","]","]","`",",","one","dictionary","for","each","input","image",".","The","keys","of","the","dictionary","are",":","-","boxes","[","N_FRAMES",",","4","]",":","the","boxes","in","[","x1",",","y1",",","x2",",","y2","]","format",",","with","0","<","=","x1","<","x2","<","=","W","and","0","<","=","y1","<","y2","<","=","H.","-","labels","[","N_FRAMES","]",":","the","labels","for","each","image",",","default","0",".","-","scores","[","N_FRAMES","]",":","the","scores","or","each","prediction",",","default","1","."]
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 (nb_samples, nb_frames, height, width, nb_channels).
      :param batch_size: Batch size.
  
      :Keyword Arguments:
          * *y_init* (``np.ndarray``) --
            Initial box around object to be tracked as [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and
            0 <= y1 < y2 <= H.
  
      :return: Predictions of format `List[Dict[str, np.ndarray]]`, one dictionary for each input image. The keys of
               the dictionary are:
  
                - boxes [N_FRAMES, 4]: the boxes in [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and
                                       0 <= y1 < y2 <= H.
                - labels [N_FRAMES]: the labels for each image, default 0.
                - scores [N_FRAMES]: the scores or each prediction, default 1.
      """
      import torch
  
      self._model.eval()
      if hasattr(self._model, "freeze"):
          self._model.freeze()
  
      y_init = kwargs.get("y_init")
      if y_init is None:  # pragma: no cover
          raise ValueError(
              "y_init is a required argument for method `predict`."
          )
  
      if isinstance(y_init, np.ndarray):
          y_init = torch.from_numpy(y_init).to(self.device).float()
      else:
          y_init = y_init.to(self.device).float()
  
      predictions = []
  
      for i in range(x.shape[0]):
          if isinstance(x, np.ndarray):
              x_i = torch.from_numpy(x[i]).to(self.device)
          else:
              x_i = x[i].to(self.device)
  
          # Apply preprocessing
          x_i = torch.unsqueeze(x_i, dim=0)
          x_i, _ = self._apply_preprocessing(
              x_i, y=None, fit=False, no_grad=False
          )
          x_i = torch.squeeze(x_i)
  
          y_pred = self._track(x=x_i, y_init=y_init[i])
          prediction_dict = {}
          if isinstance(x, np.ndarray):
              prediction_dict["boxes"] = y_pred.detach().cpu().numpy()
          else:
              prediction_dict["boxes"] = y_pred
          predictions.append(prediction_dict)
  
      return predictions
  
imports: import logging
  import time
  from typing import List, Dict, Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  from art.estimators.object_tracking.object_tracker import ObjectTrackerMixin
  from art.estimators.pytorch import PyTorchEstimator
label_desc: Use image node_id 10 for calling the PyTorchGoturn obj's underlying member method code with example usage: obj.predict(x, batch_size) and returns: predictions