File "KittiClass.py", line 111, in __getitem__ lbl_path = self.labels[self.split][index] IndexError: list index out of range

def main():
    from torchvision import transforms
    from torch.utils import data

    tf_source = transforms.Compose([
        transforms.Resize(64),
        transforms.ToTensor(),
        transforms.Normalize(mean=(0.1307,), std=(0.3081,))
    ])



    dataset = KittiLoader('/home/abderrazzak/kitti',  transforms=tf_source)

    print(len(dataset))

    train_loader = data.DataLoader(dataset=dataset,
                                    batch_size=1, shuffle=True,)
    print(len(train_loader))

    for x, y in train_loader:
       print(x.size())
       print(y)
       break

if __name__ == '__main__':
    main()

    def __getitem__(self, index):

        img_name = self.files[self.split][index]
        img_path = img_name
        print(len(img_path))
        # img = m.imread(img_path)
        img = cv2.imread(img_path)
        height, width, channels = img.shape
        # img = np.array(img, dtype=np.uint8)
        if self.split != "testing":

            lbl_path = self.labels[self.split][index]
            lbl_lines = open(lbl_path, 'r').readlines()
            if self.target_transform is not None:
                target = self.target_transform(lbl_lines, width, height)
        else:
            lbl = None
        # if self.is_transform:
        #     img, lbl = self.transform(img, lbl)
        if self.transforms is not None:
            target = np.array(target)
            img, boxes, labels = self.transforms(img, target[:, :4], target[:, 4])
            # img, lbl = self.transforms(img, lbl)
            img = img[:, :, (2, 1, 0)]
            target = np.hstack((boxes, np.expand_dims(labels, axis=1)))
        if self.split != "testing":
            # return img, lbl
            return torch.from_numpy(img).permute(2, 0, 1), target, height, width
        else:
            return img

How did you initialize self.split and what are you returning in the __len__ method?
Could you print the length of labels:

split = ... # set the same split value here
print(len(dataset.labels[split]))

Thank you for your message :

class KittiLoader(data.Dataset):
    def __init__(self, root, split="training",
                 img_size=512, transforms=None, target_transform=None):
        self.root = root
        self.split = split # that how i initialize self.split 
        self.target_transform = target_transform
        self.n_classes = 2
        self.img_size = img_size if isinstance(img_size, tuple) else (img_size, img_size)

        self.files = collections.defaultdict(list)
        self.labels = collections.defaultdict(list)
        self.transforms = transforms
        self.name = 'kitti'

        for split in ["training", "testing"]:
            file_list = glob(os.path.join(root, split, 'image_2', '*.png'))
            self.files[split] = file_list

            if not split=='testing':
                label_list=glob(os.path.join(root, split, '*.txt'))
                self.labels[split] = label_list




    def __len__(self): # that is my __len__ method
        return len(self.files[self.split])

What does

split = ... # set the same split value here
print(len(dataset.labels[split]))

return? It might be, that the path is set to a wrong folder and thus no images are found using glob.