code: def run_dataset_in_graph(
      dali_datasets, iterations, to_stop_iter=False
  ):
      if not isinstance(dali_datasets, list):
          dali_datasets = [dali_datasets]
  
      dataset_results = []
      initializers = [tf.compat.v1.global_variables_initializer()]
      ops_to_run = []
  
      for dali_dataset in dali_datasets:
          iterator = tf.compat.v1.data.make_initializable_iterator(
              dali_dataset
          )
          initializers.append(iterator.initializer)
          ops_to_run.append(iterator.get_next())
  
      with tf.compat.v1.Session() as sess:
          sess.run(initializers)
          with expect_iter_end(
              not to_stop_iter, tf.errors.OutOfRangeError
          ):
              for _ in range(iterations):
                  dataset_results.append(sess.run(ops_to_run))
      return dataset_results
  
imports: import math
  import numpy
  import nvidia.dali.fn
  import nvidia.dali.plugin.tf
  import nvidia.dali.types
  import os
  import tensorflow
  from contextlib import contextmanager
  from nose import SkipTest
  from nvidia.dali.pipeline import Pipeline
  from tensorflow.python.client import device_lib
  from test_utils import to_array, get_dali_extra_path
label_desc: Use image node_id 12 for calling a global function with example usage: run_dataset_in_graph(dali_datasets, iterations, to_stop_iter) and returns: dataset_results