Thank you very much.I tried to write in this way,is there anything wrong?Can I now use  “cat_img” to train my netural network?
from future import print_function, division
import torch
import torchvision.transforms.functional as TF
from torch.utils.data import Dataset
from PIL import Image
image_paths = ‘F:\picture1’
target_paths = ‘F:\picture2’
class MyDataset(Dataset):
def init(self, image_paths, target_paths, train=True):
self.image_paths = image_paths
self.target_paths = target_paths
def transform(self, image, mask,cat_img):

    
    image = TF.to_tensor(image)
    mask = TF.to_tensor(mask)
    cat_img = torch.cat((image, mask), dim=1)
    return image, mask,cat_img

def __getitem__(self, index):
    image = Image.open(self.image_paths[index])
    mask = Image.open(self.target_paths[index])
    x, y = self.transform(image, mask)
    return x, y

def __len__(self):
    return len(self.image_paths)