code: def topk_class_boxes(
      params, cls_outputs: T, box_outputs: T
  ) -> Tuple[T, T, T, T]:
      """Pick the topk class and box outputs."""
      batch_size = tf.shape(cls_outputs)[0]
      num_classes = params["num_classes"]
  
      max_nms_inputs = params["nms_configs"].get("max_nms_inputs", 0)
      if max_nms_inputs > 0:
          # Prune anchors and detections to only keep max_nms_inputs.
          # Due to some issues, top_k is currently slow in graph model.
          logging.info("use max_nms_inputs for pre-nms topk.")
          cls_outputs_reshape = tf.reshape(
              cls_outputs, [batch_size, -1]
          )
          _, cls_topk_indices = tf.math.top_k(
              cls_outputs_reshape, k=max_nms_inputs, sorted=False
          )
          indices = cls_topk_indices // num_classes
          classes = cls_topk_indices % num_classes
          cls_indices = tf.stack([indices, classes], axis=2)
  
          cls_outputs_topk = tf.gather_nd(
              cls_outputs, cls_indices, batch_dims=1
          )
          box_outputs_topk = tf.gather_nd(
              box_outputs, tf.expand_dims(indices, 2), batch_dims=1
          )
      else:
          logging.info("use max_reduce for pre-nms topk.")
          # Keep all anchors, but for each anchor, just keep the max probablity for
          # each class.
          cls_outputs_idx = tf.math.argmax(
              cls_outputs, axis=-1, output_type=tf.int32
          )
          num_anchors = tf.shape(cls_outputs)[1]
  
          classes = cls_outputs_idx
          indices = tf.tile(
              tf.expand_dims(tf.range(num_anchors), axis=0),
              [batch_size, 1],
          )
          cls_outputs_topk = tf.reduce_max(cls_outputs, -1)
          box_outputs_topk = box_outputs
  
      return cls_outputs_topk, box_outputs_topk, classes, indices
  
file_path: DALI/docs/examples/use_cases/tensorflow/efficientdet/model/utils/postprocess.py
imports: from typing import List, Tuple
  from absl import logging
  import tensorflow
  from pipeline import anchors
label_desc: Use image node_id 4 for calling a global function with example usage: topk_class_boxes(params, cls_outputs, box_outputs) and returns: cls_outputs_topk,  box_outputs_topk,  classes,  indices