You need to write a custom collate function to collect the output of __getitem__() method into a list or tuple. An example of custom collate function:

  
    
    
    RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 3 and 2 in dimension 1 
  
  
    Yes. It is not dealing with your exact issue. I was hoping, it might give you some idea. 
Please try-out the following collate function: 
import torch
import numpy as np
import torch.utils.data as data

def my_collate(batch):
    data = torch.stack([item[0].unsqueeze(0) for item in batch], 0)
    target = torch.Tensor([item[1] for item in batch])
    return [data, target]

class dataset(data.Dataset):
    def __init__(self):
        super(dataset, self).__init__()

    def __len__(self):
       …