While listing all the image files and then iterating to open and parse them is a straightforward pipeline solution, it can be suboptimal. Loading and parsing image files one by one is resource-consuming. Storing a large number of images together into a binary file would make the read-from-disk operations (or streaming operations for remote files) much more efficient. Therefore, TensorFlow users are often advised to use the TFRecord file format, based on Google's Protocol Buffers, a language-neutral, platform-neutral extensible mechanism for serializing structured data (refer to the documentation at https://developers.google.com/protocol-buffers).
TFRecord files are binary files aggregating data samples (such as images, labels, and metadata). A TFRecord file contains serialized tf.train.Example instances, which are basically dictionaries naming each data element (called features according to this API) composing the sample (for example, {'img': image_sample1...