class_docstr: This class implements a `Single Shot Object Detector <https://arxiv.org/abs/1512.02325>`_
  
  Args:
      opts: command-line arguments
      encoder (BaseImageEncoder): Encoder network (e.g., ResNet or MobileViT)
class_docstr_tok: ["This","class","implements","a","`","Single","Shot","Object","Detector","<","https",":","\/\/arxiv.org\/abs\/1512.02325",">","`","_","Args",":","opts",":","command-line","arguments","encoder","(","BaseImageEncoder",")",":","Encoder","network","(","e.g.",",","ResNet","or","MobileViT",")"]
docstr: Post process detections, including NMS
docstr_tok: ["Post","process","detections",",","including","NMS"]
code: def postprocess_detections(
      self, boxes: Tensor, scores: Tensor
  ) -> List[DetectionPredTuple]:
      """Post process detections, including NMS"""
      # boxes [B, N, 4]
      # scores [B, N]
      # labels [B, N]
  
      batch_size = boxes.shape[0]
      n_classes = scores.shape[-1]
  
      device = boxes.device
      box_dtype = boxes.dtype
      scores_dtype = scores.dtype
  
      results = []
      for b_id in range(batch_size):
          object_labels = []
          object_boxes = []
          object_scores = []
  
          for class_index in range(1, n_classes):
              probs = scores[b_id, :, class_index]
              mask = probs > self.conf_threshold
              probs = probs[mask]
              if probs.size(0) == 0:
                  continue
              masked_boxes = boxes[b_id, mask, :]
  
              # keep only top-k indices
              num_topk = min(self.top_k, probs.size(0))
              probs, idxs = probs.topk(num_topk)
              masked_boxes = masked_boxes[idxs, ...]
  
              object_boxes.append(masked_boxes)
              object_scores.append(probs)
              object_labels.append(
                  torch.full_like(
                      probs,
                      fill_value=class_index,
                      dtype=torch.int64,
                      device=device,
                  )
              )
  
          if len(object_scores) == 0:
              output = DetectionPredTuple(
                  labels=torch.empty(
                      0, device=device, dtype=torch.long
                  ),
                  scores=torch.empty(
                      0, device=device, dtype=scores_dtype
                  ),
                  boxes=torch.empty(
                      0, 4, device=device, dtype=box_dtype
                  ),
              )
          else:
              # concatenate all results
              object_scores = torch.cat(object_scores, dim=0)
              object_boxes = torch.cat(object_boxes, dim=0)
              object_labels = torch.cat(object_labels, dim=0)
  
              # non-maximum suppression
              keep = batched_nms(
                  object_boxes,
                  object_scores,
                  object_labels,
                  self.nms_threshold,
              )
              keep = keep[: self.objects_per_image]
  
              output = DetectionPredTuple(
                  labels=object_labels[keep],
                  scores=object_scores[keep],
                  boxes=object_boxes[keep],
              )
          results.append(output)
      return results
  
imports: import argparse
  import math
  from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  from torch import Tensor, nn
  from torchvision.ops import batched_nms
  from cvnets.anchor_generator import build_anchor_generator
  from cvnets.layers import AdaptiveAvgPool2d, ConvLayer2d, SeparableConv2d
  from cvnets.matcher_det import build_matcher
  from cvnets.misc.init_utils import initialize_conv_layer
  from cvnets.models import MODEL_REGISTRY
  from cvnets.models.classification.base_image_encoder import BaseImageEncoder
  from cvnets.models.detection import DetectionPredTuple
  from cvnets.models.detection.base_detection import BaseDetection
  from cvnets.modules import SSDHead
  from utils import logger
  from utils.common_utils import is_coreml_conversion
label_desc: Use image node_id 9 for calling the SingleShotMaskDetector obj's underlying member method code with example usage: obj.postprocess_detections(boxes, scores) and returns: results