'PosixPath' object has no attribute 'apply_tfms'

(Kshitij) #1


In lesson 7 – I am getting the error ‘Exception: It’s not possible to apply those transforms to your dataset:’ object has no attribute ‘apply_tfms’" while executing code;

data_crit = get_crit_data([name_gen, ‘images’], bs=bs, size=size)
def get_crit_data(classes, bs, size):
#src = ImageItemList.from_folder(path, include=classes).random_split_by_pct(0.1, seed=42)
src = ItemList.from_folder(path, include=classes).split_by_rand_pct(0.1, seed=42)
ll = src.label_from_folder(classes=classes)
data = (ll.transform(get_transforms(max_zoom=2.), size=size)
data.c = 3
return data

Please advise.



I have the same issue when calling get_data(bs,size).

AttributeError                            Traceback (most recent call last)
~\Miniconda3\lib\site-packages\fastai\data_block.py in _check_kwargs(ds, tfms, **kwargs)
    580         x = ds[0]
--> 581         try: x.apply_tfms(tfms, **kwargs)
    582         except Exception as e:

AttributeError: 'WindowsPath' object has no attribute 'apply_tfms'

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-39-1e99d4dbbccc> in <module>
----> 1 data_gen = get_data(bs,size)

<ipython-input-38-6368e247f676> 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))

~\Miniconda3\lib\site-packages\fastai\data_block.py in transform(self, tfms, **kwargs)
    491         if not tfms: tfms=(None,None)
    492         assert is_listy(tfms) and len(tfms) == 2, "Please pass a list of two lists of transforms (train and valid)."
--> 493         self.train.transform(tfms[0], **kwargs)
    494         self.valid.transform(tfms[1], **kwargs)
    495         if self.test: self.test.transform(tfms[1], **kwargs)

~\Miniconda3\lib\site-packages\fastai\data_block.py in transform(self, tfms, tfm_y, **kwargs)
    709         _check_kwargs(self.x, tfms, **kwargs)
    710         if tfm_y is None: tfm_y = self.tfm_y
--> 711         if tfm_y: _check_kwargs(self.y, tfms, **kwargs)
    712         self.tfms,self.tfmargs = tfms,kwargs
    713         self.tfm_y,self.tfms_y,self.tfmargs_y = tfm_y,tfms,kwargs

~\Miniconda3\lib\site-packages\fastai\data_block.py in _check_kwargs(ds, tfms, **kwargs)
    581         try: x.apply_tfms(tfms, **kwargs)
    582         except Exception as e:
--> 583             raise Exception(f"It's not possible to apply those transforms to your dataset:\n {e}")
    585 class LabelList(Dataset):

Exception: It's not possible to apply those transforms to your dataset:
 'WindowsPath' object has no attribute 'apply_tfms'

(Kshitij) #3


Per the Crestle admin I followed the below steps and for now lesson 7 (gan) is working fine.

Start your instance

Sign in to Crestle and click on Start Jupyter. The instance should take a min or two to spin up. Your previous work will be automatically loaded.

Update the course repo

To update the course repo, you will need to be in terminal. On the ‘Jupyter Notebook’ button, launch a new terminal from the jupyter notebook menu.

This should give you the latest of the course notebooks. If you modified some of the notebooks in course-v3/nbs directly, GitHub will probably throw you an error. You should type git stash to remove your local changes. Remember you should always work on a copy of the lesson notebooks.

Update the fastai library

To update the fastai library, open the terminal like before and type:

Stop your instance

Once you’re finished navigate back to the dashboard tab and click Stop Jupyter

It’s not enough to just close your browser or turn off your own computer.



(Arkadiusz Klemenko) #4

I’ve got the same issue and the error was with your output.

src = ItemList.from_folder(path, include=classes).split_by_rand_pct(0.1, seed=42)

ItemList means that what you get as an input is Item, and your x contain path instead of image. You should use:

src = ImageList.from_folder(path, include=classes).split_by_rand_pct(0.1, seed=42)

The same problem I found in the get_data, you should use ImageImageList, not ImageList when you want to apply_tfms to the output. tfm_y=True.



Thanks for your reply. Yes, I realised I needed a double Image list. I think I got confused by API changes for some of the functions and didn’t update the code correctly.

1 Like