Search⌘ K
AI Features

TFRecords Dataset

Explore how to create and configure TFRecords datasets in TensorFlow. Understand parsing serialized Examples, applying dataset shuffling, repetition, and batching to build an effective input pipeline for scalable machine learning projects.

Chapter Goals:

  • Create a TFRecords dataset for the input pipeline

A. Dataset from TFRecords file

After setting up the Example spec and feature parsing functions, we’re finally ready to create TensorFlow datasets from the TFRecords files for both training and evaluation.

Python 3.5
import tensorflow as tf
train_file = 'train.tfrecords'
eval_file = 'eval.tfrecords'
train_dataset = tf.data.TFRecordDataset(train_file)
eval_dataset = tf.data.TFRecordDataset(eval_file)

The TFRecords datasets contain serialized Example objects. Using the Example spec and feature parsing functions, we can convert each serialized Example to a tuple ...