renato145 / fastai_scans

Fastai extension to work with 3d medical images
41 stars 12 forks source link

Data augmentation #2

Closed at110 closed 5 years ago

at110 commented 5 years ago

Hi Renato,

I am trying to do following..

data = (fastai_scans.SegmentationItemList.from_paths(train_data_bolz, train_labels_bolz)
                                         .random_split_by_pct(0.2, seed=7)
                                         .label_from_bcolz()
                                         .transform(fastai_scans.get_transforms(), tfm_y=True)
                                         .databunch(bs=bs)
                                         .normalize())
tfms = fastai_scans.get_transforms(); len(tfms)

volume0 =data.train_ds.x[0];volume0

So fa so good

Volume (42, 288, 288)

but when i tried...

volume0.apply_tfms(tfms=tfms)

it produced

AttributeError Traceback (most recent call last)

in 1 ----> 2 volume0.apply_tfms(tfms=tfms) ~/myenv/fastai_scans/fastai_scans/volume.py in apply_tfms(self, tfms, do_resolve, **kwargs) 21 22 def apply_tfms(self, tfms, do_resolve=True, **kwargs): ---> 23 tfms = sorted(listify(tfms), key=lambda o: o.tfm.order) 24 if do_resolve: 25 for f in listify(tfms): ~/myenv/fastai_scans/fastai_scans/volume.py in (o) 21 22 def apply_tfms(self, tfms, do_resolve=True, **kwargs): ---> 23 tfms = sorted(listify(tfms), key=lambda o: o.tfm.order) 24 if do_resolve: 25 for f in listify(tfms): AttributeError: 'list' object has no attribute 'tfm'

Can you please help to resolve or give more information about this issue?

renato145 commented 5 years ago

Hi,

When you call .get_transforms() you get one set of tfms for the train set and another for the validation. So you should do: train_tfms,val_tfms = fastai_scans.get_transforms() and then volume0.apply_tfms(tfms=train_tfms) should work.

One more thing, If you do data.train_ds[0][0] you will have the volumes with the tfms applied.

at110 commented 5 years ago

Thank you Renato for prompt reply!