import tensorflow as tf
class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self,epoch,logs={}):
if logs.get('acc')>0.99:
print('\nReaching 99% accuracy so cancelling training')
self.model.stop_training = True
def train():
callback = myCallback()
model = tf.keras.Sequential([tf.keras.layers.Flatten(input_shape = (28,28)),
tf.keras.layers.Dense(512,activation = tf.nn.relu),
])
model.compile(optimizer='adam',loss='',metrics='')
history = model.fit(x,y,epochs=10,callbacks=[callback])
转载于:https://www.cnblogs.com/rise0111/p/11382246.html