Setting up input pipelines for training and testing

TensorFlow allows us to create a reliable input pipeline for quick and easy training. In this section, we will implement tf.TextLineReader to read the train and test text files. We will use tf.train.batch to read and preprocess images in parallel.

First, we need to create a new Python file named datasets.py in the project directory and add the following code:

 import tensorflow as tf import os def load_files(filenames): filename_queue = tf.train.string_input_producer(filenames) line_reader = tf.TextLineReader() key, line = line_reader.read(filename_queue) label, image_path = tf.decode_csv(records=line, record_defaults=[tf.constant([], dtype=tf.int32), tf.constant([], dtype=tf.string)], field_delim=' ...

Get Machine Learning with TensorFlow 1.x now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.