class_docstr: This class implements a model-specific object detector using DEtection TRansformer (DETR)
  and PyTorch following the input and output formats of torchvision.
class_docstr_tok: ["This","class","implements","a","model-specific","object","detector","using","DEtection","TRansformer","(","DETR",")","and","PyTorch","following","the","input","and","output","formats","of","torchvision","."]
docstr: Perform prediction for a batch of inputs.
  
  :param x: Samples of shape (nb_samples, height, width, nb_channels).
  :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 or each prediction.
docstr_tok: ["Perform","prediction","for","a","batch","of","inputs",".",":","param","x",":","Samples","of","shape","(","nb_samples",",","height",",","width",",","nb_channels",")",".",":","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","or","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 (nb_samples, height, width, nb_channels).
      :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 or each prediction.
      """
      import torch
      from art.estimators.object_detection.detr import rescale_bboxes
  
      self._model.eval()
      x_resized, _ = self._apply_resizing(x)
  
      x_preprocessed, _ = self._apply_preprocessing(
          x_resized, y=None, fit=False
      )
  
      if self.clip_values is not None:
          norm_factor = self.clip_values[1]
      else:
          norm_factor = 1.0
  
      x_preprocessed_tensor = torch.from_numpy(x_preprocessed).to(
          self.device
      )
      x_preprocessed_tensor /= norm_factor
  
      model_output = self._model(x_preprocessed_tensor)
  
      predictions: List[Dict[str, np.ndarray]] = []
      for i in range(x_preprocessed_tensor.shape[0]):
          predictions.append(
              {
                  "boxes": rescale_bboxes(
                      model_output["pred_boxes"][i, :, :].cpu(),
                      (self._input_shape[2], self._input_shape[1]),
                  )
                  .detach()
                  .numpy(),
                  "labels": model_output["pred_logits"][i, :, :]
                  .unsqueeze(0)
                  .softmax(-1)[0, :, :-1]
                  .max(dim=1)[1]
                  .detach()
                  .cpu()
                  .numpy(),
                  "scores": model_output["pred_logits"][i, :, :]
                  .unsqueeze(0)
                  .softmax(-1)[0, :, :-1]
                  .max(dim=1)[0]
                  .detach()
                  .cpu()
                  .numpy(),
              }
          )
      return predictions
  
file_path: adversarial-robustness-toolbox/art/estimators/object_detection/pytorch_detection_transformer.py
imports: import logging
  from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union, Any
  import numpy
  from art.estimators.object_detection.object_detector import ObjectDetectorMixin
  from art.estimators.pytorch import PyTorchEstimator
label_desc: Use image node_id 5 for calling the PyTorchDetectionTransformer obj's underlying member method code with example usage: obj.predict(x, batch_size) and returns: predictions