{"action":"opened","issue":{"url":"https://api.github.com/repos/fastai/fastai/issues/1084","repository_url":"https://api.github.com/repos/fastai/fastai","labels_url":"https://api.github.com/repos/fastai/fastai/issues/1084/labels{/name}","comments_url":"https://api.github.com/repos/fastai/fastai/issues/1084/comments","events_url":"https://api.github.com/repos/fastai/fastai/issues/1084/events","html_url":"https://github.com/fastai/fastai/issues/1084","id":377431477,"node_id":"MDU6SXNzdWUzNzc0MzE0Nzc=","number":1084,"title":"on_train_begin() missing 1 required positional argument: 'self' for custom callback","user":{"login":"jfilter","id":3450307,"node_id":"MDQ6VXNlcjM0NTAzMDc=","avatar_url":"https://avatars2.githubusercontent.com/u/3450307?v=4","gravatar_id":"","url":"https://api.github.com/users/jfilter","html_url":"https://github.com/jfilter","followers_url":"https://api.github.com/users/jfilter/followers","following_url":"https://api.github.com/users/jfilter/following{/other_user}","gists_url":"https://api.github.com/users/jfilter/gists{/gist_id}","starred_url":"https://api.github.com/users/jfilter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfilter/subscriptions","organizations_url":"https://api.github.com/users/jfilter/orgs","repos_url":"https://api.github.com/users/jfilter/repos","events_url":"https://api.github.com/users/jfilter/events{/privacy}","received_events_url":"https://api.github.com/users/jfilter/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-05T14:46:25Z","updated_at":"2018-11-05T14:46:25Z","closed_at":null,"author_association":"NONE","body":"**Describe the bug**\r\nCan't add a custom  callback. \r\n\r\n`TypeError: on_train_begin() missing 1 required positional argument: 'self'`\r\n\r\nInstalled version: 1.0.19, Python 3.6.6 on Ubuntu 16.04\r\n\r\n**To Reproduce**\r\n```\r\nlearn = RNNLearner.classifier(data_clas)\r\n\r\n@dataclass\r\nclass MyCallback(Callback):\r\n    pass\r\n\r\nlearn.fit_one_cycle(1, 1e-3, callbacks=[MyCallback])\r\n```\r\n**Expected behavior**\r\n\r\nNo TypeError exception\r\n\r\n**Additional context**\r\n```\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-18-6f946fbd1976> in <module>\r\n     11 # learn2.recorder.plot()\r\n     12 \r\n---> 13 learn2.fit_one_cycle(1, 1e-3, callbacks=[MyCallback])\r\n     14 \r\n     15 class_report(learn2)\r\n\r\n~/anaconda3/envs/fv1/lib/python3.6/site-packages/fastai/train.py in fit_one_cycle(learn, cyc_len, max_lr, moms, div_factor, pct_start, wd, callbacks, **kwargs)\r\n     20     callbacks.append(OneCycleScheduler(learn, max_lr, moms=moms, div_factor=div_factor,\r\n     21                                         pct_start=pct_start, **kwargs))\r\n---> 22     learn.fit(cyc_len, max_lr, wd=wd, callbacks=callbacks)\r\n     23 \r\n     24 def lr_find(learn:Learner, start_lr:Floats=1e-7, end_lr:Floats=10, num_it:int=100, stop_div:bool=True, **kwargs:Any):\r\n\r\n~/anaconda3/envs/fv1/lib/python3.6/site-packages/fastai/basic_train.py in fit(self, epochs, lr, wd, callbacks)\r\n    160         callbacks = [cb(self) for cb in self.callback_fns] + listify(callbacks)\r\n    161         fit(epochs, self.model, self.loss_func, opt=self.opt, data=self.data, metrics=self.metrics,\r\n--> 162             callbacks=self.callbacks+callbacks)\r\n    163 \r\n    164     def create_opt(self, lr:Floats, wd:Floats=0.)->None:\r\n\r\n~/anaconda3/envs/fv1/lib/python3.6/site-packages/fastai/basic_train.py in fit(epochs, model, loss_func, opt, data, callbacks, metrics)\r\n     72     cb_handler = CallbackHandler(callbacks, metrics)\r\n     73     pbar = master_bar(range(epochs))\r\n---> 74     cb_handler.on_train_begin(epochs, pbar=pbar, metrics=metrics)\r\n     75 \r\n     76     exception=False\r\n\r\n~/anaconda3/envs/fv1/lib/python3.6/site-packages/fastai/callback.py in on_train_begin(self, epochs, pbar, metrics)\r\n    192         self.state_dict['n_epochs'],self.state_dict['pbar'],self.state_dict['metrics'] = epochs,pbar,metrics\r\n    193         names = [(met.name if hasattr(met, 'name') else camel2snake(met.__class__.__name__)) for met in self.metrics]\r\n--> 194         self('train_begin', metrics_names=names)\r\n    195 \r\n    196     def on_epoch_begin(self)->None:\r\n\r\n~/anaconda3/envs/fv1/lib/python3.6/site-packages/fastai/callback.py in __call__(self, cb_name, call_mets, **kwargs)\r\n    185         \"Call through to all of the `CallbakHandler` functions.\"\r\n    186         if call_mets: [getattr(met, f'on_{cb_name}')(**self.state_dict, **kwargs) for met in self.metrics]\r\n--> 187         return [getattr(cb, f'on_{cb_name}')(**self.state_dict, **kwargs) for cb in self.callbacks]\r\n    188 \r\n    189     def on_train_begin(self, epochs:int, pbar:PBar, metrics:MetricFuncList)->None:\r\n\r\n~/anaconda3/envs/fv1/lib/python3.6/site-packages/fastai/callback.py in <listcomp>(.0)\r\n    185         \"Call through to all of the `CallbakHandler` functions.\"\r\n    186         if call_mets: [getattr(met, f'on_{cb_name}')(**self.state_dict, **kwargs) for met in self.metrics]\r\n--> 187         return [getattr(cb, f'on_{cb_name}')(**self.state_dict, **kwargs) for cb in self.callbacks]\r\n    188 \r\n    189     def on_train_begin(self, epochs:int, pbar:PBar, metrics:MetricFuncList)->None:\r\n\r\nTypeError: on_train_begin() missing 1 required positional argument: 'self'\r\n\r\n```\r\n"}}
{"actor":{"display_login":"jfilter"}}