class_docstr: Inspired by https://github.com/kuangliu/pytorch-src
  Transform between (bboxes, lables) <-> SSD output
  
  dboxes: default boxes in size 8732 x 4,
      encoder: input ltrb format, output xywh format
      decoder: input xywh format, output ltrb format
  
  encode:
      input  : bboxes_in (Tensor nboxes x 4), labels_in (Tensor nboxes)
      output : bboxes_out (Tensor 8732 x 4), labels_out (Tensor 8732)
      criteria : IoU threshold of bboexes
  
  decode:
      input  : bboxes_in (Tensor 8732 x 4), scores_in (Tensor 8732 x nitems)
      output : bboxes_out (Tensor nboxes x 4), labels_out (Tensor nboxes)
      criteria : IoU threshold of bboexes
      max_output : maximum number of output bboxes
docstr: encode:
      input  : bboxes_in (Tensor nboxes x 4), labels_in (Tensor nboxes)
      output : bboxes_out (Tensor 8732 x 4), labels_out (Tensor 8732)
      criteria : IoU threshold of bboexes
docstr_tok: ["encode",":","input",":","bboxes_in","(","Tensor","nboxes","x","4",")",",","labels_in","(","Tensor","nboxes",")","output",":","bboxes_out","(","Tensor","8732","x","4",")",",","labels_out","(","Tensor","8732",")","criteria",":","IoU","threshold","of","bboexes"]
code: def encode(self, bboxes_in, labels_in, criteria=0.5):
      """
      encode:
          input  : bboxes_in (Tensor nboxes x 4), labels_in (Tensor nboxes)
          output : bboxes_out (Tensor 8732 x 4), labels_out (Tensor 8732)
          criteria : IoU threshold of bboexes
      """
      # [nboxes, 8732]
      ious = calc_iou_tensor(
          bboxes_in, self.dboxes
      )  # 计算每个GT与default box的iou
      # [8732,]
      best_dbox_ious, best_dbox_idx = ious.max(
          dim=0
      )  # 寻找每个default box匹配到的最大IoU
      # [nboxes,]
      best_bbox_ious, best_bbox_idx = ious.max(dim=1)  # 寻找每个GT匹配到的最大IoU
  
      # 将每个GT匹配到的最佳default box设置为正样本（对应论文中Matching strategy的第一条）
      # set best ious 2.0
      best_dbox_ious.index_fill_(
          0, best_bbox_idx, 2.0
      )  # dim, index, value
      # 将相应default box匹配最大IOU的GT索引进行替换
      idx = torch.arange(0, best_bbox_idx.size(0), dtype=torch.int64)
      best_dbox_idx[best_bbox_idx[idx]] = idx
  
      # filter IoU > 0.5
      # 寻找与GT iou大于0.5的default box,对应论文中Matching strategy的第二条(这里包括了第一条匹配到的信息)
      masks = best_dbox_ious > criteria
      # [8732,]
      labels_out = torch.zeros(self.nboxes, dtype=torch.int64)
      labels_out[masks] = labels_in[best_dbox_idx[masks]]
      # 将default box匹配到正样本的位置设置成对应GT的box信息
      bboxes_out = self.dboxes.clone()
      bboxes_out[masks, :] = bboxes_in[best_dbox_idx[masks], :]
  
      # Transform format to xywh format
      x = 0.5 * (bboxes_out[:, 0] + bboxes_out[:, 2])  # x
      y = 0.5 * (bboxes_out[:, 1] + bboxes_out[:, 3])  # y
      w = bboxes_out[:, 2] - bboxes_out[:, 0]  # w
      h = bboxes_out[:, 3] - bboxes_out[:, 1]  # h
      bboxes_out[:, 0] = x
      bboxes_out[:, 1] = y
      bboxes_out[:, 2] = w
      bboxes_out[:, 3] = h
      return bboxes_out, labels_out
  
imports: from math import sqrt
  import itertools
  import torch
  import torch.nn.functional
  from torch.jit.annotations import Tuple, List
  from torch import nn, Tensor
  import numpy
label_desc: Use image node_id 2 for calling the Encoder obj's underlying member method code with example usage: obj.encode(bboxes_in, labels_in, criteria) and returns: bboxes_out,  labels_out