Guest User

Untitled

a guest
Sep 8th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import tensorflow as tf
  2. import os
  3.  
  4. mnist = tf.keras.datasets.mnist
  5.  
  6. (x_train, y_train),(x_test, y_test) = mnist.load_data()
  7.  
  8. print(x_train[0])
  9.  
  10. x_train = tf.keras.utils.normalize(x_train, axis=0)
  11. x_test = tf.keras.utils.normalize(x_test, axis=0)
  12.  
  13. print(x_test[0].size)
  14.  
  15. #path = "training_1/sp.ckpt"
  16. #checkpoint_dir = os.path.dirname(path)
  17.  
  18. #cp_callback = tf.keras.callbacks.ModelCheckpoint(path, save_weights_only = True, verbose = 1)
  19.  
  20. model = tf.keras.models.Sequential()
  21. model.add(tf.keras.layers.Flatten())
  22. model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
  23. model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
  24. model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))
  25.  
  26. model.compile(optimizer = "adam",
  27.               loss="sparse_categorical_crossentropy",
  28.               metrics= ["accuracy"])
  29.  
  30.  
  31. model.fit(x_train, y_train,  epochs = 1)
  32. model.save("number.h5")
Advertisement
Add Comment
Please, Sign In to add comment