Hey, thank you for your help!
I had already tried that as well, but it didn’t work out, unfortunately. You could see that the **
was there but before the merge
. Anyway, I tried both variations, and it still didn’t work.
It seems to me that passing the cls.create
into type_tfms
helps later on the Datasets
or DataBlock
classes to set what Transform
there would be used per each item
. Basically it passes in the method that is used to open the image file from a filename. Only when passing **kwargs
, somewhere in between it realises that it was supposed to get the fn
passed in too, but it wasn’t. So it then asserts some error.
I really wish that there was a way to send **kwargs
in the ImageBlock(cls=PILImage(**kwargs))
so it can let the user pick what way the PILImage would open the image file (size, quality, etc).
Here’s an error: (I didn’t need to pass in any kwargs, just add the two ()
in the first instance of PILImage in the ImageBlock.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-14-4179cfe33bfc> in <module>()
----> 1 dblock = DataBlock(blocks=(ImageBlock(cls=PILImage()), ImageBlock(cls=PILImage)),
2 splitter=RandomSplitter(seed=2022),
/usr/local/lib/python3.7/dist-packages/fastcore/meta.py in __call__(cls, x, *args, **kwargs)
60 if hasattr(cls, '_new_meta'): x = cls._new_meta(x, *args, **kwargs)
61 elif not isinstance(x,getattr(cls,'_bypass_type',object)) or len(args) or len(kwargs):
---> 62 x = super().__call__(*((x,)+args), **kwargs)
63 if cls!=x.__class__: x.__class__ = cls
64 return x
TypeError: __init__() takes 1 positional argument but 2 were given
I tried to fix this by adjusting the ImageBlock
, as seen here, but once again another error:
TypeError Traceback (most recent call last)
<ipython-input-9-1dda9d15a3c1> in <module>()
----> 1 dblock = DataBlock(blocks=(ImageBlock(cls=PILImage, check=1), ImageBlock(cls=PILImage)),
2 splitter=RandomSplitter(seed=2022),
/usr/local/lib/python3.7/dist-packages/fastai/vision/data.py in ImageBlock(cls, **kwargs)
84 def ImageBlock(cls:PILBase=PILImage,**kwargs):
85 "A `TransformBlock` for images of `cls`"
---> 86 return TransformBlock(type_tfms=cls.create(**kwargs), batch_tfms=IntToFloatTensor)
87
88 # Cell
TypeError: create() missing 1 required positional argument: 'fn'
Another update. I tried to add fn=None,**kwargs
in the create
inside the ImageBlock
. Then I got this progress, yet error:
Collecting items from /content/drive/MyDrive/Dataset15/RAW/Short3
Found 107 items
2 datasets of sizes 86,21
Setting up Pipeline: RAWImage
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-6a7e357dcd28> in <module>()
18 xtra_tfms=RandomErasing(max_count=2, min_aspect=0.3)
19 )])
---> 20 dls = dblock.dataloaders(source=path_short,bs=btchSize,path=path,verbose=True)
21 dls.c=3 # Setting n_out // c=Channels
10 frames
/usr/local/lib/python3.7/dist-packages/fastai/data/block.py in dataloaders(self, source, path, verbose, **kwargs)
156 **kwargs
157 ) -> DataLoaders:
--> 158 dsets = self.datasets(source, verbose=verbose)
159 kwargs = {**self.dls_kwargs, **kwargs, 'verbose': verbose}
160 return dsets.dataloaders(path=path, after_item=self.item_tfms, after_batch=self.batch_tfms, **kwargs)
/usr/local/lib/python3.7/dist-packages/fastai/data/block.py in datasets(self, source, verbose)
148 splits = (self.splitter or RandomSplitter())(items)
149 pv(f"{len(splits)} datasets of sizes {','.join([str(len(s)) for s in splits])}", verbose)
--> 150 return Datasets(items, tfms=self._combine_type_tfms(), splits=splits, dl_type=self.dl_type, n_inp=self.n_inp, verbose=verbose)
151
152 def dataloaders(self,
/usr/local/lib/python3.7/dist-packages/fastai/data/core.py in __init__(self, items, tfms, tls, n_inp, dl_type, **kwargs)
452 ):
453 super().__init__(dl_type=dl_type)
--> 454 self.tls = L(tls if tls else [TfmdLists(items, t, **kwargs) for t in L(ifnone(tfms,[None]))])
455 self.n_inp = ifnone(n_inp, max(1, len(self.tls)-1))
456
/usr/local/lib/python3.7/dist-packages/fastai/data/core.py in <listcomp>(.0)
452 ):
453 super().__init__(dl_type=dl_type)
--> 454 self.tls = L(tls if tls else [TfmdLists(items, t, **kwargs) for t in L(ifnone(tfms,[None]))])
455 self.n_inp = ifnone(n_inp, max(1, len(self.tls)-1))
456
/usr/local/lib/python3.7/dist-packages/fastcore/foundation.py in __call__(cls, x, *args, **kwargs)
95 def __call__(cls, x=None, *args, **kwargs):
96 if not args and not kwargs and x is not None and isinstance(x,cls): return x
---> 97 return super().__call__(x, *args, **kwargs)
98
99 # Cell
/usr/local/lib/python3.7/dist-packages/fastai/data/core.py in __init__(self, items, tfms, use_list, do_setup, split_idx, train_setup, splits, types, verbose, dl_type)
366 if do_setup:
367 pv(f"Setting up {self.tfms}", verbose)
--> 368 self.setup(train_setup=train_setup)
369
370 def _new(self, items, split_idx=None, **kwargs):
/usr/local/lib/python3.7/dist-packages/fastai/data/core.py in setup(self, train_setup)
393 for f in self.tfms.fs:
394 self.types.append(getattr(f, 'input_types', type(x)))
--> 395 x = f(x)
396 self.types.append(type(x))
397 types = L(t if is_listy(t) else [t] for t in self.types).concat().unique()
/usr/local/lib/python3.7/dist-packages/fastcore/transform.py in __call__(self, x, **kwargs)
71 @property
72 def name(self): return getattr(self, '_name', _get_name(self))
---> 73 def __call__(self, x, **kwargs): return self._call('encodes', x, **kwargs)
74 def decode (self, x, **kwargs): return self._call('decodes', x, **kwargs)
75 def __repr__(self): return f'{self.name}:\nencodes: {self.encodes}decodes: {self.decodes}'
/usr/local/lib/python3.7/dist-packages/fastcore/transform.py in _call(self, fn, x, split_idx, **kwargs)
81 def _call(self, fn, x, split_idx=None, **kwargs):
82 if split_idx!=self.split_idx and self.split_idx is not None: return x
---> 83 return self._do_call(getattr(self, fn), x, **kwargs)
84
85 def _do_call(self, f, x, **kwargs):
/usr/local/lib/python3.7/dist-packages/fastcore/transform.py in _do_call(self, f, x, **kwargs)
87 if f is None: return x
88 ret = f.returns(x) if hasattr(f,'returns') else None
---> 89 return retain_type(f(x, **kwargs), x, ret)
90 res = tuple(self._do_call(f, x_, **kwargs) for x_ in x)
91 return retain_type(res, x)
/usr/local/lib/python3.7/dist-packages/fastcore/dispatch.py in __call__(self, *args, **kwargs)
121 elif self.inst is not None: f = MethodType(f, self.inst)
122 elif self.owner is not None: f = MethodType(f, self.owner)
--> 123 return f(*args, **kwargs)
124
125 def __get__(self, inst, owner):
TypeError: 'RAWImage' object is not callable