code: def encode_bbox_target(boxes, anchors):
      """
      Args:
          boxes: (..., 4), float32
          anchors: (..., 4), float32
  
      Returns:
          box_encoded: (..., 4), float32 with the same shape.
      """
      anchors_x1y1x2y2 = tf.reshape(anchors, (-1, 2, 2))
      anchors_x1y1, anchors_x2y2 = tf.split(anchors_x1y1x2y2, 2, axis=1)
      waha = anchors_x2y2 - anchors_x1y1
      xaya = (anchors_x2y2 + anchors_x1y1) * 0.5
  
      boxes_x1y1x2y2 = tf.reshape(boxes, (-1, 2, 2))
      boxes_x1y1, boxes_x2y2 = tf.split(boxes_x1y1x2y2, 2, axis=1)
      wbhb = boxes_x2y2 - boxes_x1y1
      xbyb = (boxes_x2y2 + boxes_x1y1) * 0.5
  
      # Note that here not all boxes are valid. Some may be zero
      txty = (xbyb - xaya) / waha
      twth = tf.math.log(
          wbhb / waha
      )  # may contain -inf for invalid boxes
      encoded = tf.concat([txty, twth], axis=1)  # (-1x2x2)
      return tf.reshape(encoded, tf.shape(boxes))
  
file_path: tensorpack/examples/FasterRCNN/modeling/model_box.py
imports: import numpy
  import tensorflow
  from collections import namedtuple
  from tensorpack.tfutils.scope_utils import under_name_scope
  from config import config
label_desc: Use image node_id 3 for calling a global function with example usage: encode_bbox_target(boxes, anchors) and returns: tf