I also came across the same issue when trying to build a custom dataset:
Here is the getitem method:
    def __getitem__(self, index):
            fname = self.train_filenames[index]
            image = Image.open(os.path.join(celeba_imgpath, fname))
            label = self.train_labels[index]
            return self.transform(image), torch.FloatTensor(label)


I think it was caused by the label given as a scalar value. I converted the label to a list, and then the problem was solved. Here is the corrected code:
    def __getitem__(self, index):
            fname = self.train_filenames[index]
            image = Image.open(os.path.join(celeba_imgpath, fname))
            label = [self.train_labels[index]]
            return self.transform(image), torch.FloatTensor(label)