Hi,
I’ve tried using the custom ImageTupleList
which is introduced in this tutorial.
I am seeing RecursionError: maximum recursion depth exceeded
.
Here is the code:
class ImageTuple(ItemBase):
def __init__(self, img1, img2):
self.img1,self.img2 = img1,img2
self.obj,self.data = (img1,img2),[-1+2*img1.data,-1+2*img2.data]
def apply_tfms(self, tfms, **kwargs):
self.img1 = self.img1.apply_tfms(tfms, **kwargs)
self.img2 = self.img2.apply_tfms(tfms, **kwargs)
self.data = [-1+2*self.img1.data,-1+2*self.img2.data]
return self
def to_one(self):
return Image(0.5+torch.cat(self.data,2)/2)
class ImageTupleList(ImageItemList):
# _label_cls=TargetTupleList
def __init__(self, items, itemsB=None, **kwargs):
self.itemsB = itemsB
super().__init__(items, **kwargs)
def new(self, items, **kwargs):
return super().new(items, itemsB=self.itemsB, **kwargs)
def get(self, i):
img1 = super().get(i)
fn = self.itemsB[random.randint(0, len(self.itemsB)-1)]
return ImageTuple(img1, open_image(fn))
def reconstruct(self, t:Tensor):
return ImageTuple(Image(t[0]/2+0.5),Image(t[1]/2+0.5))
@classmethod
def from_folders(cls, path, folderA, folderB, **kwargs):
itemsB = ImageItemList.from_folder(path/folderB).items
res = super().from_folder(path/folderA, itemsB=itemsB, **kwargs)
res.path = path
return res
# list of fnames
itemsA = ImageItemList.from_df(train_df_dummy, cols=['ImageA'], path=data_path, folder='cropped_training').items
itemsB = ImageItemList.from_df(train_df_dummy, cols=['ImageB'], path=data_path, folder='cropped_training').items
ImageTupleList(itemsA, itemsB)
---------------------------------------------------------------------------
RecursionError Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
700 type_pprinters=self.type_printers,
701 deferred_pprinters=self.deferred_printers)
--> 702 printer.pretty(obj)
703 printer.flush()
704 return stream.getvalue()
~/anaconda3/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
381 if cls in self.type_pprinters:
382 # printer registered in self.type_pprinters
--> 383 return self.type_pprinters[cls](obj, self, cycle)
384 else:
385 # deferred printer
~/anaconda3/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
693 """A pprint that just redirects to the normal repr function."""
694 # Find newlines and replace them with p.break_()
--> 695 output = repr(obj)
696 for idx,output_line in enumerate(output.splitlines()):
697 if idx:
~/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in __repr__(self)
60 def __repr__(self)->str:
61 items = [self[i] for i in range(min(5,len(self.items)))]
---> 62 return f'{self.__class__.__name__} ({len(self.items)} items)\n{items}...\nPath: {self.path}'
63
64 def process(self, processor=None):
~/anaconda3/lib/python3.7/site-packages/fastai/core.py in __repr__(self)
148 "Base item type in the fastai library."
149 def __init__(self, data:Any): self.data=self.obj=data
--> 150 def __repr__(self): return f'{self.__class__.__name__} {self}'
151 def show(self, ax:plt.Axes, **kwargs):
152 "Subclass this method if you want to customize the way this `ItemBase` is shown on `ax`."
... last 1 frames repeated, from the frame below ...
~/anaconda3/lib/python3.7/site-packages/fastai/core.py in __repr__(self)
148 "Base item type in the fastai library."
149 def __init__(self, data:Any): self.data=self.obj=data
--> 150 def __repr__(self): return f'{self.__class__.__name__} {self}'
151 def show(self, ax:plt.Axes, **kwargs):
152 "Subclass this method if you want to customize the way this `ItemBase` is shown on `ax`."
RecursionError: maximum recursion depth exceeded
What might be the reason to this?
Thanks