callbacks tensorflow 2 0

Solutions on MaxInterview for callbacks tensorflow 2 0 by the best coders in the world

showing results for - "callbacks tensorflow 2 0"
Liam
24 Oct 2017
1import tensorflow as tf
2
3class 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
9mnist = tf.keras.datasets.fashion_mnist
10
11(x_train, y_train),(x_test, y_test) = mnist.load_data()
12x_train, x_test = x_train / 255.0, x_test / 255.0
13
14callbacks = myCallback()
15
16model = 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])
21model.compile(optimizer=tf.optimizers.Adam(),
22              loss='sparse_categorical_crossentropy',
23              metrics=['accuracy'])
24
25model.fit(x_train, y_train, epochs=10, callbacks=[callbacks])