Nbs 15 and 16A - AttributeError: object has no attribute

Hey all,

I ran into some unexpected errors in notebooks 15 and 16A:

AttributeError: ‘DDPMCB’ object has no attribute ‘n_inp’
(from: …/notebooks/course22p2/nbs/15_DDPM.ipynb)

AttributeError: ‘_OpNamespace’ ‘image’ object has no attribute ‘decode_image’
(from: …/notebooks/course22p2/nbs/16A_StyleTransfer-Copy1.ipynb)

The missing ‘n_inp’ attribute appears to be caused by the DDPMCB object not inheriting from TrainCB, but when I got the other AttributeError in notebook 16A, I suspected they have the same cause, somewhere in the lib installs.

Has anyone else encountered this, and maybe found a solution?

Here’s the full stack trace:

0.00% [0/5 00:00<?]
0.00% [0/469 00:00<?]

AttributeError                            Traceback (most recent call last)
Cell In[30], line 1
----> 1 learn.fit(epochs)

File ~/projects/fastai/course22p2/miniai/learner.py:177, in Learner.fit(self, n_epochs, train, valid, cbs, lr)
    175     with self.cb_ctx('fit'):
    176         for self.epoch in self.epochs:
--> 177             if train: self.one_epoch(True)
    178             if valid: torch.no_grad()(self.one_epoch)(False)
    179 finally:

File ~/projects/fastai/course22p2/miniai/learner.py:157, in Learner.one_epoch(self, train)
    155 self.predict()
    156 self.callback('after_predict')
--> 157 self.get_loss()
    158 self.callback('after_loss')
    159 if self.training:

File ~/projects/fastai/course22p2/miniai/learner.py:186, in Learner.callback(self, method_nm)
--> 186 def callback(self, method_nm): run_cbs(self.cbs, method_nm, self)

File ~/projects/fastai/course22p2/miniai/learner.py:50, in run_cbs(cbs, method_nm, learn)
     48 for cb in sorted(cbs, key=attrgetter('order')):
     49     method = getattr(cb, method_nm, None)
---> 50     if method is not None: method(learn)

File ~/projects/fastai/course22p2/miniai/learner.py:101, in TrainCB.get_loss(self, learn)
--> 101 def get_loss(self, learn): learn.loss = learn.loss_func(learn.preds, *learn.batch[self.n_inp:])

AttributeError: 'DDPMCB' object has no attribute 'n_inp'

Neverrmind. I cleaned up and did some re-installs of the conda base environment.
…crisis averted

1 Like

I bumped into similar problem, the issue was that I did not have libjpeg and libpng before installing torch vision. Steps to fix this

sudo apt-get install libpng-dev libjpeg-dev
pip install --upgrade --force-reinstall torchvision