Image classification problem using convolutional neural networks
In the __getitem__ method you should return both the image and the label, in your current example you are trying to get the image by indexing the img_dir variable or your class, which won't work since this is of type Path. The general steps for the __getitem__ method is that you should (1) get the path of image, (2) load the image and (3) convert the image to a tensor for pytorch to use. This would something like this:
from torch.utils.data import Dataset
import torchvision.transforms as transforms
from pathlib import Path
import pandas as pd
from PIL import Image

class LesionDataset(Dataset):
    def __init__(self, img_dir, labels_fname):
        self.img_dir = Path(img_dir)
        self.img_paths = self.img_dir.glob(&quot;*&quot;)
        self.labels_fname = pd.read_csv(labels_fname)

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

    def __getitem__(self, idx):
        img_path = self.img_paths[idx]
        image = Image.open(img_path)
        image = transforms.ToTensor()(image)
        label = self.labels_fname[idx]
        return image, label