Lesson 7: Error when applying transforms

Hi everyone,

I’m trying to run FastAI’s GAN superresolution notebook from lesson 7 but when it comes to creating databunch I get the following error:

RuntimeError Traceback (most recent call last)
c:\users\cranberry\appdata\local\programs\python\python36\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:

c:\users\cranberry\appdata\local\programs\python\python36\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()

c:\users\cranberry\appdata\local\programs\python\python36\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

c:\users\cranberry\appdata\local\programs\python\python36\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)

c:\users\cranberry\appdata\local\programs\python\python36\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)

c:\users\cranberry\appdata\local\programs\python\python36\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)
----> 1 data_gen = get_data(bs,size)

in get_data(bs, size)
1 def get_data(bs,size):
2 data = (src.label_from_func(lambda x: path_hr/x.name)
----> 3 .transform(get_transforms(max_zoom=2.), size=size, tfm_y=True)
4 .databunch(bs=bs).normalize(imagenet_stats, do_y=True))
5 print(data)

c:\users\cranberry\appdata\local\programs\python\python36\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)

c:\users\cranberry\appdata\local\programs\python\python36\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)))

c:\users\cranberry\appdata\local\programs\python\python36\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}")
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

Just in case here is the link to the notebook: https://github.com/fastai/course-v3/blob/master/nbs/dl1/lesson7-superres-gan.ipynb
I changed nothing except for batch size. Please help, I’m new to FastAI and as I understand I need to cast the data to Float but I’m not sure how to do it properly. Also I’m wondering why did I get this error in the first place since as I said I changed nothing.