@muellerzr With the next order:
manual = DataBlock(blocks=(ImageBlock,MaskBlock(codes),BBoxBlockSegmentation, BBoxLblBlock),
get_items=partial(get_image_files,folders=[dataset1]),
getters=getters,
splitter=RandomSplitter(valid_pct=0.1,seed=2020),
item_tfms=Resize((size,size)),
batch_tfms=Normalize.from_stats(*imagenet_stats),
n_inp=1
)
manual.summary(path_images)
dls = manual.dataloaders(path_images,bs=bs)
dls.one_batch()
Different error
Setting-up type transforms pipelines
Collecting items from ../datasets/Images
Found 621 items
2 datasets of sizes 559,62
Setting up Pipeline: <lambda> -> PILBase.create
Setting up Pipeline: get_mask -> PILBase.create
Setting up Pipeline: get_bbox -> TensorBBox.create
Setting up Pipeline: get_bbox_label -> MultiCategorize
Building one sample
Pipeline: <lambda> -> PILBase.create
starting from
../datasets/Images/manual/165.png
applying <lambda> gives
../datasets/Images/manual/165.png
applying PILBase.create gives
PILImage mode=RGB size=1002x1004
Pipeline: get_mask -> PILBase.create
starting from
../datasets/Images/manual/165.png
applying get_mask gives
../datasets/Labels/manual/165.png
applying PILBase.create gives
PILMask mode=L size=1002x1004
Pipeline: get_bbox -> TensorBBox.create
starting from
../datasets/Images/manual/165.png
applying get_bbox gives
[[425, 387, 641, 591]]
applying TensorBBox.create gives
TensorBBox of size 1x4
Pipeline: get_bbox_label -> MultiCategorize
starting from
../datasets/Images/manual/165.png
applying get_bbox_label gives
[Class1]
applying MultiCategorize gives
TensorMultiCategory([1])
Final sample: (PILImage mode=RGB size=1002x1004, PILMask mode=L size=1002x1004, TensorBBox([[425., 387., 641., 591.]]), TensorMultiCategory([1]))
Setting up after_item: Pipeline: AddMaskCodes -> BBoxLabeler -> PointScaler -> Resize -> ToTensor
Setting up before_batch: Pipeline: mybb_pad
Setting up after_batch: Pipeline: IntToFloatTensor -> Normalize
Could not do one pass in your dataloader, there is something wrong in it
Building one batch
Applying item_tfms to the first sample:
Pipeline: AddMaskCodes -> BBoxLabeler -> PointScaler -> Resize -> ToTensor
starting from
(PILImage mode=RGB size=1002x1004, PILMask mode=L size=1002x1004, TensorBBox of size 1x4, TensorMultiCategory([1]))
applying AddMaskCodes gives
(PILImage mode=RGB size=1002x1004, PILMask mode=L size=1002x1004, TensorBBox of size 1x4, TensorMultiCategory([1]))
applying BBoxLabeler gives
(PILImage mode=RGB size=1002x1004, PILMask mode=L size=1002x1004, TensorBBox of size 1x4, TensorMultiCategory([1]))
applying PointScaler gives
(PILImage mode=RGB size=1002x1004, PILMask mode=L size=1002x1004, TensorBBox of size 1x4, TensorMultiCategory([1]))
applying Resize gives
(PILImage mode=RGB size=1002x1002, PILMask mode=L size=1002x1002, TensorBBox of size 1x4, TensorMultiCategory([1]))
applying ToTensor gives
(TensorImage of size 3x1002x1002, TensorMask of size 1002x1002, TensorBBox of size 1x4, TensorMultiCategory([1]))
Adding the next 3 samples
Applying before_batch to the list of samples
Pipeline: mybb_pad
starting from
[(TensorImage of size 3x1002x1002, TensorMask of size 1002x1002, TensorBBox of size 1x4, TensorMultiCategory([1])), (TensorImage of size 3x1002x1002, TensorMask of size 1002x1002, TensorBBox of size 1x4, TensorMultiCategory([1])), (TensorImage of size 3x1002x1002, TensorMask of size 1002x1002, TensorBBox of size 1x4, TensorMultiCategory([1])), (TensorImage of size 3x1002x1002, TensorMask of size 1002x1002, TensorBBox of size 1x4, TensorMultiCategory([1]))]
applying mybb_pad failed.
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-22-e40df62d36e3> in <module>
7 n_inp=1
8 )
----> 9 manual.summary(path_images)
10 dls = manual.dataloaders(path_images,bs=bs)
11 dls.one_batch()
~/anaconda3/envs/seg/lib/python3.7/site-packages/fastai2/data/block.py in summary(self, source, bs, show_batch, **kwargs)
171 if len([f for f in dls.train.before_batch.fs if f.name != 'noop'])!=0:
172 print("\nApplying before_batch to the list of samples")
--> 173 s = _apply_pipeline(dls.train.before_batch, s)
174 else: print("\nNo before_batch transform to apply")
175
~/anaconda3/envs/seg/lib/python3.7/site-packages/fastai2/data/block.py in _apply_pipeline(p, x)
131 except Exception as e:
132 print(f" applying {name} failed.")
--> 133 raise e
134 return x
135
~/anaconda3/envs/seg/lib/python3.7/site-packages/fastai2/data/block.py in _apply_pipeline(p, x)
127 name = f.name
128 try:
--> 129 x = f(x)
130 if name != "noop": print(f" applying {name} gives\n {_short_repr(x)}")
131 except Exception as e:
~/anaconda3/envs/seg/lib/python3.7/site-packages/fastcore/transform.py in __call__(self, x, **kwargs)
70 @property
71 def name(self): return getattr(self, '_name', _get_name(self))
---> 72 def __call__(self, x, **kwargs): return self._call('encodes', x, **kwargs)
73 def decode (self, x, **kwargs): return self._call('decodes', x, **kwargs)
74 def __repr__(self): return f'{self.name}: {self.encodes} {self.decodes}'
~/anaconda3/envs/seg/lib/python3.7/site-packages/fastcore/transform.py in _call(self, fn, x, split_idx, **kwargs)
80 def _call(self, fn, x, split_idx=None, **kwargs):
81 if split_idx!=self.split_idx and self.split_idx is not None: return x
---> 82 return self._do_call(getattr(self, fn), x, **kwargs)
83
84 def _do_call(self, f, x, **kwargs):
~/anaconda3/envs/seg/lib/python3.7/site-packages/fastcore/transform.py in _do_call(self, f, x, **kwargs)
84 def _do_call(self, f, x, **kwargs):
85 if not _is_tuple(x):
---> 86 return x if f is None else retain_type(f(x, **kwargs), x, f.returns_none(x))
87 res = tuple(self._do_call(f, x_, **kwargs) for x_ in x)
88 return retain_type(res, x)
~/anaconda3/envs/seg/lib/python3.7/site-packages/fastcore/dispatch.py in __call__(self, *args, **kwargs)
96 if not f: return args[0]
97 if self.inst is not None: f = MethodType(f, self.inst)
---> 98 return f(*args, **kwargs)
99
100 def __get__(self, inst, owner):
<ipython-input-13-ef644dab5e4a> in mybb_pad(samples, pad_idx)
2 "Function that collect `samples` of labelled bboxes and adds padding with `pad_idx`."
3 if len(samples[0]) > 3:
----> 4 samples = [(s[0], *clip_remove_empty(*s[1:3])) for s in samples]
5 else:
6 samples = [(s[0], *clip_remove_empty(*s[1:])) for s in samples]
<ipython-input-13-ef644dab5e4a> in <listcomp>(.0)
2 "Function that collect `samples` of labelled bboxes and adds padding with `pad_idx`."
3 if len(samples[0]) > 3:
----> 4 samples = [(s[0], *clip_remove_empty(*s[1:3])) for s in samples]
5 else:
6 samples = [(s[0], *clip_remove_empty(*s[1:])) for s in samples]
~/anaconda3/envs/seg/lib/python3.7/site-packages/fastai2/vision/data.py in clip_remove_empty(bbox, label)
26 bbox = torch.clamp(bbox, -1, 1)
27 empty = ((bbox[...,2] - bbox[...,0])*(bbox[...,3] - bbox[...,1]) < 0.)
---> 28 return (bbox[~empty], label[~empty])
29
30 # Cell
IndexError: The shape of the mask [1002] at index 0 does not match the shape of the indexed tensor [1, 4] at index 0