class_docstr: The linear box-to-box transform defined in FCOS. The transformation is parameterized
  by the distance from the center of (square) src box to 4 edges of the target box.
class_docstr_tok: ["The","linear","box-to-box","transform","defined","in","FCOS",".","The","transformation","is","parameterized","by","the","distance","from","the","center","of","(","square",")","src","box","to","4","edges","of","the","target","box","."]
docstr: Encode a set of proposals with respect to some reference boxes
  
  Args:
      reference_boxes (Tensor): reference boxes
      proposals (Tensor): boxes to be encoded
  
  Returns:
      Tensor: the encoded relative box offsets that can be used to
      decode the boxes.
docstr_tok: ["Encode","a","set","of","proposals","with","respect","to","some","reference","boxes","Args",":","reference_boxes","(","Tensor",")",":","reference","boxes","proposals","(","Tensor",")",":","boxes","to","be","encoded","Returns",":","Tensor",":","the","encoded","relative","box","offsets","that","can","be","used","to","decode","the","boxes","."]
code: def encode(
      self, reference_boxes: Tensor, proposals: Tensor
  ) -> Tensor:
      """
      Encode a set of proposals with respect to some reference boxes
  
      Args:
          reference_boxes (Tensor): reference boxes
          proposals (Tensor): boxes to be encoded
  
      Returns:
          Tensor: the encoded relative box offsets that can be used to
          decode the boxes.
  
      """
  
      # get the center of reference_boxes
      reference_boxes_ctr_x = 0.5 * (
          reference_boxes[..., 0] + reference_boxes[..., 2]
      )
      reference_boxes_ctr_y = 0.5 * (
          reference_boxes[..., 1] + reference_boxes[..., 3]
      )
  
      # get box regression transformation deltas
      target_l = reference_boxes_ctr_x - proposals[..., 0]
      target_t = reference_boxes_ctr_y - proposals[..., 1]
      target_r = proposals[..., 2] - reference_boxes_ctr_x
      target_b = proposals[..., 3] - reference_boxes_ctr_y
  
      targets = torch.stack(
          (target_l, target_t, target_r, target_b), dim=-1
      )
  
      if self.normalize_by_size:
          reference_boxes_w = (
              reference_boxes[..., 2] - reference_boxes[..., 0]
          )
          reference_boxes_h = (
              reference_boxes[..., 3] - reference_boxes[..., 1]
          )
          reference_boxes_size = torch.stack(
              (
                  reference_boxes_w,
                  reference_boxes_h,
                  reference_boxes_w,
                  reference_boxes_h,
              ),
              dim=-1,
          )
          targets = targets / reference_boxes_size
      return targets
  
imports: import math
  from collections import OrderedDict
  from typing import Dict, List, Optional, Tuple
  import torch
  from torch import nn, Tensor
  from torch.nn import functional
  from torchvision.ops import complete_box_iou_loss, distance_box_iou_loss, FrozenBatchNorm2d, generalized_box_iou_loss
label_desc: Use image node_id 2 for calling the BoxLinearCoder obj's underlying member method code with example usage: obj.encode(reference_boxes, proposals) and returns: targets