July 2019
Intermediate to advanced
512 pages
19h 39m
English
Now, it is time to train our model. As we have learned, first, we need to initialize all of the variables:
init = tf.global_variables_initializer()
Define the batch size, number of iterations, and learning rate, as follows:
learning_rate = 1e-4num_iterations = 1000batch_size = 128
Start the TensorFlow session:
with tf.Session() as sess:
Initialize all the variables:
sess.run(init)
Save the event files:
summary_writer = tf.summary.FileWriter('./graphs', graph=sess.graph)
Train the model for a number of iterations:
for i in range(num_iterations):
Get a batch of data according to the batch size:
batch_x, batch_y = mnist.train.next_batch(batch_size)
Train the network:
sess.run(optimizer, feed_dict={ X: batch_x, Y: batch_y}) ...Read now
Unlock full access