RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0

Hello,everyone, I am using my own dataset, and I met the error below. I googled it but failed to solve it. Here are the codes.

import torch
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim


def imshow(img):
    img = img / 2 + 0.5 
    npimg = img.numpy()
    plt.imshow(np.transpose(npimg, (1, 2, 0)))
for i,data in enumerate(trainloader,0):
RuntimeError                              Traceback (most recent call last)
<ipython-input-12-b39757ccbf7b> in <module>
---> 22 for i,data in enumerate(trainloader,0):
     23     images,labels=data
     24     imshow(torchvision.utils.make_grid(images))

D:\Anaconda3\lib\site-packages\torch\utils\data\ in __next__(self)
    635                 self.reorder_dict[idx] = batch
    636                 continue
--> 637             return self._process_next_batch(batch)
    639     next = __next__  # Python 2 compatibility

D:\Anaconda3\lib\site-packages\torch\utils\data\ in _process_next_batch(self, batch)
    656         self._put_indices()
    657         if isinstance(batch, ExceptionWrapper):
--> 658             raise batch.exc_type(batch.exc_msg)
    659         return batch

RuntimeError: Traceback (most recent call last):
  File "D:\Anaconda3\lib\site-packages\torch\utils\data\", line 138, in _worker_loop
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "D:\Anaconda3\lib\site-packages\torch\utils\data\", line 232, in default_collate
    return [default_collate(samples) for samples in transposed]
  File "D:\Anaconda3\lib\site-packages\torch\utils\data\", line 232, in <listcomp>
    return [default_collate(samples) for samples in transposed]
  File "D:\Anaconda3\lib\site-packages\torch\utils\data\", line 209, in default_collate
    return torch.stack(batch, 0, out=out)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 2448 and 3000 in dimension 2 at c:\a\w\1\s\tmp_conda_3.7_110509\conda\conda-bld\pytorch_1544094576194\work\aten\src\th\generic/THTensorMoreMath.cpp:1333

My pictures have different sizes, after I resized them to an uniform size, the problem was solved.