V4 notebook errors

getting an exception in notebook 05, step 13:

  3                  splitter=RandomSplitter(seed=42),
  4                  get_y=using_attr(RegexLabeller(r'(.+)_\d+.jpg$'), 'name'))

----> 5 pets1.summary(path/“images”)

/opt/conda/lib/python3.7/site-packages/fastai2/data/block.py in summary(self, source, bs, **kwargs)
181 why = _find_fail_collate(s)
182 print(“Make sure all parts of your samples are tensors of the same size” if why is None else why)
–> 183 raise e
184
185 if len([f for f in dls.train.after_batch.fs if f.name != ‘noop’])!=0:

/opt/conda/lib/python3.7/site-packages/fastai2/data/block.py in summary(self, source, bs, **kwargs)
175 print("\nCollating items in a batch")
176 try:
–> 177 b = dls.train.create_batch(s)
178 b = retain_types(b, s[0] if is_listy(s) else s)
179 except Exception as e:

/opt/conda/lib/python3.7/site-packages/fastai2/data/load.py in create_batch(self, b)
124 def retain(self, res, b): return retain_types(res, b[0] if is_listy(b) else b)
125 def create_item(self, s): return next(self.it) if s is None else self.dataset[s]
–> 126 def create_batch(self, b): return (fa_collate,fa_convert)self.prebatched
127 def do_batch(self, b): return self.retain(self.create_batch(self.before_batch(b)), b)
128 def to(self, device): self.device = device

/opt/conda/lib/python3.7/site-packages/fastai2/data/load.py in fa_collate(t)
44 b = t[0]
45 return (default_collate(t) if isinstance(b, _collate_types)
—> 46 else type(t[0])([fa_collate(s) for s in zip(*t)]) if isinstance(b, Sequence)
47 else default_collate(t))
48

/opt/conda/lib/python3.7/site-packages/fastai2/data/load.py in (.0)
44 b = t[0]
45 return (default_collate(t) if isinstance(b, _collate_types)
—> 46 else type(t[0])([fa_collate(s) for s in zip(*t)]) if isinstance(b, Sequence)
47 else default_collate(t))
48

/opt/conda/lib/python3.7/site-packages/fastai2/data/load.py in fa_collate(t)
43 def fa_collate(t):
44 b = t[0]
—> 45 return (default_collate(t) if isinstance(b, _collate_types)
46 else type(t[0])([fa_collate(s) for s in zip(*t)]) if isinstance(b, Sequence)
47 else default_collate(t))

/opt/conda/lib/python3.7/site-packages/torch/utils/data/utils/collate.py in default_collate(batch)
53 storage = elem.storage().new_shared(numel)
54 out = elem.new(storage)
—> 55 return torch.stack(batch, 0, out=out)
56 elif elem_type.module == ‘numpy’ and elem_type.name != 'str

57 and elem_type.name != 'string
’:

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 333 and 393 in dimension 2 at /opt/conda/conda-bld/pytorch_1579022060824/work/aten/src/TH/generic/THTensor.cpp:612

When showing us the code please provide the whole datablock. If I had to guess you don’t include any item transforms. You need to ensure your data is all the same size before putting it into a batch. Is there a Resize() method on item_tfms? If not include one and your problem should be solved

1 Like

the cell in question:

pets1 = DataBlock(blocks = (ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter=RandomSplitter(seed=42),
get_y=using_attr(RegexLabeller(r’(.+)_\d+.jpg$’), ‘name’))
pets1.summary(path/“images”)

I was just executing each cell in notebook 05 … in v4 of the course…

If you read further this is supposed to not work, and highlight the use of dblock.summary.

Collating items in a batch
Error! It’s not possible to collate your items in a batch
Could not collate the 0-th members of your tuples because got the following shapes
torch.Size([3, 414, 500]),torch.Size([3, 375, 500]),torch.Size([3, 500, 281]),torch.Size([3, 203, 300])

Again, this alludes to your images not all being the same size.

1 Like

oh! my bad then … I was just trying to quickly verify that I had everything installed correctly by shift-clicking through each notebook …
thanks ! :slight_smile: