code: def mosaic(images, bboxes, labels, image_size):
      def generate_tiles(bboxes, labels, shape_x, shape_y):
          idx = dali.fn.batch_permutation()
          permuted_boxes = dali.fn.permute_batch(bboxes, indices=idx)
          permuted_labels = dali.fn.permute_batch(labels, indices=idx)
          shape = dali.fn.stack(shape_y, shape_x)
          in_anchor, _, bbx, lbl = dali.fn.random_bbox_crop(
              permuted_boxes,
              permuted_labels,
              input_shape=image_size,
              crop_shape=shape,
              shape_layout="HW",
              allow_no_crop=False,
              total_num_attempts=64,
          )
  
          # swap coordinates (x, y) -> (y, x)
          in_anchor = in_anchor[::-1]
          in_anchor_c = dali.fn.cast(
              in_anchor, dtype=dali.types.DALIDataType.INT32
          )
  
          return idx, bbx, lbl, in_anchor_c, shape
  
      prop0_x = dali.fn.random.uniform(range=(0.2, 0.8))
      prop0_y = dali.fn.random.uniform(range=(0.2, 0.8))
      prop1_x = 1.0 - prop0_x
      prop1_y = 1.0 - prop0_y
  
      pix0_x = dali.fn.cast(
          prop0_x * image_size[0], dtype=dali.types.DALIDataType.INT32
      )
      pix0_y = dali.fn.cast(
          prop0_y * image_size[1], dtype=dali.types.DALIDataType.INT32
      )
      pix1_x = image_size[0] - pix0_x
      pix1_y = image_size[1] - pix0_y
  
      (
          perm_UL,
          bboxes_UL,
          labels_UL,
          in_anchor_UL,
          size_UL,
      ) = generate_tiles(bboxes, labels, pix0_x, pix0_y)
      (
          perm_UR,
          bboxes_UR,
          labels_UR,
          in_anchor_UR,
          size_UR,
      ) = generate_tiles(bboxes, labels, pix1_x, pix0_y)
      (
          perm_LL,
          bboxes_LL,
          labels_LL,
          in_anchor_LL,
          size_LL,
      ) = generate_tiles(bboxes, labels, pix0_x, pix1_y)
      (
          perm_LR,
          bboxes_LR,
          labels_LR,
          in_anchor_LR,
          size_LR,
      ) = generate_tiles(bboxes, labels, pix1_x, pix1_y)
  
      idx = dali.fn.stack(perm_UL, perm_UR, perm_LL, perm_LR)
      out_anchors = dali.fn.stack(
          dali.fn.stack(0, 0),
          dali.fn.stack(0, pix0_x),
          dali.fn.stack(pix0_y, 0),
          dali.fn.stack(pix0_y, pix0_x),
      )
      in_anchors = dali.fn.stack(
          in_anchor_UL, in_anchor_UR, in_anchor_LL, in_anchor_LR
      )
      shapes = dali.fn.stack(size_UL, size_UR, size_LL, size_LR)
  
      bboxes_UL = bbox_adjust_ltrb(
          bboxes_UL, prop0_x, prop0_y, 0.0, 0.0
      )
      bboxes_UR = bbox_adjust_ltrb(
          bboxes_UR, prop1_x, prop0_y, prop0_x, 0.0
      )
      bboxes_LL = bbox_adjust_ltrb(
          bboxes_LL, prop0_x, prop1_y, 0.0, prop0_y
      )
      bboxes_LR = bbox_adjust_ltrb(
          bboxes_LR, prop1_x, prop1_y, prop0_x, prop0_y
      )
      stacked_bboxes = dali.fn.cat(
          bboxes_UL, bboxes_UR, bboxes_LL, bboxes_LR
      )
      stacked_labels = dali.fn.cat(
          labels_UL, labels_UR, labels_LL, labels_LR
      )
  
      mosaic = dali.fn.multi_paste(
          images,
          in_ids=idx,
          output_size=image_size,
          in_anchors=in_anchors,
          shapes=shapes,
          out_anchors=out_anchors,
          dtype=dali.types.DALIDataType.UINT8,
      )
  
      return mosaic, stacked_bboxes, stacked_labels
  
imports: import nvidia.dali
label_desc: Use image node_id 7 for calling a global function with example usage: mosaic(images, bboxes, labels, image_size) and returns: mosaic,  stacked_bboxes,  stacked_labels, idx,  bbx,  lbl,  in_anchor_c,  shape