How to do it...

  1. We will start by loading the necessary libraries for our script.
import tensorflow as tffrom sklearn.preprocessing import MultiLabelBinarizerfrom keras.utils import to_categoricalfrom tensorflow import kerasfrom tensorflow.python.framework import opsops.reset_default_graph()# Load MNIST datafrom tensorflow.examples.tutorials.mnist import input_data
  1. We can load the library with the provided MNIST data import function in TensorFlow.  Although the original MNIST images are 28 pixels by 28 pixels, the imported data is a flattened version of them, where each observation is a row of 784 greyscale points between 0 and 1.  The y-labels are imported as integers between 0 and 9.
mnist = input_data.read_data_sets("MNIST_data/")

Get TensorFlow Machine Learning Cookbook - Second Edition 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.