--- title: Callback keywords: fastai sidebar: home_sidebar summary: "Miscellaneous callbacks for timeseriesAI." description: "Miscellaneous callbacks for timeseriesAI." nb_path: "nbs/060_callback.core.ipynb" ---
A callback can implement actions on the following events:
When writing a callback, the following attributes of Learner are available:
The following attributes are added by TrainEvalCallback and should be available unless you went out of your way to remove that callback:
The following attribute is added by Recorder and should be available unless you went out of your way to remove that callback:
from tsai.data.all import *
from tsai.models.InceptionTime import *
from tsai.models.layers import *
dsid = 'NATOPS'
X, y, splits = get_UCR_data(dsid, return_split=False)
tfms = [None, Categorize()]
dsets = TSDatasets(X, y, tfms=tfms, splits=splits)
dls = TSDataLoaders.from_dsets(dsets.train, dsets.valid, bs=[64, 128])
loss_func = gambler_loss()
learn = Learner(dls, InceptionTime(dls.vars, dls.c + 1), loss_func=loss_func, cbs=GamblersCallback, metrics=[accuracy])
learn.fit_one_cycle(1)
TransformScheduler(SchedCos(1, 0))
p = torch.linspace(0.,1,100)
f = combine_scheds([0.3, 0.4, 0.3], [SchedLin(1.,1.), SchedCos(1.,0.), SchedLin(0.,.0), ])
plt.plot(p, [f(o) for o in p]);
p = torch.linspace(0.,1,100)
f = combine_scheds([0.3, 0.7], [SchedCos(0.,1.), SchedCos(1.,0.)])
plt.plot(p, [f(o) for o in p]);
from tsai.data.all import *
from tsai.models.all import *
dsid = 'NATOPS'
X, y, splits = get_UCR_data(dsid, return_split=False)
tfms = [None, Categorize()]
dsets = TSDatasets(X, y, tfms=tfms, splits=splits)
dls = TSDataLoaders.from_dsets(dsets.train, dsets.valid, batch_tfms=[TSStandardize()])
model = create_model(InceptionTime, dls=dls)
TS_tfms = [TSMagScale(.75, p=.5), TSMagWarp(.1, p=0.5), TSWindowWarp(.25, p=.5),
TSSmooth(p=0.5), TSRandomResizedCrop(.1, p=.5),
TSRandomCropPad(.3, p=0.5),
TSMagAddNoise(.5, p=.5)]
ubda_cb = UBDAug(TS_tfms, N=2, C=4, S=2)
learn = Learner(dls, model, cbs=ubda_cb, metrics=accuracy)
learn.fit_one_cycle(1)