callback

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])
    
上一篇:TensorFlow 2.0 版本安装教程+CNN图像mnist手写数字识别实战代码-CNN图像识别


下一篇:车道线-论文阅读: Learning Lightweight Lane Detection CNNs by Self Attention Distillation