Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import tensorflow as tf
  2.  
  3. class myCallback(tf.keras.callbacks.Callback):
  4. def on_epoch_end(self, epoch, logs={}):
  5. if(logs.get('acc')>0.6):
  6. print("\nReached 60% accuracy so cancelling training!")
  7. self.model.stop_training = True
  8.  
  9. mnist = tf.keras.datasets.fashion_mnist
  10.  
  11. (x_train, y_train),(x_test, y_test) = mnist.load_data()
  12. x_train, x_test = x_train / 255.0, x_test / 255.0
  13.  
  14. callbacks = myCallback()
  15.  
  16. model = tf.keras.models.Sequential([
  17. tf.keras.layers.Flatten(input_shape=(28, 28)),
  18. tf.keras.layers.Dense(512, activation=tf.nn.relu),
  19. tf.keras.layers.Dense(10, activation=tf.nn.softmax)
  20. ])
  21. model.compile(optimizer='adam',
  22. loss='sparse_categorical_crossentropy',
  23. metrics=['accuracy'])
  24.  
  25. model.fit(x_train, y_train, epochs=10, callbacks=[callbacks])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement