@ptrblck. I did manage to get this at the moment. I was expecting to get the count of data from len(). It’s returning me 35 for len, but I have 43 images and 43 masks.
Also, I add normalisation to the data as they are large values. To normalise them, I got the mean of an image (198) and standard deviation (64)? My question is:
should I get the standard deviation and mean of all dataset or one image?
Could you please let me know where I am doing wrong. thank you
I am getting an error train_set = CustomDataset(folder_mask) TypeError: __init__() missing 1 required positional argument: 'target_paths'
import torch
from torch.utils.data.dataset import Dataset  # For custom data-sets
import torchvision.transforms as transforms
from PIL import Image
import numpy as np
import torchvision
import matplotlib.pyplot as plt


folder_data = "D:\\Neda\\Pytorch\\U-net\\BMMCdata\\data"
folder_mask = "D:\\Neda\\Pytorch\\U-net\\BMMCmasks\\masks"


class CustomDataset(Dataset):
    def __init__(self, image_paths, target_paths, train=True):   # initial logic happens like transform

        self.image_paths = image_paths
        self.target_paths = target_paths
        self.transforms = transforms.Compose(
            [transforms.ToTensor(),
             transforms.Normalize((198, 198, 198), (64, 64, 64))])

    def __getitem__(self, index):

        image = Image.open(self.image_paths[index])
        mask = Image.open(self.target_paths[index])
        t_image, t_mask = self.transforms(image, mask)
        return t_image, t_mask

    def __len__(self):  # return count of sample we have

        return len(self.image_paths)


custom_img = CustomDataset(folder_data, folder_mask)
print(len(custom_img))

train_set = CustomDataset(folder_mask)
train_set = torch.utils.data.TensorDataset(train_set, train=True)
train_loader = torch.utils.data.DataLoader(train_set, batch_size=4, shuffle=True, num_workers=1)


test_set = CustomDataset(folder_data)
test_set = torch.utils.data.DataLoader(test_set, train=False)
test_loader = torch.utils.data.DataLoader(test_set, batch_size=4, shuffle=False, num_workers=1)


def imshow(img):
    img = img / 2
    npimg = img.numpy()
    plt.imshow(np.transpose(npimg, (1, 2, 0)))


dataiter = iter(train_loader)
images, mask = dataiter.next()

imshow(torchvision.utils.make_grid(images))
plt.show()