def convert_strided_predictions_to_instance_masks(boxes, classes, masks, true_image_shapes, densepose_part_heatmap=None, densepose_surface_coords=None, stride=4, mask_height=256, mask_width=256, score_threshold=0.5, densepose_class_index=(- 1)):
    'Converts predicted full-image masks into instance masks.\n\n  For each predicted detection box:\n    * Crop and resize the predicted mask (and optionally DensePose coordinates)\n      based on the detected bounding box coordinates and class prediction. Uses\n      bilinear resampling.\n    * Binarize the mask using the provided score threshold.\n\n  Args:\n    boxes: A tensor of shape [batch, max_detections, 4] holding the predicted\n      boxes, in normalized coordinates (relative to the true image dimensions).\n    classes: An integer tensor of shape [batch, max_detections] containing the\n      detected class for each box (0-indexed).\n    masks: A [batch, output_height, output_width, num_classes] float32\n      tensor with class probabilities.\n    true_image_shapes: A tensor of shape [batch, 3] representing the true\n      shape of the inputs not considering padding.\n    densepose_part_heatmap: (Optional) A [batch, output_height, output_width,\n      num_parts] float32 tensor with part scores (i.e. logits).\n    densepose_surface_coords: (Optional) A [batch, output_height, output_width,\n      2 * num_parts] float32 tensor with predicted part coordinates (in\n      vu-format).\n    stride: The stride in the output space.\n    mask_height: The desired resized height for instance masks.\n    mask_width: The desired resized width for instance masks.\n    score_threshold: The threshold at which to convert predicted mask\n       into foreground pixels.\n    densepose_class_index: The class index (0-indexed) corresponding to the\n      class which has DensePose labels (e.g. person class).\n\n  Returns:\n    A tuple of masks and surface_coords.\n    instance_masks: A [batch_size, max_detections, mask_height, mask_width]\n      uint8 tensor with predicted foreground mask for each\n      instance. If DensePose tensors are provided, then each pixel value in the\n      mask encodes the 1-indexed part.\n    surface_coords: A [batch_size, max_detections, mask_height, mask_width, 2]\n      float32 tensor with (v, u) coordinates. Note that v, u coordinates are\n      only defined on instance masks, and the coordinates at each location of\n      the foreground mask correspond to coordinates on a local part coordinate\n      system (the specific part can be inferred from the `instance_masks`\n      output. If DensePose feature maps are not passed to this function, this\n      output will be None.\n\n  Raises:\n    ValueError: If one but not both of `densepose_part_heatmap` and\n    `densepose_surface_coords` is provided.\n  '
    (batch_size, output_height, output_width, _) = shape_utils.combined_static_and_dynamic_shape(masks)
    input_height = (stride * output_height)
    input_width = (stride * output_width)
    (true_heights, true_widths, _) = tf.unstack(true_image_shapes, axis=1)
    densepose_present = True
    if ((densepose_part_heatmap is not None) ^ (densepose_surface_coords is not None)):
        raise ValueError('To use DensePose, both `densepose_part_heatmap` and `densepose_surface_coords` must be provided')
    if ((densepose_part_heatmap is None) and (densepose_surface_coords is None)):
        densepose_present = False
        densepose_part_heatmap = tf.zeros((batch_size, output_height, output_width, 1), dtype=tf.float32)
        densepose_surface_coords = tf.zeros((batch_size, output_height, output_width, 2), dtype=tf.float32)
    crop_and_threshold_fn = functools.partial(crop_and_threshold_masks, input_height=input_height, input_width=input_width, mask_height=mask_height, mask_width=mask_width, score_threshold=score_threshold, densepose_class_index=densepose_class_index)
    (instance_masks, surface_coords) = shape_utils.static_or_dynamic_map_fn(crop_and_threshold_fn, elems=[boxes, classes, masks, densepose_part_heatmap, densepose_surface_coords, true_heights, true_widths], dtype=[tf.uint8, tf.float32], back_prop=False)
    surface_coords = (surface_coords if densepose_present else None)
    return (instance_masks, surface_coords)
Converts predicted full-image masks into instance masks.

For each predicted detection box:
  * Crop and resize the predicted mask (and optionally DensePose coordinates)
    based on the detected bounding box coordinates and class prediction. Uses
    bilinear resampling.
  * Binarize the mask using the provided score threshold.

Args:
  boxes: A tensor of shape [batch, max_detections, 4] holding the predicted
    boxes, in normalized coordinates (relative to the true image dimensions).
  classes: An integer tensor of shape [batch, max_detections] containing the
    detected class for each box (0-indexed).
  masks: A [batch, output_height, output_width, num_classes] float32
    tensor with class probabilities.
  true_image_shapes: A tensor of shape [batch, 3] representing the true
    shape of the inputs not considering padding.
  densepose_part_heatmap: (Optional) A [batch, output_height, output_width,
    num_parts] float32 tensor with part scores (i.e. logits).
  densepose_surface_coords: (Optional) A [batch, output_height, output_width,
    2 * num_parts] float32 tensor with predicted part coordinates (in
    vu-format).
  stride: The stride in the output space.
  mask_height: The desired resized height for instance masks.
  mask_width: The desired resized width for instance masks.
  score_threshold: The threshold at which to convert predicted mask
     into foreground pixels.
  densepose_class_index: The class index (0-indexed) corresponding to the
    class which has DensePose labels (e.g. person class).

Returns:
  A tuple of masks and surface_coords.
  instance_masks: A [batch_size, max_detections, mask_height, mask_width]
    uint8 tensor with predicted foreground mask for each
    instance. If DensePose tensors are provided, then each pixel value in the
    mask encodes the 1-indexed part.
  surface_coords: A [batch_size, max_detections, mask_height, mask_width, 2]
    float32 tensor with (v, u) coordinates. Note that v, u coordinates are
    only defined on instance masks, and the coordinates at each location of
    the foreground mask correspond to coordinates on a local part coordinate
    system (the specific part can be inferred from the `instance_masks`
    output. If DensePose feature maps are not passed to this function, this
    output will be None.

Raises:
  ValueError: If one but not both of `densepose_part_heatmap` and
  `densepose_surface_coords` is provided.
def convert_strided_predictions_to_instance_masks(boxes, classes, masks, true_image_shapes, densepose_part_heatmap=None, densepose_surface_coords=None, stride=4, mask_height=256, mask_width=256, score_threshold=0.5, densepose_class_index=(- 1)):
    'Converts predicted full-image masks into instance masks.\n\n  For each predicted detection box:\n    * Crop and resize the predicted mask (and optionally DensePose coordinates)\n      based on the detected bounding box coordinates and class prediction. Uses\n      bilinear resampling.\n    * Binarize the mask using the provided score threshold.\n\n  Args:\n    boxes: A tensor of shape [batch, max_detections, 4] holding the predicted\n      boxes, in normalized coordinates (relative to the true image dimensions).\n    classes: An integer tensor of shape [batch, max_detections] containing the\n      detected class for each box (0-indexed).\n    masks: A [batch, output_height, output_width, num_classes] float32\n      tensor with class probabilities.\n    true_image_shapes: A tensor of shape [batch, 3] representing the true\n      shape of the inputs not considering padding.\n    densepose_part_heatmap: (Optional) A [batch, output_height, output_width,\n      num_parts] float32 tensor with part scores (i.e. logits).\n    densepose_surface_coords: (Optional) A [batch, output_height, output_width,\n      2 * num_parts] float32 tensor with predicted part coordinates (in\n      vu-format).\n    stride: The stride in the output space.\n    mask_height: The desired resized height for instance masks.\n    mask_width: The desired resized width for instance masks.\n    score_threshold: The threshold at which to convert predicted mask\n       into foreground pixels.\n    densepose_class_index: The class index (0-indexed) corresponding to the\n      class which has DensePose labels (e.g. person class).\n\n  Returns:\n    A tuple of masks and surface_coords.\n    instance_masks: A [batch_size, max_detections, mask_height, mask_width]\n      uint8 tensor with predicted foreground mask for each\n      instance. If DensePose tensors are provided, then each pixel value in the\n      mask encodes the 1-indexed part.\n    surface_coords: A [batch_size, max_detections, mask_height, mask_width, 2]\n      float32 tensor with (v, u) coordinates. Note that v, u coordinates are\n      only defined on instance masks, and the coordinates at each location of\n      the foreground mask correspond to coordinates on a local part coordinate\n      system (the specific part can be inferred from the `instance_masks`\n      output. If DensePose feature maps are not passed to this function, this\n      output will be None.\n\n  Raises:\n    ValueError: If one but not both of `densepose_part_heatmap` and\n    `densepose_surface_coords` is provided.\n  '
    (batch_size, output_height, output_width, _) = shape_utils.combined_static_and_dynamic_shape(masks)
    input_height = (stride * output_height)
    input_width = (stride * output_width)
    (true_heights, true_widths, _) = tf.unstack(true_image_shapes, axis=1)
    densepose_present = True
    if ((densepose_part_heatmap is not None) ^ (densepose_surface_coords is not None)):
        raise ValueError('To use DensePose, both `densepose_part_heatmap` and `densepose_surface_coords` must be provided')
    if ((densepose_part_heatmap is None) and (densepose_surface_coords is None)):
        densepose_present = False
        densepose_part_heatmap = tf.zeros((batch_size, output_height, output_width, 1), dtype=tf.float32)
        densepose_surface_coords = tf.zeros((batch_size, output_height, output_width, 2), dtype=tf.float32)
    crop_and_threshold_fn = functools.partial(crop_and_threshold_masks, input_height=input_height, input_width=input_width, mask_height=mask_height, mask_width=mask_width, score_threshold=score_threshold, densepose_class_index=densepose_class_index)
    (instance_masks, surface_coords) = shape_utils.static_or_dynamic_map_fn(crop_and_threshold_fn, elems=[boxes, classes, masks, densepose_part_heatmap, densepose_surface_coords, true_heights, true_widths], dtype=[tf.uint8, tf.float32], back_prop=False)
    surface_coords = (surface_coords if densepose_present else None)
    return (instance_masks, surface_coords)