code: def get_sample_iterable_from_callback(
      source_desc: SourceDescription, batch_size
  ):
      """Transform sample callback accepting one argument into an Iterable"""
      first = source_desc.source(types.SampleInfo(0, 0, 0, 0))
      dtype, shape = _inspect_data(first, False)
  
      class CallableSampleIterator:
          first_value = first
  
          def __init__(self):
              self.idx_in_epoch = 0
              self.idx_in_batch = 0
              self.iteration = 0
              self.source = source_desc.source
  
          def __iter__(self):
              self.idx_in_epoch = 0
              self.idx_in_batch = 0
              self.iteration = 0
              return self
  
          def __next__(self):
              if (
                  self.idx_in_epoch == 0
                  and CallableSampleIterator.first_value is not None
              ):
                  result = CallableSampleIterator.first_value
                  CallableSampleIterator.first_value = None
              else:
                  # There is no notion of epochs when iterating over DALI Dataset
                  # as the "raise" policy is not supported, so we use epoch 0 only.
                  idx = types.SampleInfo(
                      self.idx_in_epoch,
                      self.idx_in_batch,
                      self.iteration,
                      0,
                  )
                  result = self.source(idx)
              self.idx_in_epoch += 1
              self.idx_in_batch += 1
              if self.idx_in_batch == batch_size:
                  self.idx_in_batch = 0
                  self.iteration += 1
              return sample_to_numpy(result, _tf_sample_error_msg)
  
      return CallableSampleIterator, dtype, shape
  
imports: from enum import Enum
  from nvidia.dali import types
  from nvidia.dali import tensors
  import inspect
  import functools
label_desc: Use image node_id 12 for calling a global function with example usage: get_sample_iterable_from_callback(source_desc, batch_size) and returns: CallableSampleIterator,  dtype,  shape, self, sample_to_numpy