ImageDataBunch.from_name_re breaks in colab environment

In colab environment fastai v1.0.60 is already there. while running the notebook of first lession, I encountered an error for ImageDataBunch.from_name_re function.

RuntimeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in _check_kwargs(ds, tfms, **kwargs)
593 x = ds[0]
–> 594 try: x.apply_tfms(tfms, **kwargs)
595 except Exception as e:

11 frames
RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #3 ‘mat2’ in call to _th_addmm_out

During handling of the above exception, another exception occurred:

Exception Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in _check_kwargs(ds, tfms, **kwargs)
594 try: x.apply_tfms(tfms, **kwargs)
595 except Exception as e:
–> 596 raise Exception(f"It’s not possible to apply those transforms to your dataset:\n {e}")
597
598 class LabelList(Dataset):

Exception: It’s not possible to apply those transforms to your dataset:
Expected object of scalar type Float but got scalar type Double for argument #3 ‘mat2’ in call to _th_addmm_out

Now even if there is an update for this fix, How do I update the pre-exesting fastai library in my google colab.

Also looks like google colab has installed the latest release tag only which is v1.0.60. That release has happened in dec 2019 after that even if there are any fixes, The library is not getting updated with the fixes.

The problem is possibly with the tfms=get_transforms() line in this cell

bs = 128
data_f = ImageDataBunch.from_name_re(path=path, 
                                   pat='([^/]+)_\d+.jpg$',
                                   fnames=img_paths3, test="/content/test/",
                                   ds_tfms=get_transforms(),   <- This line
                                   bs=bs, size=48)

So remove it.
I got the same error too when not using the Oxford dogs dataset.

People here are facing same problem

!pip uninstall torch torchvision -y
!pip install torch==1.4.0 torchvision==0.5.0

Put these two line at the top of the notebook and run it. Restart the runtime and you are good to go. torch updated the release version on 21 april and fastai v1.0.60 became incompatable. although fastai has fixed the issue to make it compatable but unless someboday has installed fastai from source itself, getting the fixed changes is difficult. fastai need to create another relaese with updated changes.

4 Likes