1.As custom pytorch optimiser :
def opt_func(params,lr,**kwargs): return OptimWrapper(torch.optim.Adam(params, lr))
learn = Learner(dsets,vgg.cuda(), metrics=accuracy , opt_func=opt_func(vgg.classifier.parameters(),2e-3))
learn.fit_one_cycle(2,5e-3)
/usr/local/lib/python3.6/dist-packages/fastai/callback/schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
105 moms=None, cbs=None, reset_opt=False):
106 “Fit self.model
for n_epoch
using the 1cycle policy.”
–> 107 if self.opt is None: self.create_opt()
108 self.opt.set_hyper(‘lr’, self.lr if lr_max is None else lr_max)
109 lr_max = np.array([h[‘lr’] for h in self.opt.hypers])
/usr/local/lib/python3.6/dist-packages/fastai/learner.py in create_opt(self)
147 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)
148 def create_opt(self):
–> 149 self.opt = self.opt_func(self.splitter(self.model), lr=self.lr)
150 if not self.wd_bn_bias:
151 for p in self._bn_bias_state(True ): p[‘do_wd’] = False
TypeError: ‘OptimWrapper’ object is not callable
2.fast ai adam:
learn = Learner(dsets,vgg.cuda(), metrics=accuracy , opt_func=Adam(params=vgg.classifier.parameters(),lr=2e-3))
learn.fit_one_cycle(2,5e-3)
/usr/local/lib/python3.6/dist-packages/fastai/callback/schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
105 moms=None, cbs=None, reset_opt=False):
106 “Fit self.model
for n_epoch
using the 1cycle policy.”
–> 107 if self.opt is None: self.create_opt()
108 self.opt.set_hyper(‘lr’, self.lr if lr_max is None else lr_max)
109 lr_max = np.array([h[‘lr’] for h in self.opt.hypers])
/usr/local/lib/python3.6/dist-packages/fastai/learner.py in create_opt(self)
147 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)
148 def create_opt(self):
–> 149 self.opt = self.opt_func(self.splitter(self.model), lr=self.lr)
150 if not self.wd_bn_bias:
151 for p in self._bn_bias_state(True ): p[‘do_wd’] = False
TypeError: ‘Optimizer’ object is not callable