I want to compute the mean pixel values of all training images and subtract them from all images as opposed to finding the mean of a single image and subtracting it from the pixels in that image.
This is the specific line in the paper which are trying to reproduce the results for:

After resizing the images, we compute the mean pixel values
of the training images and subtract them from all images to
center the training data.

and here’s the link to the full paper https://arxiv.org/pdf/1704.03557.pdf 1
This is what I have now:
class RvlCdipDataset(Dataset):
    def __init__(self, labels_file, img_dir, transform=None, target_transform=None):
        self.img_labels = pd.read_table(labels_file, header=None, names = ["image_path", "label"],sep=" ")
        self.img_dir = img_dir
        self.transform = transform
        self.target_transform = target_transform

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

    def __getitem__(self, idx):
        img_path = os.path.join(self.img_dir, self.img_labels.iloc[idx, 0])
        image = Image.open(img_path).convert('RGB')
        label = self.img_labels.iloc[idx, 1]
        if self.transform:
            image = self.transform(image)
        if self.target_transform:
            label = self.target_transform(label)
        return image, label

dataset = RvlCdipDataset('labels/train.txt', 
                         'images/', 
                         transform=transforms.Compose([transforms.ToTensor(),
                                                       transforms.Resize((224,224))]))