def _get_non_maximum_supression(context, node, iou_threshold_override=None, score_threshold_override=None):
    """
    The helper function returns the outputs from mb.non_maximum_suppression,
    along with the number of boxes and the maximum number of boxes.
    """
    boxes = context[node.inputs[0]]
    scores = context[node.inputs[1]]
    max_boxes = context[node.inputs[2]]
    iou_threshold = iou_threshold_override or context[node.inputs[3]]
    score_threshold = score_threshold_override or context[node.inputs[4]]

    # The boxes' coordinates in Tensorflow is (y1, x1, y2, x2) where (y1, x1) and (y2, x2) are the
    # coordinates of diagonal pair of box corners. However, MIL NMS expects CENTER_SIZE_WIDTH_FIRST
    # format, which is (x, y, width, height) where (x, y) is the center coordinate.
    y1, x1, y2, x2 = mb.split(x=boxes, num_splits=4, axis=-1)
    # As the input coordinates could be any diagonal pair of box corners, it's not guaranteed that
    # x2 > x1 nor y2 > y1. So we need to use abs to get width/height, and (x1+x2)/2 to get center.
    width = mb.abs(x=mb.sub(x=x2, y=x1))
    height = mb.abs(x=mb.sub(x=y2, y=y1))
    center_x = mb.real_div(x=mb.add(x=x1, y=x2), y=2.0)
    center_y = mb.real_div(x=mb.add(x=y1, y=y2), y=2.0)
    boxes = mb.concat(values=[center_x, center_y, width, height], axis=-1)

    if score_threshold.val == float("-inf"):
        # TensorFlow's default value for score_threshold, Core ML does not
        # have float('-inf') support, converted to minimum float32 instead
        score_threshold = -3.4e38

    boxes = mb.expand_dims(x=boxes, axes=[0])
    scores = mb.expand_dims(x=scores, axes=[0, -1])
    coordinates, scores, indices, valid_outputs = mb.non_maximum_suppression(
        boxes=boxes,
        scores=scores,
        max_boxes=max_boxes,
        iou_threshold=iou_threshold,
        score_threshold=score_threshold,
    )

    # The results from MIL NMS op are padded to max_boxes. We need to extract the valid part for TF.
    # Notice that the batch dim and class num dim also need to be squeezed.
    valid_outputs = mb.squeeze(x=valid_outputs, axes=[0])
    range = mb.range_1d(end=valid_outputs, start=0, step=1)
    coordinates = mb.squeeze(x=coordinates, axes=[0])
    valid_coordinates = mb.gather(x=coordinates, indices=range, axis=0)
    scores = mb.squeeze(x=scores, axes=[0, -1])
    valid_scores = mb.gather(x=scores, indices=range, axis=0)
    indices = mb.squeeze(x=indices, axes=[0])
    valid_indices = mb.cast(
        x=mb.gather(x=mb.cast(x=indices, dtype="fp32"), indices=range, axis=0),
        dtype="int32",
        name=node.name,
    )

    return valid_coordinates, valid_scores, valid_indices, valid_outputs

    The helper function returns the outputs from mb.non_maximum_suppression,
    along with the number of boxes and the maximum number of boxes.
    
coremltools/converters/mil/frontend/tensorflow/ops.py