Training the model

Once the neural network layers have been defined we train the model by calling method

autoencoder.partial_fit(batch_xs) for each batch of data:

for epoch in range(training_epochs):    avg_cost = 0.    total_batch = int(n_samples / batch_size)    # Loop over all batches    for i in range(total_batch):        batch_xs = get_random_block_from_data(X_train, batch_size)        # Fit training using batch data        cost = autoencoder.partial_fit(batch_xs)        # Compute average loss        avg_cost += cost / n_samples * batch_size    # Display logs per epoch step    if epoch % display_step == 0:        print("Epoch:", '%04d' % (epoch + 1), "cost=", avg_cost)print("Total cost: " + str(autoencoder.calc_total_cost(X_test)))

The cost of each epoch is printed:

('Epoch:', '0001', 'cost=', ...

Get Neural Network Programming with TensorFlow 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.