RuntimeError while running LeNet on 128*128*3 images

I am trying to run a LeNET over my dataset of images containing 128*128 size.

MY model info is like this:
LeNet(
(conv1): Conv2d(3, 6, kernel_size=(5, 5), stride=(1, 1))
(pool): MaxPool2d(kernel_size=(2, 2), stride=(2, 2), dilation=(1, 1), ceil_mode=False)
(conv2): Conv2d(6, 16, kernel_size=(5, 5), stride=(1, 1))
(fc1): Linear(in_features=400, out_features=120, bias=True)
(fc2): Linear(in_features=120, out_features=84, bias=True)
(fc3): Linear(in_features=84, out_features=10, bias=True)
)

Traceback (most recent call last):
File “cnn.py”, line 88, in
for data in trainLoader:
File “/home/jessie-pinkman/anaconda2/lib/python2.7/site-packages/torch/utils/data/dataloader.py”, line 281, in next
return self._process_next_batch(batch)
File “/home/jessie-pinkman/anaconda2/lib/python2.7/site-packages/torch/utils/data/dataloader.py”, line 301, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
RuntimeError: Traceback (most recent call last):
File “/home/jessie-pinkman/anaconda2/lib/python2.7/site-packages/torch/utils/data/dataloader.py”, line 55, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File “/home/jessie-pinkman/anaconda2/lib/python2.7/site-packages/torch/utils/data/dataloader.py”, line 135, in default_collate
return [default_collate(samples) for samples in transposed]
File “/home/jessie-pinkman/anaconda2/lib/python2.7/site-packages/torch/utils/data/dataloader.py”, line 112, in default_collate
return torch.stack(batch, 0, out=out)
File “/home/jessie-pinkman/anaconda2/lib/python2.7/site-packages/torch/functional.py”, line 66, in stack
return torch.cat(inputs, dim, out=out)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 32 and 48 in dimension 3 at /opt/conda/conda-bld/pytorch_1518238581238/work/torch/lib/TH/generic/THTensorMath.c:2897

I need some help…Thank you .

Hi,

It looks like all images in your dataset are not the same size: the loader fails to concatenate them because some have size 32 on the 3rd dimension and some have size 48 on this same dimension.
Are you sure that your dataset contains images of size 128*128? make sure that the getitem function returns a tensor of size number_channels x 128 x 128.

1 Like

Thanks,their was a problem with the data .