from fastai.gen_doc.nbdoc import * from fastai.vision import * from fastai.callbacks import * path = untar_data(URLs.MNIST_SAMPLE) data = ImageDataBunch.from_folder(path) show_doc(TerminateOnNaNCallback) model = simple_cnn((3,16,16,2)) learn = Learner(data, model, metrics=[accuracy]) learn.fit_one_cycle(1,1e4) model = simple_cnn((3,16,16,2)) learn = Learner(data, model, metrics=[accuracy], callbacks=[TerminateOnNaNCallback()]) learn.fit(2,1e4) show_doc(TerminateOnNaNCallback.on_batch_end) show_doc(TerminateOnNaNCallback.on_epoch_end) show_doc(EarlyStoppingCallback) model = simple_cnn((3,16,16,2)) learn = Learner(data, model, metrics=[accuracy], callback_fns=[partial(EarlyStoppingCallback, monitor='accuracy', min_delta=0.01, patience=3)]) learn.fit(50,1e-42) show_doc(EarlyStoppingCallback.on_train_begin) show_doc(EarlyStoppingCallback.on_epoch_end) show_doc(SaveModelCallback) model = simple_cnn((3,16,16,2)) learn = Learner(data, model, metrics=[accuracy]) learn.fit_one_cycle(5,1e-4, callbacks=[SaveModelCallback(learn, every='epoch', monitor='accuracy', name='model')]) !ls ~/.fastai/data/mnist_sample/models learn.fit_one_cycle(5,1e-4, callbacks=[SaveModelCallback(learn, every='improvement', monitor='accuracy', name='best')]) !ls ~/.fastai/data/mnist_sample/models show_doc(SaveModelCallback.on_epoch_end) show_doc(SaveModelCallback.on_train_end) show_doc(ReduceLROnPlateauCallback) show_doc(ReduceLROnPlateauCallback.on_train_begin) show_doc(ReduceLROnPlateauCallback.on_epoch_end) show_doc(TrackerCallback) show_doc(TrackerCallback.get_monitor_value) show_doc(TrackerCallback.on_train_begin)