Torchvision.transfors: How to perform identical transform on both image and target?

You can also use the standard functions from the library torchvision
example:

from PIL import Image
from torchvision import transforms
from torchvision.transforms import functional as tvF
...
# create custom class transform
class RRC(transforms.RandomResizedCrop):
    def __call__(self, img1, img2):
        assert img1.size == img2.size
        # fix parameter
        i, j, h, w = self.get_params(img1, self.scale, self.ratio)
        # return the image with the same transformation
        return [tvF.resized_crop(img1, i, j, h, w, self.size, self.interpolation), tvF.resized_crop(img2, i, j, h, w, self.size, self.interpolation)]

imgInput = Image.open('input.png')
imgTarget = Image.open('target.png')   

imgInput, imgTarget = RRC(inputSize, scale=(0.5, 1.0), ratio=(5.0/6.0, 6.0/5.0))(imgInput, imgTarget)