Code example in A Layered API for Deep Learning

I’m going over https://www.fast.ai/2020/02/13/fastai-A-Layered-API-for-Deep-Learning/ and I’m unable to run the first vision code example:

>>> import fastai
>>> fastai.__version__
'1.0.60'

>>> from fastai.vision.all import *
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-5635efd54484> in <module>
----> 1 from fastai.vision.all import *

ModuleNotFoundError: No module named 'fastai.vision.all'

This should be from fastai2.vision.all (as it’s on the new v2 version of the library)

@jeremy pinging you on this (should this be adjusted or is the end goal for it to be like this?)

Thanks for your quick reply!
I did try fastai2 before posting and the code breaks here:

dls = ImageDataLoaders.from_name_re(
...
AssertionError: Failed to find "re.compile('/([^/]+)_\\d+.jpg$')" in "german_shorthaired_9.jpg"

After fixing the regex, then the code breaks here:

learn.fit_one_cycle(4)
...
~/miniconda3/envs/py37/lib/python3.7/site-packages/fastcore/foundation.py in __getattr__(self, k)
    221             attr = getattr(self,self._default,None)
    222             if attr is not None: return getattr(attr, k)
--> 223         raise AttributeError(k)
    224     def __dir__(self): return custom_dir(self, self._dir() if self._xtra is None else self._dir())
    225 #     def __getstate__(self): return self.__dict__

AttributeError: _IterableDataset_len_called

The _IterableDataset issue is due to the most recent torchvision. It’s recommended to use torch 1.3.1 and torchvision 0.4.2 (along with Pillow 6.2.1)

1 Like

Those versions work, it trained in 25 secs/epoch!
I just had to change:

pat = r'/([^/]+)_\d+.jpg

to

pat = r'([^/]+)_\d+.jpg

Does it make sense to add a function fastai.check_lib_versions() to check for the recommended library versions?

Yes the paper is written based on how things will be after fastai2 is released. At that time it’ll just be fastai.

1 Like

BTW best place to discuss fastai2 and the paper is: #fastai-users:fastai-v2

1 Like