class_docstr: CenterNet network using Hourglass from https://arxiv.org/abs/1904.07850S.
class_docstr_tok: ["CenterNet","network","using","Hourglass","from","https",":","\/\/arxiv.org\/abs\/1904.07850S","."]
docstr: Post-process model predictions into detections.
docstr_tok: ["Post-process","model","predictions","into","detections","."]
code: def postprocess_sample2(
      self, input_image_size, sample, output, apply_sigmoid=True
  ):
      """Post-process model predictions into detections."""
  
      if apply_sigmoid:
          print(apply_sigmoid)
  
      batch_id = 0
      detections_dict = {}
      detections_dict["centers"] = output["centers"][batch_id, ...]
      detections_dict["centers_sigmoid"] = output["centers_sigmoid"][
          batch_id, ...
      ]
      detections_dict["centers_nms"] = output["centers_nms"][
          batch_id, ...
      ]
  
      # self.K = sample['num_boxes'][0].numpy()
  
      (
          xs,
          ys,
          topk_classes,
          topk_inds,
          scores,
      ) = self._top_scores_heatmaps(output["centers_nms"], self.k)
  
      # Filter based on threshold
      mask = scores > self.score_threshold
      xs = tf.expand_dims(xs[mask], 0)
      ys = tf.expand_dims(ys[mask], 0)
      topk_classes = tf.expand_dims(topk_classes[mask], 0)
      topk_inds = tf.expand_dims(topk_inds[mask], 0)
      scores = tf.expand_dims(scores[mask], 0)
      k = tf.shape(scores)[-1]
  
      offset = self._get_offsets(output["offset"], topk_inds)
      xs, ys = xs + offset[..., 0], ys + offset[..., 1]
      width_height = self._get_width_height(
          output["width_height"], topk_inds
      )
      detections = self.group_detections(
          xs, ys, scores, topk_classes, width_height
      )
      original_image_size = sample[self.sample_image_size][batch_id, :2]
      (
          center,
          side_size,
          input_size,
      ) = transforms.compute_image_size_affine_transform(
          original_image_size, input_image_size
      )
      metadata = tf.stack([center, side_size, input_size], axis=0)[
          None, ...
      ]
      detections = self.transform_detections(detections, metadata)
  
      (
          sizes_3d,
          translations_3d,
          rotations_3d,
      ) = centernet_utils.decode_box_3d(
          output, topk_inds, self.rotation_svd
      )
      rotations_3d = tf.reshape(rotations_3d, [-1, k, 3, 3])
  
      # Shape post-processing
      shape_logits = self._get_width_height(output["shapes"], topk_inds)
  
      status = True
      if status:
          detection_classes = tf.cast(
              detections[:, :, -1], dtype=tf.int32
          )
          # 3   8   0- 50  bottle
          # 4  56  50-100  bowl
          # 0 119 100-150  chair
          # 5 156 150-200  mug
          # 1 202 200-250  sofa
          # 2 287 250-300  table
  
          num_classes = 6
          cluster_size = 50
          detection_classes_reorder = np.array([3, 4, 0, 5, 1, 2])[
              detection_classes.numpy()
          ]
          mask = tf.repeat(
              tf.one_hot(
                  detection_classes_reorder, num_classes, axis=-1
              ),
              repeats=[cluster_size],
              axis=-1,
          )
          shape_logits = shape_logits - (1 - mask) * tf.reduce_min(
              shape_logits, axis=-1, keepdims=True
          )
  
      shape_classes = tf.argmax(shape_logits, axis=-1)
  
      # Get predicted SDFs and Pointclouds
      predicted_sdfs = centernet_utils.softargmax(
          shape_logits, self.shape_sdfs
      )
      predicted_sdfs = tf.reshape(predicted_sdfs, [1, -1, 32, 32, 32])
      predicted_pointclouds = centernet_utils.softargmax(
          shape_logits, self.shape_pointclouds
      )
      predicted_pointclouds = tf.reshape(
          predicted_pointclouds, [1, -1, 512, 3]
      )
  
      # Transform predicted point cloud
      transformed_pointclouds = centernet_utils.transform_pointcloud(
          predicted_pointclouds / 2.0,
          sizes_3d,
          rotations_3d,
          translations_3d,
      )
      transformed_pointclouds = tf.concat(
          [transformed_pointclouds, tf.ones([1, k, 512, 1])], axis=-1
      )
      transformed_pointclouds = tf.transpose(
          transformed_pointclouds, [0, 1, 3, 2]
      )  # (5, 3, 4, 512)
  
      intrinsics = tf.reshape(sample["k"], [1, 1, 3, 3])  # (5, 3, 3)
      intrinsics = tf.tile(intrinsics, [1, k, 1, 1])  # (5, 1, 3, 4)
      extrinsics = tf.expand_dims(sample["rt"], axis=1)  # (5, 1, 3, 4)
      extrinsics = tf.tile(extrinsics, [1, k, 1, 1])  # (5, 1, 3, 4)
  
      projected_pointclouds = (
          intrinsics @ extrinsics @ transformed_pointclouds
      )
      projected_pointclouds = tf.transpose(
          projected_pointclouds, [0, 1, 3, 2]
      )
      projected_pointclouds = (
          projected_pointclouds / projected_pointclouds[:, :, :, -1:]
      )
  
      # detections_dict['centers'] = detections_dict['centers']
      # detections_dict['centers_sigmoid'] = detections_dict['centers_sigmoid']
      # detections_dict['centers_nms'] = detections_dict['centers_nms']
      detections_dict["detection_boxes"] = detections[batch_id, :, :4]
      detections_dict["detection_scores"] = detections[batch_id, :, 4]
      detections_dict["detection_classes"] = detections[batch_id, :, 5]
      detections_dict["rotations_3d"] = rotations_3d[batch_id, ...]
      detections_dict["translations_3d"] = translations_3d[
          batch_id, ...
      ]
      detections_dict["sizes_3d"] = sizes_3d[batch_id, ...]
      detections_dict["groundtruth_sdfs"] = output["groundtruth_sdfs"][
          batch_id, ...
      ]
      detections_dict["groundtruth_pointclouds"] = output[
          "groundtruth_pointclouds"
      ][batch_id, ...]
      detections_dict["predicted_sdfs"] = predicted_sdfs[batch_id, ...]
      detections_dict["predicted_pointclouds"] = predicted_pointclouds[
          batch_id, ...
      ]
      detections_dict["shapes"] = shape_classes[batch_id, ...]
      detections_dict["shapes_logits"] = shape_logits[batch_id, ...]
      detections_dict["projected_pointclouds"] = projected_pointclouds[
          batch_id, ...
      ]
      return detections_dict
  
imports: import collections
  import os
  import random
  import string
  import time
  from absl import logging
  import numpy
  import tensorflow
  from tensorflow_graphics.projects.points_to_3Dobjects.models import centernet_utils
  from tensorflow_graphics.projects.points_to_3Dobjects.networks import hourglass
  from tensorflow_graphics.projects.points_to_3Dobjects.transforms import transforms
  from tensorflow_graphics.projects.points_to_3Dobjects.utils import image
  from google3.pyglib import gfile
label_desc: Use image node_id 19 for calling the CenterNetVID obj's underlying member method code with example usage: obj.postprocess_sample2(input_image_size, sample, output, apply_sigmoid) and returns: detections_dict