Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in the lesson #5 #122

Closed
sergei-bondarenko opened this issue Jan 30, 2018 · 3 comments
Closed

Problem in the lesson #5 #122

sergei-bondarenko opened this issue Jan 30, 2018 · 3 comments

Comments

@sergei-bondarenko
Copy link

In the "Collaborative filtering" section got the error when trying to learn.fit:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-8cf2e7ab9f6b> in <module>()
----> 1 learn.fit(1e-2, 2, wds=wd, cycle_len=1, cycle_mult=2, use_wd_sched=True)

~/courses/fastai/courses/dl1/fastai/learner.py in fit(self, lrs, n_cycle, wds, **kwargs)
    207         self.sched = None
    208         layer_opt = self.get_layer_opt(lrs, wds)
--> 209         return self.fit_gen(self.model, self.data, layer_opt, n_cycle, **kwargs)
    210 
    211     def warm_up(self, lr, wds=None):

~/courses/fastai/courses/dl1/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, use_clr, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, **kwargs)
    154         n_epoch = sum_geom(cycle_len if cycle_len else 1, cycle_mult, n_cycle)
    155         return fit(model, data, n_epoch, layer_opt.opt, self.crit,
--> 156             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, **kwargs)
    157 
    158     def get_layer_groups(self): return self.models.get_layer_groups()

~/courses/fastai/courses/dl1/fastai/model.py in fit(model, data, epochs, opt, crit, metrics, callbacks, **kwargs)
     78     avg_mom=0.98
     79     batch_num,avg_loss=0,0.
---> 80     for cb in callbacks: cb.on_train_begin()
     81     names = ["epoch", "trn_loss", "val_loss"] + [f.__name__ for f in metrics]
     82     layout = "{!s:10} " * len(names)

AttributeError: 'NoneType' object has no attribute 'on_train_begin'
@interogativ
Copy link

The reason for this is that the model fit function requires a callback class reference and for the attributes of that reference to have been initialized. While this is normally done for the user in the calling subclass (learner) it is not done in lesson 5 because Jeremy has you building this yourself. So you have two choices:

  1. define you own callback class with the appropriate attributes.
  2. Make the changes to the model fit routine to check to see if the callbacks class and attributes are appropriately defined before using them as suggested here

@interogativ
Copy link

@sergei-bondarenko
Copy link
Author

It's fixed now.

borisdayma pushed a commit to borisdayma/fastai that referenced this issue Aug 18, 2020
fix datablock.summary device error if normalize is a batch_tfm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants