Hi Oli, Thanks for your reply, appreciate it!
I rethinked a little bit about it and I changed the format of the paths in the text file. Basically, I just put all 8 file paths in one line and separate them with a comma and put the label in the end. It looks like this:
…\O2Hb_1.png,…\O2Hb_2.png,…\O2Hb_3.png,…\O2Hb_4.png,…\O2Hb_5.png,…\O2Hb_6.png,…\O2Hb_7.png,…\O2Hb_8.png,0
I will put all the input images’ paths in this text file and read each line iteratively.
and instead of reading the list in initial I decided to do it in the getitem function because I have all 8 paths and label in one line.
class MyDataset(Dataset):
def __init__(self, txt_path,transform=None,target_transform = None):
    fh = open(txt_path, 'r')
    imgs = []
    for line in fh:
        imgs.append(line)
    self.imgs = imgs
    self.transform = transform
    self.target_transform = target_transform
    
def __getitem__(self, index):
    fn = self.imgs[index]
    fn = fn.rstrip()
    paths = fn.split(',')
    image_dir_1 = paths[0]
    image_dir_2 = paths[1]
    label = paths[8]
    img1 = Image.open(image_dir_1).convert('RGB')
    if self.transform is not None:
        img1 = self.transform(img1)
    img2 = Image.open(image_dir_2).convert('RGB')
    if self.transform is not None:
        img2 = self.transform(img2)
    img2 = torch.cat(img1,img2)
    return img2,label

I am using the first 2 images as an example, and it seems like working but I don’t know why I cannot use torch.cat() to combine two tensors properly.