class_docstr: Implement RetinaNet in :paper:`RetinaNet`.
class_docstr_tok: ["Implement","RetinaNet","in",":","paper",":","`","RetinaNet","`","."]
docstr: Single-image inference. Return bounding-box detection results by thresholding
  on scores and applying non-maximum suppression (NMS).
  
  Arguments:
      anchors (list[Boxes]): list of #feature levels. Each entry contains
          a Boxes object, which contains all the anchors in that feature level.
      box_cls (list[Tensor]): list of #feature levels. Each entry contains
          tensor of size (H x W x A, K)
      box_delta (list[Tensor]): Same shape as 'box_cls' except that K becomes 4.
      image_size (tuple(H, W)): a tuple of the image height and width.
  
  Returns:
      Same as `inference`, but for only one image.
docstr_tok: ["Single-image","inference",".","Return","bounding-box","detection","results","by","thresholding","on","scores","and","applying","non-maximum","suppression","(","NMS",")",".","Arguments",":","anchors","(","list","[","Boxes","]",")",":","list","of","#","feature","levels",".","Each","entry","contains","a","Boxes","object",",","which","contains","all","the","anchors","in","that","feature","level",".","box_cls","(","list","[","Tensor","]",")",":","list","of","#","feature","levels",".","Each","entry","contains","tensor","of","size","(","H","x","W","x","A",",","K",")","box_delta","(","list","[","Tensor","]",")",":","Same","shape","as","'box_cls","'","except","that","K","becomes","4.","image_size","(","tuple","(","H",",","W",")",")",":","a","tuple","of","the","image","height","and","width",".","Returns",":","Same","as","`","inference","`",",","but","for","only","one","image","."]
code: def inference_single_image(
      self,
      anchors: List[Boxes],
      box_cls: List[Tensor],
      box_delta: List[Tensor],
      image_size: Tuple[int, int],
  ):
      """
      Single-image inference. Return bounding-box detection results by thresholding
      on scores and applying non-maximum suppression (NMS).
  
      Arguments:
          anchors (list[Boxes]): list of #feature levels. Each entry contains
              a Boxes object, which contains all the anchors in that feature level.
          box_cls (list[Tensor]): list of #feature levels. Each entry contains
              tensor of size (H x W x A, K)
          box_delta (list[Tensor]): Same shape as 'box_cls' except that K becomes 4.
          image_size (tuple(H, W)): a tuple of the image height and width.
  
      Returns:
          Same as `inference`, but for only one image.
      """
      pred = self._decode_multi_level_predictions(
          anchors,
          box_cls,
          box_delta,
          self.test_score_thresh,
          self.test_topk_candidates,
          image_size,
      )
      keep = batched_nms(  # per-class NMS
          pred.pred_boxes.tensor,
          pred.scores,
          pred.pred_classes,
          self.test_nms_thresh,
      )
      return pred[keep[: self.max_detections_per_image]]
  
imports: import logging
  import math
  from typing import List, Tuple
  import torch
  from fvcore.nn import sigmoid_focal_loss_jit
  from torch import Tensor, nn
  from torch.nn import functional
  from detectron2.config import configurable
  from detectron2.layers import CycleBatchNormList, ShapeSpec, batched_nms, cat, get_norm
  from detectron2.structures import Boxes, ImageList, Instances, pairwise_iou
  from detectron2.utils.events import get_event_storage
  from ..anchor_generator import build_anchor_generator
  from ..backbone import Backbone, build_backbone
  from ..box_regression import Box2BoxTransform, _dense_box_regression_loss
  from ..matcher import Matcher
  from .build import META_ARCH_REGISTRY
  from .dense_detector import DenseDetector, permute_to_N_HWA_K
label_desc: Use image node_id 7 for calling the RetinaNet obj's underlying member method code with example usage: obj.inference_single_image(anchors, box_cls, box_delta, image_size) and returns: pred