fastai / course-v3

The 3rd edition of course.fast.ai
https://course.fast.ai/
Apache License 2.0
4.91k stars 3.57k forks source link

Lesson 1 - What's your pet - Missing imports, error show data bunch and cnn_learner is not defined. #247

Closed ghost closed 5 years ago

ghost commented 5 years ago

python version: 3.6.8 fastai version: 1.0.34

I downloaded the notebook from https://github.com/fastai/course-v3/blob/master/nbs/dl1/lesson1-pets.ipynb I installed jupyter notebook, pytorch and fastai using conda (https://docs.fast.ai/install.html)

Issue 1 of 3: When running the notebook from fastai import * is missing from the initial imports as shown in the video instructions, so I added it.

Issue 2 of 3: When running data.show_batch(rows=3, figsize=(7,6)) I receive the following error:

RuntimeError                              Traceback (most recent call last)
<ipython-input-11-66824b983385> in <module>()
----> 1 data.show_batch(rows=3, figsize=(7,6))

~/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/basic_data.py in show_batch(self, rows, ds_type, **kwargs)
    151     def show_batch(self, rows:int=5, ds_type:DatasetType=DatasetType.Train, **kwargs)->None:
    152         "Show a batch of data in `ds_type` on a few `rows`."
--> 153         x,y = self.one_batch(ds_type, True, True)
    154         if self.train_ds.x._square_show: rows = rows ** 2
    155         xs = [self.train_ds.x.reconstruct(grab_idx(x, i, self._batch_first)) for i in range(rows)]

~/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/basic_data.py in one_batch(self, ds_type, detach, denorm)
    134         w = self.num_workers
    135         self.num_workers = 0
--> 136         try:     x,y = next(iter(dl))
    137         finally: self.num_workers = w
    138         if detach: x,y = to_detach(x),to_detach(y)

~/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/basic_data.py in __iter__(self)
     68     def __iter__(self):
     69         "Process and returns items from `DataLoader`."
---> 70         for b in self.dl:
     71             y = b[1][0] if is_listy(b[1]) else b[1]
     72             yield self.proc_batch(b)

~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/utils/data/dataloader.py in __next__(self)
    635                 self.reorder_dict[idx] = batch
    636                 continue
--> 637             return self._process_next_batch(batch)
    638 
    639     next = __next__  # Python 2 compatibility

~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/utils/data/dataloader.py in _process_next_batch(self, batch)
    656         self._put_indices()
    657         if isinstance(batch, ExceptionWrapper):
--> 658             raise batch.exc_type(batch.exc_msg)
    659         return batch
    660 

RuntimeError: Traceback (most recent call last):
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 138, in <listcomp>
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/data_block.py", line 486, in __getitem__
    x = x.apply_tfms(self.tfms, **self.tfmargs)
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/vision/image.py", line 113, in apply_tfms
    else: x = tfm(x)
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/vision/image.py", line 498, in __call__
    return self.tfm(x, *args, **{**self.resolved, **kwargs}) if self.do_run else x
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/vision/image.py", line 445, in __call__
    if args: return self.calc(*args, **kwargs)
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/vision/image.py", line 450, in calc
    if self._wrap: return getattr(x, self._wrap)(self.func, *args, **kwargs)
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/vision/image.py", line 167, in coord
    self.flow = func(self.flow, *args, **kwargs)
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/vision/transform.py", line 227, in symmetric_warp
    return _perspective_warp(c, targ_pts, invert)
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/vision/transform.py", line 213, in _perspective_warp
    return _apply_perspective(c, _find_coeffs(_orig_pts, targ_pts))
  File "/home/deeplearning/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/vision/transform.py", line 194, in _find_coeffs
    return torch.gesv(B,A)[0][:,0]
RuntimeError: b should have at least 2 dimensions, but has 1 dimensions instead

Issue 3 of 3: When running learn = cnn_learner(data, models.resnet34, metrics=error_rate) I receive:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-13-efdbe27853be> in <module>()
----> 1 learn = cnn_learner(data, models.resnet34, metrics=error_rate)

NameError: name 'cnn_learner' is not defined
ghost commented 5 years ago

Turns out I was on an older version which was installed using the installation guide provided.

What I ended up doing is:

conda uninstall pytorch
conda install fastai -c pytorch -c fastai

This removed pytorch and upgraded it. I found this post on the forums for it: https://forums.fast.ai/t/update-fastai-with-conda-doesnt-update-to-the-latest-version/33546/13