Load and parse the MNIST test set

To begin building your own TensorFlow model, load and parse the MNIST test set.

The following sample code loads and parses the MNIST test set:

// Load a test image and its correct label
std::string dataDir = "data/";
int testImageIndex = 0;
std::unique_ptr input = loadMnistImage(dataDir, testImageIndex);

The loadMnistImage helper function is not covered here. In simple terms, it parses the MNIST data files and returns an MnistImage struct for the requested image with a label and a 28*28=784 element array containing the data:

//Helper struct for loading MNIST data
struct MnistImage
{
unsigned int label;
float image[g_kMnistImageByteSize];
};
Previous Next