I have several masks which I turn into 0 and 1 tensors. I create ImageBlock isntance:
field = DataBlock(blocks=(ImageBlock, MaskBlock(keys)),
get_items=get_image_files,
splitter=FileSplitter('photos/valid.txt'),
get_y=get_msk,
batch_tfms=[*aug_transforms(size=half),
Normalize.from_stats(*imagenet_stats)])
Where get_msk is lambda function to get all masks from directory
Later I use the field DataBlock when creating dataloaders
dls = field.dataloaders(train_path, bs=2)
I use dls when creating unet_learner:
learn = unet_learner(dls, resnet34, opt_func=ranger, act_cls=Mish, self_attention=True, metrics=acc_camvid)
I encounter the TypeError when trying to get learn.summary()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-42-bc39e9e85f86> in <module>
----> 1 learn.summary()
~/anaconda3/envs/rmnt/lib/python3.8/site-packages/fastai/callback/hook.py in summary(self)
189 "Print a summary of the model, optimizer and loss function."
190 xb = self.dls.train.one_batch()[:self.dls.train.n_inp]
--> 191 res = module_summary(self, *xb)
192 res += f"Optimizer used: {self.opt_func}\nLoss function: {self.loss_func}\n\n"
193 if self.opt is not None:
~/anaconda3/envs/rmnt/lib/python3.8/site-packages/fastai/callback/hook.py in module_summary(learn, *xb)
166 infos = layer_info(learn, *xb)
167 n,bs = 64,find_bs(xb)
--> 168 inp_sz = _print_shapes(apply(lambda x:x.shape, xb), bs)
169 res = f"{learn.model.__class__.__name__} (Input shape: {inp_sz})\n"
170 res += "=" * n + "\n"
~/anaconda3/envs/rmnt/lib/python3.8/site-packages/fastai/callback/hook.py in _print_shapes(o, bs)
156 def _print_shapes(o, bs):
157 if isinstance(o, torch.Size): return ' x '.join([str(bs)] + [str(t) for t in o[1:]])
--> 158 else: return str([_print_shapes(x, bs) for x in o])
159
160 # Cell
~/anaconda3/envs/rmnt/lib/python3.8/site-packages/fastai/callback/hook.py in <listcomp>(.0)
156 def _print_shapes(o, bs):
157 if isinstance(o, torch.Size): return ' x '.join([str(bs)] + [str(t) for t in o[1:]])
--> 158 else: return str([_print_shapes(x, bs) for x in o])
159
160 # Cell
~/anaconda3/envs/rmnt/lib/python3.8/site-packages/fastai/callback/hook.py in _print_shapes(o, bs)
156 def _print_shapes(o, bs):
157 if isinstance(o, torch.Size): return ' x '.join([str(bs)] + [str(t) for t in o[1:]])
--> 158 else: return str([_print_shapes(x, bs) for x in o])
159
160 # Cell
~/anaconda3/envs/rmnt/lib/python3.8/site-packages/fastai/callback/hook.py in <listcomp>(.0)
156 def _print_shapes(o, bs):
157 if isinstance(o, torch.Size): return ' x '.join([str(bs)] + [str(t) for t in o[1:]])
--> 158 else: return str([_print_shapes(x, bs) for x in o])
159
160 # Cell
~/anaconda3/envs/rmnt/lib/python3.8/site-packages/fastai/callback/hook.py in _print_shapes(o, bs)
156 def _print_shapes(o, bs):
157 if isinstance(o, torch.Size): return ' x '.join([str(bs)] + [str(t) for t in o[1:]])
--> 158 else: return str([_print_shapes(x, bs) for x in o])
159
160 # Cell
TypeError: 'int' object is not iterable```
In the traceback at the end I see what I understand as recursion: _print_shapes calls itself and after two full cycles it encounters int it throws the typeerror
I would appreciate suggestions how to fix the error. I am guessing that the only way is to escape the recurssion loop is to get to the if part o the _print_shapes method