Hello ptrblck, Thanks for your quick response. Actually I discovered I also have images with four channels so I implemented this code in my  custom dataset
import os
import pandas as pd
import torch

from torch.utils.data import Dataset

from skimage import io

class CustomDataset(Dataset):
	
    def __init__(self,csv_file,root_dir,transform=None):
        self.annotations=pd.read_csv(csv_file)
        self.root_dir=root_dir
        self.transform=transform

    def __len__(self):
        return len(self.annotations)
    
    def __getitem__(self,index):
        img_path=os.path.join(self.root_dir,self.annotations.iloc[index,0])
        image=io.imread(img_path)
        
        if len(image.shape) == 2:
        #convert grayscale to RGB
        #image = Image.open(path).convert('RGB') 
            image=torch.from_numpy(image)
            image=torch.stack([image,image,image],0)
            image=torch.transpose(image,0,2)
            image=image.numpy()
            #print('this was 1d before')
            #print(image.shape)
        elif len(image.shape) == 3: 
        #image has 4 channels
            if image.shape[0]==4:
                image=torch.from_numpy(image)
                image = image[:,:,:3]
                image=torch.transpose(image,0,2)
                image=image.numpy()
            
        y_label=torch.tensor(int(self.annotations.iloc[index,2]))

        if self.transform:
            image=self.transform(image)
        return (image,y_label)