def _postprocess_keypoints_for_class_and_image(self, keypoint_heatmap, keypoint_offsets, keypoint_regression, classes, y_indices, x_indices, boxes, indices_with_kpt_class, batch_index, kp_params):
    'Postprocess keypoints for a single image and class.\n\n    This function performs the following postprocessing operations on a single\n    image and single keypoint class:\n    - Converts keypoints scores to range [0, 1] with sigmoid.\n    - Determines the detections that correspond to the specified keypoint class.\n    - Gathers the regressed keypoints at the detection (i.e. box) centers.\n    - Gathers keypoint candidates from the keypoint heatmaps.\n    - Snaps regressed keypoints to nearby keypoint candidates.\n\n    Args:\n      keypoint_heatmap: A [batch_size, height, width, num_keypoints] float32\n        tensor with keypoint heatmaps.\n      keypoint_offsets: A [batch_size, height, width, 2] float32 tensor with\n        local offsets to keypoint centers.\n      keypoint_regression: A [batch_size, height, width, 2 * num_keypoints]\n        float32 tensor with regressed offsets to all keypoints.\n      classes: A [batch_size, max_detections] int tensor with class indices for\n        all detected objects.\n      y_indices: A [batch_size, max_detections] int tensor with y indices for\n        all object centers.\n      x_indices: A [batch_size, max_detections] int tensor with x indices for\n        all object centers.\n      boxes: A [batch_size, max_detections, 4] float32 tensor with detected\n        boxes in the output (strided) frame.\n      indices_with_kpt_class: A [num_instances] int tensor where each element\n        indicates the instance location within the `classes` tensor. This is\n        useful to associate the refined keypoints with the original detections\n        (i.e. boxes)\n      batch_index: An integer specifying the index for an example in the batch.\n      kp_params: A `KeypointEstimationParams` object with parameters for a\n        single keypoint class.\n\n    Returns:\n      A tuple of\n      refined_keypoints: A [1, num_instances, num_keypoints, 2] float32 tensor\n        with refined keypoints for a single class in a single image, expressed\n        in the output (strided) coordinate frame. Note that `num_instances` is a\n        dynamic dimension, and corresponds to the number of valid detections\n        for the specific class.\n      refined_scores: A [1, num_instances, num_keypoints] float32 tensor with\n        keypoint scores.\n    '
    keypoint_indices = kp_params.keypoint_indices
    num_keypoints = len(keypoint_indices)
    keypoint_heatmap = tf.nn.sigmoid(keypoint_heatmap[batch_index:(batch_index + 1), ...])
    keypoint_offsets = keypoint_offsets[batch_index:(batch_index + 1), ...]
    keypoint_regression = keypoint_regression[batch_index:(batch_index + 1), ...]
    y_indices = y_indices[batch_index:(batch_index + 1), ...]
    x_indices = x_indices[batch_index:(batch_index + 1), ...]
    y_indices_for_kpt_class = tf.gather(y_indices, indices_with_kpt_class, axis=1)
    x_indices_for_kpt_class = tf.gather(x_indices, indices_with_kpt_class, axis=1)
    boxes_for_kpt_class = tf.gather(boxes, indices_with_kpt_class, axis=1)
    regressed_keypoints_for_objects = regressed_keypoints_at_object_centers(keypoint_regression, y_indices_for_kpt_class, x_indices_for_kpt_class)
    regressed_keypoints_for_objects = tf.reshape(regressed_keypoints_for_objects, [1, (- 1), num_keypoints, 2])
    (keypoint_candidates, keypoint_scores, num_keypoint_candidates) = prediction_tensors_to_keypoint_candidates(keypoint_heatmap, keypoint_offsets, keypoint_score_threshold=kp_params.keypoint_candidate_score_threshold, max_pool_kernel_size=kp_params.peak_max_pool_kernel_size, max_candidates=kp_params.num_candidates_per_keypoint)
    (refined_keypoints, refined_scores) = refine_keypoints(regressed_keypoints_for_objects, keypoint_candidates, keypoint_scores, num_keypoint_candidates, bboxes=boxes_for_kpt_class, unmatched_keypoint_score=kp_params.unmatched_keypoint_score, box_scale=kp_params.box_scale, candidate_search_scale=kp_params.candidate_search_scale, candidate_ranking_mode=kp_params.candidate_ranking_mode)
    return (refined_keypoints, refined_scores)
Postprocess keypoints for a single image and class.

This function performs the following postprocessing operations on a single
image and single keypoint class:
- Converts keypoints scores to range [0, 1] with sigmoid.
- Determines the detections that correspond to the specified keypoint class.
- Gathers the regressed keypoints at the detection (i.e. box) centers.
- Gathers keypoint candidates from the keypoint heatmaps.
- Snaps regressed keypoints to nearby keypoint candidates.

Args:
  keypoint_heatmap: A [batch_size, height, width, num_keypoints] float32
    tensor with keypoint heatmaps.
  keypoint_offsets: A [batch_size, height, width, 2] float32 tensor with
    local offsets to keypoint centers.
  keypoint_regression: A [batch_size, height, width, 2 * num_keypoints]
    float32 tensor with regressed offsets to all keypoints.
  classes: A [batch_size, max_detections] int tensor with class indices for
    all detected objects.
  y_indices: A [batch_size, max_detections] int tensor with y indices for
    all object centers.
  x_indices: A [batch_size, max_detections] int tensor with x indices for
    all object centers.
  boxes: A [batch_size, max_detections, 4] float32 tensor with detected
    boxes in the output (strided) frame.
  indices_with_kpt_class: A [num_instances] int tensor where each element
    indicates the instance location within the `classes` tensor. This is
    useful to associate the refined keypoints with the original detections
    (i.e. boxes)
  batch_index: An integer specifying the index for an example in the batch.
  kp_params: A `KeypointEstimationParams` object with parameters for a
    single keypoint class.

Returns:
  A tuple of
  refined_keypoints: A [1, num_instances, num_keypoints, 2] float32 tensor
    with refined keypoints for a single class in a single image, expressed
    in the output (strided) coordinate frame. Note that `num_instances` is a
    dynamic dimension, and corresponds to the number of valid detections
    for the specific class.
  refined_scores: A [1, num_instances, num_keypoints] float32 tensor with
    keypoint scores.
def _postprocess_keypoints_for_class_and_image(self, keypoint_heatmap, keypoint_offsets, keypoint_regression, classes, y_indices, x_indices, boxes, indices_with_kpt_class, batch_index, kp_params):
    'Postprocess keypoints for a single image and class.\n\n    This function performs the following postprocessing operations on a single\n    image and single keypoint class:\n    - Converts keypoints scores to range [0, 1] with sigmoid.\n    - Determines the detections that correspond to the specified keypoint class.\n    - Gathers the regressed keypoints at the detection (i.e. box) centers.\n    - Gathers keypoint candidates from the keypoint heatmaps.\n    - Snaps regressed keypoints to nearby keypoint candidates.\n\n    Args:\n      keypoint_heatmap: A [batch_size, height, width, num_keypoints] float32\n        tensor with keypoint heatmaps.\n      keypoint_offsets: A [batch_size, height, width, 2] float32 tensor with\n        local offsets to keypoint centers.\n      keypoint_regression: A [batch_size, height, width, 2 * num_keypoints]\n        float32 tensor with regressed offsets to all keypoints.\n      classes: A [batch_size, max_detections] int tensor with class indices for\n        all detected objects.\n      y_indices: A [batch_size, max_detections] int tensor with y indices for\n        all object centers.\n      x_indices: A [batch_size, max_detections] int tensor with x indices for\n        all object centers.\n      boxes: A [batch_size, max_detections, 4] float32 tensor with detected\n        boxes in the output (strided) frame.\n      indices_with_kpt_class: A [num_instances] int tensor where each element\n        indicates the instance location within the `classes` tensor. This is\n        useful to associate the refined keypoints with the original detections\n        (i.e. boxes)\n      batch_index: An integer specifying the index for an example in the batch.\n      kp_params: A `KeypointEstimationParams` object with parameters for a\n        single keypoint class.\n\n    Returns:\n      A tuple of\n      refined_keypoints: A [1, num_instances, num_keypoints, 2] float32 tensor\n        with refined keypoints for a single class in a single image, expressed\n        in the output (strided) coordinate frame. Note that `num_instances` is a\n        dynamic dimension, and corresponds to the number of valid detections\n        for the specific class.\n      refined_scores: A [1, num_instances, num_keypoints] float32 tensor with\n        keypoint scores.\n    '
    keypoint_indices = kp_params.keypoint_indices
    num_keypoints = len(keypoint_indices)
    keypoint_heatmap = tf.nn.sigmoid(keypoint_heatmap[batch_index:(batch_index + 1), ...])
    keypoint_offsets = keypoint_offsets[batch_index:(batch_index + 1), ...]
    keypoint_regression = keypoint_regression[batch_index:(batch_index + 1), ...]
    y_indices = y_indices[batch_index:(batch_index + 1), ...]
    x_indices = x_indices[batch_index:(batch_index + 1), ...]
    y_indices_for_kpt_class = tf.gather(y_indices, indices_with_kpt_class, axis=1)
    x_indices_for_kpt_class = tf.gather(x_indices, indices_with_kpt_class, axis=1)
    boxes_for_kpt_class = tf.gather(boxes, indices_with_kpt_class, axis=1)
    regressed_keypoints_for_objects = regressed_keypoints_at_object_centers(keypoint_regression, y_indices_for_kpt_class, x_indices_for_kpt_class)
    regressed_keypoints_for_objects = tf.reshape(regressed_keypoints_for_objects, [1, (- 1), num_keypoints, 2])
    (keypoint_candidates, keypoint_scores, num_keypoint_candidates) = prediction_tensors_to_keypoint_candidates(keypoint_heatmap, keypoint_offsets, keypoint_score_threshold=kp_params.keypoint_candidate_score_threshold, max_pool_kernel_size=kp_params.peak_max_pool_kernel_size, max_candidates=kp_params.num_candidates_per_keypoint)
    (refined_keypoints, refined_scores) = refine_keypoints(regressed_keypoints_for_objects, keypoint_candidates, keypoint_scores, num_keypoint_candidates, bboxes=boxes_for_kpt_class, unmatched_keypoint_score=kp_params.unmatched_keypoint_score, box_scale=kp_params.box_scale, candidate_search_scale=kp_params.candidate_search_scale, candidate_ranking_mode=kp_params.candidate_ranking_mode)
    return (refined_keypoints, refined_scores)