Member-only story
Using TFRecords to Train a CNN on MNIST
A short walkthrough on writing, reading and using TFRecords
When I started with TFRecords, it took me a while to understand its concept. There were so many new things. To save others from this hassle, I have created a hands-on walkthrough based on the MNIST dataset.
Note: this blog post is now available in a more general version which includes more up-to-date concepts. Further, also note that the TFRecord format is not that hard once you’ve got started, which is why I’ve created a hands-on introduction to it. To learn more, after this tutorial I recommend you to consult these two resources.
Overview
The MNIST dataset consists of digitized handwritten digits in black and white. With 28x28x1 per image, they are pretty small. The memory footprint of the complete dataset is only 32 MB.
Imports and helper functions
Let us start with the necessary imports; two libraries, os and Tensorflow. Additionally, we set a global variable, AUTOTUNE, which we use later.

