code: def read_and_decode(filename):
      batchsize = 4
      raw_dataset = (
          tf.data.TFRecordDataset([filename])
          .shuffle(1000)
          .batch(batchsize)
      )
      features = {}
      for serialized_example in raw_dataset:
          features["label"] = tf.io.FixedLenFeature([], tf.int64)
          features["img_raw"] = tf.io.FixedLenFeature([], tf.string)
          features = tf.io.parse_example(serialized_example, features)
          # You can do more image distortion here for training data
          img_batch = tf.io.decode_raw(features["img_raw"], tf.uint8)
          img_batch = tf.reshape(img_batch, [-1, 32, 32, 3])
          # img = tf.cast(img, tf.float32) #* (1. / 255) - 0.5    # don't need to cast here, as it is float32 already
          label_batch = tf.cast(features["label"], tf.int32)
          yield img_batch, label_batch
  
imports: import os
  import numpy
  import tensorflow
  import tensorlayer
label_desc: Use image node_id 1 for calling a global function with example usage: read_and_decode(filename) without return types