code: def transform_targets_for_output(y_true, grid_size, anchor_idxs):
      N = tf.shape(y_true)[0]
      y_true_out = tf.zeros(
          (N, grid_size, grid_size, tf.shape(anchor_idxs)[0], 6)
      )
      anchor_idxs = tf.cast(anchor_idxs, tf.int32)
  
      def outer_comp(i):
          def inner_comp(j):
              anchor_eq = tf.equal(
                  anchor_idxs, tf.cast(y_true[i][j][5], tf.int32)
              )
  
              def reduce(y_true, anchor_eq, grid_size):
                  box = y_true[i][j][0:4]
                  box_xy = (y_true[i][j][0:2] + y_true[i][j][2:4]) / 2
                  anchor_idx = tf.cast(tf.where(anchor_eq), tf.int32)
                  grid_xy = tf.cast(box_xy // (1 / grid_size), tf.int32)
  
                  # grid[y][x][anchor] = (tx, ty, bw, bh, obj, class)
                  indexes = tf.stack(
                      [i, grid_xy[1], grid_xy[0], anchor_idx[0][0]]
                  )
                  updates = tf.stack(
                      [
                          box[0],
                          box[1],
                          box[2],
                          box[3],
                          tf.constant(1, dtype=tf.float32),
                          y_true[i][j][4],
                      ]
                  )
                  print("updates", updates)
                  # idx += 1
                  return (True, indexes, updates)
  
              (mask, indexes, updates) = tf.cond(
                  tf.math.logical_and(
                      tf.reduce_any(anchor_eq),
                      tf.math.logical_not(tf.equal(y_true[i][j][2], 0)),
                  ),
                  lambda: reduce(y_true, anchor_eq, grid_size),
                  lambda: (
                      False,
                      tf.zeros(4, tf.int32),
                      tf.zeros(6, tf.float32),
                  ),
              )
              return (mask, indexes, updates)
  
          return tf.map_fn(
              inner_comp,
              tf.range(tf.shape(y_true)[1]),
              dtype=(tf.bool, tf.int32, tf.float32),
          )
  
      (mask, indexes, updates) = tf.map_fn(
          outer_comp, tf.range(N), dtype=(tf.bool, tf.int32, tf.float32)
      )
  
      indexes = tf.boolean_mask(indexes, mask)
      updates = tf.boolean_mask(updates, mask)
  
      return tf.tensor_scatter_nd_update(y_true_out, indexes, updates)
  
imports: import tensorflow
  from tensorflow.keras.callbacks import ReduceLROnPlateau, EarlyStopping, ModelCheckpoint, TensorBoard
  from tensorflow.keras import Model
  from tensorflow.keras.layers import Add, Concatenate, Conv2D, Input, Lambda, LeakyReLU, MaxPool2D, UpSampling2D, ZeroPadding2D, BatchNormalization
  from tensorflow.keras.regularizers import l2
  from tensorflow.keras.losses import binary_crossentropy, sparse_categorical_crossentropy
  from bigdl.dllib.utils.log4Error import invalidInputError
  from bigdl.orca.data.image.parquet_dataset import read_parquet, write_parquet
  from bigdl.orca.learn.tf2 import Estimator
  from bigdl.orca import init_orca_context, stop_orca_context
  import numpy
  import tempfile
  import os
  import argparse
label_desc: Use image node_id 1 for calling a global function with example usage: transform_targets_for_output(y_true, grid_size, anchor_idxs) and returns: tf, tf, mask,  indexes,  updates, True,  indexes,  updates