You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm reading the course-v3 ***.ipynb , https://github.com/fastai/course-v3/blob/master/nbs/dl2/09_optimizers.ipynb , and I was wondering whether should I use "self.opt" or "self.run.opt" in the callbackhanders. such as: "class Recorder(Callback):" ,"class ParamScheduler(Callback):" and so on.
here is the code I am geting confused:
classRecorder(Callback):
defbegin_fit(self): self.lrs,self.losses= [],[]
defafter_batch(self):
ifnotself.in_train: return#or using: if not self.run.in_train: returnself.lrs.append(self.opt.hypers[-1]['lr']) #or using: self.lrs.append(self.run.opt.hypers[-1]['lr']) self.losses.append(self.loss.detach().cpu()) #or using: self.losses.append(self.run.loss.detach().cpu()) classParamScheduler(Callback):
_order=1def__init__(self, pname, sched_funcs):
self.pname,self.sched_funcs=pname,listify(sched_funcs)
defbegin_batch(self):
ifnotself.in_train: returnfs=self.sched_funcsiflen(fs)==1: fs=fs*len(self.opt.param_groups) #or using: if len(fs)==1: fs = fs*len(self.run.opt.param_groups)pos=self.n_epochs/self.epochs#or using: pos = self.run.n_epochs/self.run.epochsforf,hinzip(fs,self.opt.hypers): h[self.pname] =f(pos) #or using: for f,h in zip(fs,self.run.opt.hypers): h[self.pname] = f(pos)
Because , I find the attributes: "opt , loss,n_epochs, epochs.... " are only defined in the Learner(), they are passed to every CallbackHander by the Callback() class through the code:
Hi,
I'm reading the course-v3 ***.ipynb , https://github.com/fastai/course-v3/blob/master/nbs/dl2/09_optimizers.ipynb , and I was wondering whether should I use "self.opt" or "self.run.opt" in the callbackhanders. such as: "class Recorder(Callback):" ,"class ParamScheduler(Callback):" and so on.
here is the code I am geting confused:
Because , I find the attributes: "opt , loss,n_epochs, epochs.... " are only defined in the Learner(), they are passed to every CallbackHander by the Callback() class through the code:
The text was updated successfully, but these errors were encountered: