code: def get_dali_pipeline(
      tfrec_filenames,
      tfrec_idx_filenames,
      height,
      width,
      shard_id,
      num_gpus,
      dali_cpu=True,
      training=True,
  ):
      inputs = fn.readers.tfrecord(
          path=tfrec_filenames,
          index_path=tfrec_idx_filenames,
          random_shuffle=training,
          shard_id=shard_id,
          num_shards=num_gpus,
          initial_fill=10000,
          features={
              "image/encoded": tfrec.FixedLenFeature(
                  (), tfrec.string, ""
              ),
              "image/class/label": tfrec.FixedLenFeature(
                  [1], tfrec.int64, -1
              ),
              "image/class/text": tfrec.FixedLenFeature(
                  [], tfrec.string, ""
              ),
              "image/object/bbox/xmin": tfrec.VarLenFeature(
                  tfrec.float32, 0.0
              ),
              "image/object/bbox/ymin": tfrec.VarLenFeature(
                  tfrec.float32, 0.0
              ),
              "image/object/bbox/xmax": tfrec.VarLenFeature(
                  tfrec.float32, 0.0
              ),
              "image/object/bbox/ymax": tfrec.VarLenFeature(
                  tfrec.float32, 0.0
              ),
          },
      )
  
      decode_device = "cpu" if dali_cpu else "mixed"
      resize_device = "cpu" if dali_cpu else "gpu"
      if training:
          images = fn.decoders.image_random_crop(
              inputs["image/encoded"],
              device=decode_device,
              output_type=types.RGB,
              random_aspect_ratio=[0.75, 1.25],
              random_area=[0.05, 1.0],
              num_attempts=100,
              # ask HW NVJPEG to allocate memory ahead for the biggest image in the data set to avoid reallocations in runtime
              preallocate_width_hint=5980
              if decode_device == "mixed"
              else 0,
              preallocate_height_hint=6430
              if decode_device == "mixed"
              else 0,
          )
          images = fn.resize(
              images,
              device=resize_device,
              resize_x=width,
              resize_y=height,
          )
      else:
          images = fn.decoders.image(
              inputs["image/encoded"],
              device=decode_device,
              output_type=types.RGB,
          )
          # Make sure that every image > 224 for CropMirrorNormalize
          images = fn.resize(
              images, device=resize_device, resize_shorter=256
          )
  
      images = fn.crop_mirror_normalize(
          images.gpu(),
          dtype=types.FLOAT,
          crop=(height, width),
          mean=[123.68, 116.78, 103.94],
          std=[58.4, 57.12, 57.3],
          output_layout="HWC",
          mirror=fn.random.coin_flip(),
      )
      labels = inputs["image/class/label"].gpu()
  
      labels -= 1  # Change to 0-based (don't use background class)
      return images, labels
  
imports: import tensorflow
  import sys
  import os
  import numpy
  from subprocess import call
  import horovod.tensorflow.keras
  from nvidia.dali.pipeline import pipeline_def
  import nvidia.dali.fn
  import nvidia.dali.types
  import nvidia.dali.tfrecord
label_desc: Use image node_id 7 for calling a global function with example usage: get_dali_pipeline(tfrec_filenames, tfrec_idx_filenames, height, width, shard_id, num_gpus, dali_cpu, training) and returns: images,  labels