Mirodil
(Mirodil)
July 6, 2019, 11:25pm
1
Hi,
I am trying to apply custom logic on a image after a image is loaded. I tried to use after_open
parameter of the ImageList but it does not do anything:
def after_open(img):
print(type(img))
raise Exception('Hello')
src = ImageList.from_df(train_df, '.', cols='id_code', folder='./512/', suffix='.png', after_open=after_open)
src = src.split_by_rand_pct(0.1)
src = src.label_from_df(cols='diagnosis')
src = src.add_test_folder(DATA_PATH/'test_images')
data = src.transform(size=256).databunch(bs=4, num_workers=0).normalize(imagenet_stats)
data.show_batch()
Is anyone had a similar issue?
Weird, it should work. In general after_open
is supposed to return the image after treating it.
Mirodil
(Mirodil)
July 7, 2019, 7:48pm
3
I have tried the following code:
class MyList(ImageList):
def __init__(self, *args, convert_mode='RGB', after_open:Callable=None, **kwargs):
super().__init__(*args, **kwargs)
self.convert_mode,self.after_open = convert_mode,after_open
self.copy_new.append('convert_mode')
self.c,self.sizes = 3,{}
def open(self, fn):
print(type(self), self.after_open)
return open_image(fn, convert_mode=self.convert_mode, after_open=self.after_open)
def after_open(img):
print(type(img))
raise Exception('Hello')
src = MyList.from_df(train_df, '.', cols='id_code', folder=DATA_PATH/'train_images', suffix='.png', after_open=after_open)
print(src.after_open == after_open)
src = src.split_by_rand_pct(0.1)
src = src.label_from_df(cols='diagnosis')
src = src.add_test_folder(DATA_PATH/'test_images')
data = src.transform(size=256).databunch(bs=4, num_workers=0).normalize(imagenet_stats)
data.show_batch()
output:
True
<class ‘main .MyList’> None
<class ‘main .MyList’> None
<class ‘main .MyList’> None
As I see after_open
became None
after splitting.
Oh it’s not copied along indeed. Thanks for flagging, will fix now.
Mirodil
(Mirodil)
July 7, 2019, 9:30pm
5
Thank you. Could you please suggest another way around it?
It’s fixed in master now, just do an editable install before the next release.
I want to make use of random crop as soon as image is opened.
how should i init the after open with library function avail in fast ai rand_Crop or crop_pad.
I should get different portions of images croped as per the size i give