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])
相关文章
- 02-20Synchronous/Asynchronous:任务的同步异步,以及asynchronous callback异步回调
- 02-20client-side callback
- 02-20async callback z
- 02-20[Vue warn]: Error in callback for watcher "fileList": "TypeError: Cannot create prope
- 02-20callback回调函数
- 02-20why my custom callback is not called
- 02-20scrapy callback无效
- 02-20callback
- 02-20/usr/lib64/python2.6/site-packages/pycurl.so: undefined symbol: CRYPTO_set_locking_callback
- 02-20UVM设计模式 笔记(四)迭代器模式、Python/SV中的迭代器、uvm_callback_iter、scoreboard中的迭代器