SHARE
TWEET

tf2 beginner

a guest Jun 30th, 2019 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from __future__ import absolute_import, division, print_function, unicode_literals
  2.  
  3. import tensorflow as tf
  4.  
  5. mnist = tf.keras.datasets.mnist
  6.  
  7. (x_train, y_train), (x_test, y_test) = mnist.load_data()
  8. x_train, x_test = x_train / 255.0, x_test / 255.0
  9.  
  10. model = tf.keras.models.Sequential([
  11.   tf.keras.layers.Flatten(input_shape=(28, 28)),
  12.   tf.keras.layers.Dense(128, activation='relu'),
  13.   tf.keras.layers.Dropout(0.2),
  14.   tf.keras.layers.Dense(10, activation='softmax')
  15. ])
  16.  
  17. model.compile(optimizer='adam',
  18.               loss='sparse_categorical_crossentropy',
  19.               metrics=['accuracy'])
  20.  
  21. model.fit(x_train, y_train, epochs=5)
  22.  
  23. model.evaluate(x_test, y_test)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top