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

transform=transforms.Compose([transforms.ToTensor(),transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))])
trainset=torchvision.datasets.ImageFolder('D:/Desktop/cnn_test_data/train',transform=transform)
trainloader=torch.utils.data.DataLoader(trainset,batch_size=2,shuffle=True,num_workers=2)
testset=torchvision.datasets.ImageFolder('D:/Desktop/cnn_test_data/test',transform=transform)
testloader=torch.utils.data.DataLoader(testset,batch_size=2,shuffle=True,num_workers=2)

def imshow(img):
    img = img / 2 + 0.5 
    npimg = img.numpy()
    plt.imshow(np.transpose(npimg, (1, 2, 0)))
    plt.show()
    
for i,data in enumerate(trainloader,0):
    images,labels=data
    imshow(torchvision.utils.make_grid(images))
    print(labels)

RuntimeError                              Traceback (most recent call last)
<ipython-input-12-b39757ccbf7b> in <module>
     20     plt.show()
     21 
---> 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\dataloader.py in __next__(self)
    635                 self.reorder_dict[idx] = batch
    636                 continue
--> 637             return self._process_next_batch(batch)
    638 
    639     next = __next__  # Python 2 compatibility

D:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py 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
    660 

RuntimeError: Traceback (most recent call last):
  File "D:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 138, in _worker_loop
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "D:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 232, in default_collate
    return [default_collate(samples) for samples in transposed]
  File "D:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 232, in <listcomp>
    return [default_collate(samples) for samples in transposed]
  File "D:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", 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