O'Reilly logo

Deep Learning with TensorFlow by Ahmed Menshawy, Md. Rezaul Karim, Giancarlo Zaccone

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Digit classifier

In this example, we'll define and train either a two-layer model or a convolutional model in the style of LeNet 5:

from six.moves import xrange   import tensorflow as tf import prettytensor as pt from prettytensor.tutorial import data_utils tf.app.flags.DEFINE_string(     'save_path', None, 'Where to save the model checkpoints.') FLAGS = tf.app.flags.FLAGS BATCH_SIZE = 50 EPOCH_SIZE = 60000 // BATCH_SIZE TEST_SIZE = 10000 // BATCH_SIZE

Since we are feeding our data as numpy arrays, we need to create placeholders in the graph. These must then be fed using the feed dict.

image_placeholder = tf.placeholder\                       (tf.float32, [BATCH_SIZE, 28, 28, 1])labels_placeholder = tf.placeholder\                       (tf.float32, [BATCH_SIZE, 10])tf.app.flags.DEFINE_string('model', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required