code: def decode_layer(layer, layer_id):
      shape = layer.shape  # [batch, width, height, 3 * (5 + classes)]
      d = shape[3]
      gw, gh = shape[1:3]
      stride_x = 1 / gw
      stride_y = 1 / gh
      tile_x = tf.cast(
          tf.tile(tf.expand_dims(tf.range(gw), axis=0), [gw, 1]),
          tf.float32,
      )
      tile_y = tf.cast(
          tf.tile(tf.expand_dims(tf.range(gw), axis=1), [1, gh]),
          tf.float32,
      )
      output_xywh = []
      output_obj = []
      output_cls = []
      for ir in range(3):
          data = layer[..., (d // 3) * ir : (d // 3) * (ir + 1)]
          dx = data[..., 0]
          dy = data[..., 1]
          dw = data[..., 2]
          dh = data[..., 3]
          x = (
              sigmoid(dx) * SCALES[layer_id]
              - 0.5 * (SCALES[layer_id] - 1)
              + tile_x
          ) * stride_x
          y = (
              sigmoid(dy) * SCALES[layer_id]
              - 0.5 * (SCALES[layer_id] - 1)
              + tile_y
          ) * stride_y
          w = tf.math.exp(dw) * ANCHORS[layer_id][ir][0] / SIZE
          h = tf.math.exp(dh) * ANCHORS[layer_id][ir][1] / SIZE
          output_xywh.append(tf.stack([x, y, w, h], axis=-1))
  
          output_obj.append(sigmoid(data[..., 4]))
          output_cls.append(sigmoid(data[..., 5:]))
  
      return (
          tf.stack(output_xywh, axis=-2),
          tf.stack(output_obj, axis=-1),
          tf.stack(output_cls, axis=-2),
      )
  
file_path: DALI/docs/examples/use_cases/tensorflow/yolov4/src/utils.py
imports: import tensorflow
  import numpy
  from inference import decode_prediction
label_desc: Use image node_id 6 for calling a global function with example usage: decode_layer(layer, layer_id) and returns: tf,  tf,  tf