def assign(self,
             pred_boxes,
             gt_boxes,
             pred_classes,
             gt_labels,
             gt_weights=None,
             unmatched_class_label=None):
    """Assign classification and regression targets to each box_pred.

    For a given set of pred_boxes and groundtruth detections, match pred_boxes
    to gt_boxes and assign classification and regression targets to
    each box_pred as well as weights based on the resulting match (specifying,
    e.g., which pred_boxes should not contribute to training loss).

    pred_boxes that are not matched to anything are given a classification
    target of `unmatched_cls_target`.

    Args:
      pred_boxes: a BoxList representing N pred_boxes
      gt_boxes: a BoxList representing M groundtruth boxes
      pred_classes: A tensor with shape [max_num_boxes, num_classes]
        to be used by certain similarity calculators.
      gt_labels:  a tensor of shape [M, num_classes]
        with labels for each of the ground_truth boxes. The subshape
        [num_classes] can be empty (corresponding to scalar inputs).  When set
        to None, gt_labels assumes a binary problem where all
        ground_truth boxes get a positive label (of 1).
      gt_weights: a float tensor of shape [M] indicating the weight to
        assign to all pred_boxes match to a particular groundtruth box. The
        weights must be in [0., 1.]. If None, all weights are set to 1.
        Generally no groundtruth boxes with zero weight match to any pred_boxes
        as matchers are aware of groundtruth weights. Additionally,
        `cls_weights` and `reg_weights` are calculated using groundtruth
        weights as an added safety.
      unmatched_class_label: a float32 tensor with shape [d_1, d_2, ..., d_k]
        which is consistent with the classification target for each
        anchor (and can be empty for scalar targets).  This shape must thus be
        compatible with the groundtruth labels that are passed to the "assign"
        function (which have shape [num_gt_boxes, d_1, d_2, ..., d_k]).

    Returns:
      cls_targets: a float32 tensor with shape [num_pred_boxes, num_classes],
        where the subshape [num_classes] is compatible with gt_labels
        which has shape [num_gt_boxes, num_classes].
      cls_weights: a float32 tensor with shape [num_pred_boxes, num_classes],
        representing weights for each element in cls_targets.
      reg_targets: a float32 tensor with shape [num_pred_boxes,
        box_code_dimension]
      reg_weights: a float32 tensor with shape [num_pred_boxes]

    """
    if not unmatched_class_label:
      unmatched_class_label = tf.constant(
          [1] + [0] * (gt_labels.shape[1] - 1), tf.float32)

    if gt_weights is None:
      num_gt_boxes = gt_boxes.num_boxes_static()
      if not num_gt_boxes:
        num_gt_boxes = gt_boxes.num_boxes()
      gt_weights = tf.ones([num_gt_boxes], dtype=tf.float32)

    gt_boxes.add_field(fields.BoxListFields.classes, gt_labels)
    pred_boxes.add_field(fields.BoxListFields.classes, pred_classes)

    match_quality_matrix = self._similarity_calc.compare(
        gt_boxes,
        pred_boxes)
    match = self._matcher.match(match_quality_matrix,
                                valid_rows=tf.greater(gt_weights, 0))

    matched_gt_boxes = match.gather_based_on_match(
        gt_boxes.get(),
        unmatched_value=tf.zeros(4),
        ignored_value=tf.zeros(4))
    matched_gt_boxlist = box_list.BoxList(matched_gt_boxes)
    ty, tx, th, tw = matched_gt_boxlist.get_center_coordinates_and_sizes()
    reg_targets = tf.transpose(tf.stack([ty, tx, th, tw]))
    cls_targets = match.gather_based_on_match(
        gt_labels,
        unmatched_value=unmatched_class_label,
        ignored_value=unmatched_class_label)
    reg_weights = match.gather_based_on_match(
        gt_weights,
        ignored_value=0.,
        unmatched_value=0.)
    cls_weights = match.gather_based_on_match(
        gt_weights,
        ignored_value=0.,
        unmatched_value=1)

    # convert cls_weights from per-box_pred to per-class.
    class_label_shape = tf.shape(cls_targets)[1:]
    weights_multiple = tf.concat(
        [tf.constant([1]), class_label_shape],
        axis=0)
    cls_weights = tf.expand_dims(cls_weights, -1)
    cls_weights = tf.tile(cls_weights, weights_multiple)

    return (cls_targets, cls_weights, reg_targets, reg_weights)
Assign classification and regression targets to each box_pred.

    For a given set of pred_boxes and groundtruth detections, match pred_boxes
    to gt_boxes and assign classification and regression targets to
    each box_pred as well as weights based on the resulting match (specifying,
    e.g., which pred_boxes should not contribute to training loss).

    pred_boxes that are not matched to anything are given a classification
    target of `unmatched_cls_target`.

    Args:
      pred_boxes: a BoxList representing N pred_boxes
      gt_boxes: a BoxList representing M groundtruth boxes
      pred_classes: A tensor with shape [max_num_boxes, num_classes]
        to be used by certain similarity calculators.
      gt_labels:  a tensor of shape [M, num_classes]
        with labels for each of the ground_truth boxes. The subshape
        [num_classes] can be empty (corresponding to scalar inputs).  When set
        to None, gt_labels assumes a binary problem where all
        ground_truth boxes get a positive label (of 1).
      gt_weights: a float tensor of shape [M] indicating the weight to
        assign to all pred_boxes match to a particular groundtruth box. The
        weights must be in [0., 1.]. If None, all weights are set to 1.
        Generally no groundtruth boxes with zero weight match to any pred_boxes
        as matchers are aware of groundtruth weights. Additionally,
        `cls_weights` and `reg_weights` are calculated using groundtruth
        weights as an added safety.
      unmatched_class_label: a float32 tensor with shape [d_1, d_2, ..., d_k]
        which is consistent with the classification target for each
        anchor (and can be empty for scalar targets).  This shape must thus be
        compatible with the groundtruth labels that are passed to the "assign"
        function (which have shape [num_gt_boxes, d_1, d_2, ..., d_k]).

    Returns:
      cls_targets: a float32 tensor with shape [num_pred_boxes, num_classes],
        where the subshape [num_classes] is compatible with gt_labels
        which has shape [num_gt_boxes, num_classes].
      cls_weights: a float32 tensor with shape [num_pred_boxes, num_classes],
        representing weights for each element in cls_targets.
      reg_targets: a float32 tensor with shape [num_pred_boxes,
        box_code_dimension]
      reg_weights: a float32 tensor with shape [num_pred_boxes]

    
inference_api/src/main/object_detection/core/target_assigner.py