Starting the training

Start a TensorFlow Session and initialize all the variables:

sess = tf.Session()
sess.run(tf.global_variables_initializer())

Train the model for 1000 epochs. Print the results for every 100 epochs:

for epoch in range(1000):

#select some batch of data points according to the batch size (100)
X_batch, y_batch = mnist.train.next_batch(batch_size=100)


#train the network
loss, acc, _ = sess.run([cross_entropy, accuracy, optimizer], feed_dict={X_: X_batch, y: y_batch})


#print the loss on every 100th epoch
if epoch%100 == 0:
print('Epoch: {}, Loss:{} Accuracy: {}'.format(epoch,loss,acc))

You will notice that the loss decreases and the accuracy increases over epochs:

Epoch: 0, Loss:631.2734375 Accuracy: 0.129999995232
Epoch: 100, Loss:28.9199733734 Accuracy: 0.930000007153
Epoch: 200, Loss:18.2174377441 Accuracy: 0.920000016689
Epoch: 300, Loss:21.740688324 Accuracy: 0.930000007153
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset