code: def example3():
      """Example 3: Using TF dataset API to load and process image for training"""
      n_data = 100
      imgs_file_list = ["data/tiger.jpeg"] * n_data
      train_targets = [np.ones(1)] * n_data
  
      def generator():
          if len(imgs_file_list) != len(train_targets):
              raise RuntimeError(
                  "len(imgs_file_list) != len(train_targets)"
              )
          for _input, _target in zip(imgs_file_list, train_targets):
              yield _input, _target
  
      def _data_aug_fn(image):
          transform_matrix = create_transformation_matrix()
          result = tl.prepro.affine_transform_cv2(
              image, transform_matrix
          )  # Transform the image using a single operation
          return result
  
      def _map_fn(image_path, target):
          image = tf.io.read_file(image_path)
          image = tf.image.decode_jpeg(
              image, channels=3
          )  # Get RGB with 0~1
          image = tf.image.convert_image_dtype(image, dtype=tf.float32)
          image = tf.numpy_function(
              _data_aug_fn, [image], [tf.float32]
          )[0]
          target = tf.reshape(target, ())
          return image, target
  
      n_epoch = 10
      batch_size = 5
      dataset = tf.data.Dataset.from_generator(
          generator, output_types=(tf.string, tf.int64)
      )
      dataset = dataset.shuffle(
          buffer_size=4096
      )  # shuffle before loading images
      dataset = dataset.repeat(n_epoch)
      dataset = dataset.batch(
          batch_size
      )  # TODO: consider using tf.contrib.map_and_batch
      dataset = dataset.map(
          _map_fn, num_parallel_calls=multiprocessing.cpu_count()
      )
      dataset = dataset.prefetch(1)  # prefetch 1 batch
  
      n_step = 0
      st = time.time()
      for img, target in dataset:
          n_step += 1
          pass
      assert n_step == n_epoch * n_data / batch_size
      print(
          "dataset APIs took %fs for each image"
          % ((time.time() - st) / batch_size / n_step)
      )
  
file_path: TensorLayer/examples/data_process/tutorial_fast_affine_transform.py
imports: import multiprocessing
  import time
  import numpy
  import cv2
  import tensorflow
  import tensorlayer
label_desc: Use image node_id 4 for calling a global function with example usage: example3() and returns: result, image,  target