I am exploring callbacks in v2. Here is the code:
def __init__(self,learn:Learner,weights:torch.Tensor=None): super().__init__(learn) self.weights = weights print('Init') def on_train_begin(self, **kwargs): print('Inside Train Begin')
learn = cnn_learner( dl, resnet34, metrics=error_rate)
cb = TestCallback(learn) #this prints “Init”
learn.add_cb(cb) #AttributeError: ‘Learner’ object has no attribute ‘name’
Is my function within the callback class (on_train_begin) right or do I need to change the name of the function?
How do I add a custom callback to the cnn_learner object? My way of adding gives ‘Atttribute Error’. Further, this line too seems to not work: learn.fit_one_cycle(2, cbs = cb)
When creating a cnn_learner object, I see there is a property called “cbs”. When creating a cnn_learner object, the callbacks I pass to this cbs property should be the ones that do not require a learner object?
learner = cnn_learner(DL, resnet34, metrics=error_rate, cbs= ??)