Thanks for your reply and i edited like u suggested but got this error : TypeError: pic should be Tensor or ndarray. Got <class ‘PIL.TiffImagePlugin.TiffImageFile’>.
import os
import numpy as np
import torch
import torchvision.transforms as transforms
from PIL import Image
Image.MAX_IMAGE_PIXELS = None
from torch.utils import data
from skimage import io
from skimage import transform
from skimage import util
Constants.
num_classes = 4
Class that reads a sequence of image paths from a directory and creates a data.Dataset with them.
class ListDataset(data.Dataset):
def __init__(self, dataset, mode, normalization='minmax', hidden_classes=None):

    # Initializing variables.
    self.root = './' + dataset + '/'
    self.mode = mode
    self.normalization = normalization
    self.hidden_classes = hidden_classes
    self.transforms = transforms
    
    
    if mode == 'Train':
        self.transforms = transforms.Compose([
                                            transforms.ToPILImage(),
                                            transforms.FiveCrop(256),
                                            transforms.RandomHorizontalFlip(),
                                            transforms.ToTensor(),
                                            transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
                                            
    
                                            ])
    else:
        self.transforms = transforms.Compose([
                                            transforms.ToPILImage(),
                                            transforms.ToTensor(),
                                            transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
                                            ])
        
    if self.hidden_classes is not None:
        self.n_classes = num_classes - len(hidden_classes)
    else:
        self.n_classes = num_classes

    # Creating list of paths.
    self.imgs = self.make_dataset()

    # Check for consistency in list.
    if len(self.imgs) == 0:

        raise (RuntimeError('Found 0 images, please check the data set'))

def make_dataset(self):

    # Making sure the mode is correct.
    assert self.mode in ['Train', 'Test', 'Validate']

    # Setting string for the mode.
    img_dir = os.path.join(self.root, self.mode, 'image_folder')
    msk_dir = os.path.join(self.root, self.mode, 'mask_folder')
    
    if self.mode == 'Validate':
        img_dir = os.path.join(self.root, 'Train', 'image_folder')
        msk_dir = os.path.join(self.root, 'Train', 'mask_folder')
        
        
        
    data_list = sorted([f for f in os.listdir(msk_dir) if os.path.isfile(os.path.join(msk_dir, f))])
        
    #print(data_list)
    # Creating list containing image and ground truth paths.
    items = []
    for it in data_list:
        item = (os.path.join(img_dir, it.replace('Mask.tif', '.tif')), os.path.join(msk_dir, it))
        items.append(item)
        
        #print(item)
       # print(img_dir, it, it.replace('_noBoundary.tif', '.tif'), os.path.join(msk_dir, it))
    # Returning list.
    return items


def __getitem__(self, index):
    # Reading items from list.
    img_path, msk_path = self.imgs[index]
    
    # Reading images.

    image = Image.open(img_path)
    mask = Image.open(msk_path)
    
    if self.transforms:
        image = self.transforms(image)
        mask  = self.transforms(mask)
    
    # Turning to tensors.
    image = torch.tensor(image)
    mask = torch.tensor(mask)
    
    
    print(image, mask)
    return image, mask

def __len__(self):

    return len(self.imgs)