July 2019
Intermediate to advanced
512 pages
19h 39m
English
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: ...
Read now
Unlock full access