code: def transform_prediction(
      pred: torch.Tensor,
      inp_dim: int,
      anchors: Union[List[int], Tuple[int, ...], torch.Tensor],
      num_classes: int,
      device: str = "cpu",
  ) -> torch.Tensor:
      """
      Transforms the predictions of the convolutional layers
      from
          batch_size x (3 * 5+num_classes) x grid_size x grid_size
      to
          batch_size x (grid_size * grid_size * anchors) x num_classes
      aids the concatenation of the prediction at the three detection layers
      and also for easy representation of the predicted bounding boxes.
  
      Also, transforms the bounding box predictions and the objectness score
      to match the discription specified in the paper:
          Bx = sigmoid(Tx) + Cx
          By = sigmoid(Ty) + Cy
          Bw = Pw(exp(Tw))
          Bh = Ph(exp(Th))
  
      Parameters:
      -----------
          pred:           prediction of the convolutional layer
          inp_dim:        the dimension of images expected by the yolo neural network
          anchors:        a list of anchors
          num_classes:    the numbers of unique classes as specified by COCO.
  
      Returns:
      --------
          the transformed input.
      """
      batch_size = pred.shape[0]
      grid_size = pred.shape[2]
      stride = inp_dim // grid_size
      bbox_attrs = 5 + num_classes
      num_anchors = len(anchors)
  
      # transform input shape
      pred = pred.view(
          batch_size, bbox_attrs * num_anchors, grid_size * grid_size
      )
      pred = pred.transpose(1, 2).contiguous()
      pred = pred.view(
          batch_size, grid_size * grid_size * num_anchors, bbox_attrs
      )
  
      # since the dimensions of the anchors are in accordance with the original
      # dimension of the image, it's required to scale the dimension of the
      # anchors to match the dimension of the output of the convolutional
      # layer
      anchors = [(a[0] / stride, a[1] / stride) for a in anchors]
  
      # sigmoid the center_x, center_y and the objectness score
      pred[:, :, 0] = torch.sigmoid(pred[:, :, 0])
      pred[:, :, 1] = torch.sigmoid(pred[:, :, 1])
      pred[:, :, 4] = torch.sigmoid(pred[:, :, 4])
  
      # add the center offsets
      grid = torch.arange(grid_size, dtype=torch.float)
      grid = np.arange(grid_size)
      x_o, y_o = np.meshgrid(grid, grid)
      # x_offset, y_offset = torch.meshgrid(grid, grid)
  
      x_offset = torch.FloatTensor(x_o).view(-1, 1).to(device)
      y_offset = torch.FloatTensor(y_o).view(-1, 1).to(device)
      # x_offset = x_offset.transpose(0,1).reshape(-1,1).to(device)
      # y_offset = y_offset.transpose(0,1).reshape(-1,1).to(device)
  
      x_y_offset = (
          torch.cat([x_offset, y_offset], dim=1)
          .repeat(1, num_anchors)
          .view(-1, 2)
          .unsqueeze(0)
      )
      pred[:, :, :2] += x_y_offset
  
      # transform height and width
      anchors = torch.FloatTensor(anchors).to(device)
      anchors = anchors.repeat(grid_size * grid_size, 1).unsqueeze(0)
      pred[:, :, 2:4] = torch.exp(pred[:, :, 2:4]) * anchors
  
      # apply sigmoid to class scores
      pred[:, :, 5 : 5 + num_classes] = torch.sigmoid(
          pred[:, :, 5 : 5 + num_classes]
      )
  
      # resize bounding box prediction to the original image dimension
      pred[:, :, :4] *= stride
  
      return pred
  
file_path: ImageAI/imageai/yolov3/utils.py
imports: import math
  from typing import Union, List, Tuple
  import torch
  import numpy
  import cv2
  from torchvision.ops import batched_nms
label_desc: Use image node_id 5 for calling a global function with example usage: transform_prediction(pred, inp_dim, anchors, num_classes, device) and returns: pred