Neural networks in TensorFlow
Now, we will see how to build a basic neural network using TensorFlow, which predicts handwritten digits. We will use the popular MNIST dataset which has a collection of labeled handwritten images for training.
First, we must import TensorFlow and load the dataset from tensorflow.examples.tutorial.mnist
:
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
Now, we will see what we have in our data:
print("No of images in training set {}".format(mnist.train.images.shape)) print("No of labels in training set {}".format(mnist.train.labels.shape)) print("No of images in test set {}".format(mnist.test.images.shape)) print("No of labels in test set {}".format(mnist.test.labels.shape))
It will print the following:
No of images in training set (55000, 784) No of labels in training set (55000, 10) No of images in test set (10000, 784) No of labels in test set (10000, 10)
We have 55000...