Hello,
I’m running into troubles while training a CAE(Convolutional Auto Encoder) model. I defined my own dataset class as follows:
def make_dataset(dir, class_to_idx, extensions):
    label_list = []
    input_list = []
    dir = os.path.expanduser(dir)
    for target in sorted(class_to_idx.keys()):
        d = os.path.join(dir, target)
        if not os.path.isdir(d):
            continue

        for root, _, fnames in sorted(os.walk(d)):
            for fname in sorted(fnames):
                if has_file_allowed_extension(fname, extensions):        
                    if target == 'Source':
                        if fname.endswith('.wav'):
                            path = os.path.join(root, fname)
                            item = (path)
                            label_list.append(item)
                    else:
                        if fname.endswith('.wav'):
                            path = os.path.join(root, fname)
                            item = (path)
                            input_list.append(item)
    return input_list, label_list



class msd_dataset(data.Dataset):

    def __init__(self, root, extensions, train=True, input_transform=None, target_transform=None):

        self.extensions = extensions
        self.train = train

        #Join the Train/Test to the existing path if user specifies Train=True/False respectively.
        if self.train:
            self.root = os.path.join(root, 'Train')
        else:
            self.root = os.path.join(root, 'Test')
          
        classes, class_to_idx = self._find_classes(self.root)
       
        samples = make_dataset(self.root, class_to_idx, extensions)
        #Sanity check 
        if (len(samples[0]) or len(samples[1])) == 0:
            raise(RuntimeError("Found 0 files in subfolders of: " + self.root + "\n"

       self.classes = classes
        self.samples = samples

        self.input_transform = input_transform
        self.target_transform = target_transform

    def _find_classes(self, dir):
       
        if sys.version_info >= (3, 5):
            # Faster and available in Python 3.5 and above
            classes = [d.name for d in os.scandir(dir) if d.is_dir()]
        else:
            classes = [d for d in os.listdir(dir) if os.path.isdir(os.path.join(dir, d))]
        classes.sort()
        class_to_idx = {classes[i]: i for i in range(len(classes))}
        return classes, class_to_idx

def __getitem__(self, index):
        path, target = self.samples
        #Loading Audio with librosa 
        input_mixture, sr1 = librosa.load(path[index], sr=44100, mono=False)
        label_source, sr2 = librosa.load(target[index], sr=44100, mono=False)
        if self.input_transform is not None:
            input_mixture = input_mixture.reshape(input_mixture.shape[0], 1, input_mixture.shape[1])
            input_mixture = torch.from_numpy(input_mixture)
            input_mixture = self.input_transform(input_mixture)
        if self.target_transform is not None:
            label_source = label_source.reshape(label_source.shape[0], 1, label_source.shape[1])
            label_source = torch.from_numpy(label_source)
            label_source = self.target_transform(label_source)
        return input_mixture, label_source

    def __len__(self):
        return len(self.samples[0])

How can I fix this?