PyTorch 1.5 not working with fastai

I get this stack trace when trying to run this command from the first lesson’s juptyer notebook.

data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(), size=224, bs=bs
                                  ).normalize(imagenet_stats)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python38\lib\site-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:

~\AppData\Local\Programs\Python\Python38\lib\site-packages\fastai\vision\image.py in apply_tfms(self, tfms, do_resolve, xtra, size, resize_method, mult, padding_mode, mode, remove_out)
    122                     x = tfm(x, size=_get_crop_target(size,mult=mult), padding_mode=padding_mode)
--> 123             else: x = tfm(x)
    124         return x.refresh()

~\AppData\Local\Programs\Python\Python38\lib\site-packages\fastai\vision\image.py in __call__(self, x, *args, **kwargs)
    523         "Randomly execute our tfm on `x`."
--> 524         return self.tfm(x, *args, **{**self.resolved, **kwargs}) if self.do_run else x
    525 

~\AppData\Local\Programs\Python\Python38\lib\site-packages\fastai\vision\image.py in __call__(self, p, is_random, use_on_y, *args, **kwargs)
    469         "Calc now if `args` passed; else create a transform called prob `p` if `random`."
--> 470         if args: return self.calc(*args, **kwargs)
    471         else: return RandTransform(self, kwargs=kwargs, is_random=is_random, use_on_y=use_on_y, p=p)

~\AppData\Local\Programs\Python\Python38\lib\site-packages\fastai\vision\image.py in calc(self, x, *args, **kwargs)
    474         "Apply to image `x`, wrapping it if necessary."
--> 475         if self._wrap: return getattr(x, self._wrap)(self.func, *args, **kwargs)
    476         else:          return self.func(x, *args, **kwargs)

~\AppData\Local\Programs\Python\Python38\lib\site-packages\fastai\vision\image.py in affine(self, func, *args, **kwargs)
    182         m = tensor(func(*args, **kwargs)).to(self.device)
--> 183         self.affine_mat = self.affine_mat @ m
    184         return self

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)
 in 
----> 1 data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(), size=224, bs=bs
      2                                   ).normalize(imagenet_stats)

~\AppData\Local\Programs\Python\Python38\lib\site-packages\fastai\vision\data.py in from_name_re(cls, path, fnames, pat, valid_pct, **kwargs)
    156             assert res,f'Failed to find "{pat}" in "{fn}"'
    157             return res.group(1)
--> 158         return cls.from_name_func(path, fnames, _get_label, valid_pct=valid_pct, **kwargs)
    159 
    160     @staticmethod

~\AppData\Local\Programs\Python\Python38\lib\site-packages\fastai\vision\data.py in from_name_func(cls, path, fnames, label_func, valid_pct, seed, **kwargs)
    145         "Create from list of `fnames` in `path` with `label_func`."
    146         src = ImageList(fnames, path=path).split_by_rand_pct(valid_pct, seed)
--> 147         return cls.create_from_ll(src.label_from_func(label_func), **kwargs)
    148 
    149     @classmethod

~\AppData\Local\Programs\Python\Python38\lib\site-packages\fastai\vision\data.py in create_from_ll(cls, lls, bs, val_bs, ds_tfms, num_workers, dl_tfms, device, test, collate_fn, size, no_check, resize_method, mult, padding_mode, mode, tfm_y)
     94                 mode:str='bilinear', tfm_y:bool=False)->'ImageDataBunch':
     95         "Create an `ImageDataBunch` from `LabelLists` `lls` with potential `ds_tfms`."
---> 96         lls = lls.transform(tfms=ds_tfms, size=size, resize_method=resize_method, mult=mult, padding_mode=padding_mode,
     97                             mode=mode, tfm_y=tfm_y)
     98         if test is not None: lls.add_test_folder(test)

~\AppData\Local\Programs\Python\Python38\lib\site-packages\fastai\data_block.py in transform(self, tfms, **kwargs)
    503         if not tfms: tfms=(None,None)
    504         assert is_listy(tfms) and len(tfms) == 2, "Please pass a list of two lists of transforms (train and valid)."
--> 505         self.train.transform(tfms[0], **kwargs)
    506         self.valid.transform(tfms[1], **kwargs)
    507         if self.test: self.test.transform(tfms[1], **kwargs)

~\AppData\Local\Programs\Python\Python38\lib\site-packages\fastai\data_block.py in transform(self, tfms, tfm_y, **kwargs)
    722     def transform(self, tfms:TfmList, tfm_y:bool=None, **kwargs):
    723         "Set the `tfms` and `tfm_y` value to be applied to the inputs and targets."
--> 724         _check_kwargs(self.x, tfms, **kwargs)
    725         if tfm_y is None: tfm_y = self.tfm_y
    726         tfms_y = None if tfms is None else list(filter(lambda t: getattr(t, 'use_on_y', True), listify(tfms)))

~\AppData\Local\Programs\Python\Python38\lib\site-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
3 Likes

Getting the same error.

You need to user a developer install. Those bugs have been fixed in master but we haven’t made a new release of fastai yet.

How do we use the developer install? At the moment we are following the course docs.

1 Like

I am getting the same error but it’s just for rotate. If I run the transformation with commenting out the rotate transformation. It runs fine.

       [RandTransform(tfm=TfmCrop (crop_pad), kwargs={'row_pct': (0, 1), 'col_pct': (0, 1), 'padding_mode': 'reflection'}, p=1.0, resolved={}, do_run=True, is_random=True), 
        RandTransform(tfm=TfmCoord (symmetric_warp), kwargs={'magnitude': (-0.2, 0.2)}, p=0.75, resolved={}, do_run=True, is_random=True), 
        # RandTransform(tfm=TfmAffine (rotate), kwargs={'degrees': (-40, 40)}, p=0.75, resolved={}, do_run=True, is_random=True), 
        RandTransform(tfm=TfmAffine (flip_affine), kwargs={}, p=0.5, resolved={}, do_run=True, is_random=True), 
        RandTransform(tfm=TfmAffine (zoom), kwargs={'scale': (1.0, 1.4), 'row_pct': (0, 1), 'col_pct': (0, 1)}, p=0.75, resolved={}, do_run=True, is_random=True), 
        RandTransform(tfm=TfmLighting (brightness), kwargs={'change': (0.35, 0.65)}, p=0.75, resolved={}, do_run=True, is_random=True), 
        RandTransform(tfm=TfmLighting (contrast), kwargs={'scale': (0.7, 1.43)}, p=0.75, resolved={}, do_run=True, is_random=True),
        RandTransform(tfm=TfmCoord (jitter), kwargs={'magnitude': (-0.01, 0.01)}, p=0.2, resolved={}, do_run=True, is_random=True),
        RandTransform(tfm=TfmCoord (skew), kwargs={'direction': (0, 7), 'magnitude': (0.2)}, p=0.75, resolved={}, do_run=True, is_random=True),
        RandTransform(tfm=TfmAffine (squish), kwargs={'scale': (0.42, 2.4), 'row_pct': (0, 1), 'col_pct': (0, 1)}, p=0.75, resolved={}, do_run=True, is_random=True)]

pip install git+https://github.com/fastai/fastai.git

2 Likes

Hello, try to downgrade torch to version 1.4.0 or lower

1 Like

Thanks, it worked.

pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html

1 Like

You could use the command I used instead if you want.

Hi,

I was having the exact same problems while using Google Colab.
I tried this command -
!pip install git+https://github.com/fastai/fastai.git
and continue to face the problems.
Going back to the earlier versions Pytorch did slve the problem, below the command I ran -
!pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html

Hope this helps for folks usign Google Colab.

  • JP
1 Like

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

This worked for me. Thank you

Thank you, this worked for me as well.