from fastai.gen_doc.nbdoc import * from fastai.callbacks.general_sched import * from fastai.vision import * show_doc(TrainingPhase) show_doc(TrainingPhase.schedule_hp) jekyll_note("""If you want to use discriminative values, you can pass an numpy array in `vals` (or a tuple of them for start and stop).""") def fit_sgd_warm(learn, n_cycles, lr, mom, cycle_len, cycle_mult): n = len(learn.data.train_dl) phases = [(TrainingPhase(n * (cycle_len * cycle_mult**i)) .schedule_hp('lr', lr, anneal=annealing_cos) .schedule_hp('mom', mom)) for i in range(n_cycles)] sched = GeneralScheduler(learn, phases) learn.callbacks.append(sched) if cycle_mult != 1: total_epochs = int(cycle_len * (1 - (cycle_mult)**n_cycles)/(1-cycle_mult)) else: total_epochs = n_cycles * cycle_len learn.fit(total_epochs) path = untar_data(URLs.MNIST_SAMPLE) data = ImageDataBunch.from_folder(path) learn = Learner(data, simple_cnn((3,16,16,2)), metrics=accuracy) fit_sgd_warm(learn, 3, 1e-3, 0.9, 1, 2) learn.recorder.plot_lr() show_doc(GeneralScheduler) show_doc(GeneralScheduler.on_batch_end, doc_string=False) show_doc(GeneralScheduler.on_train_begin, doc_string=False)