How to create a dataloader with variable-size input

How can I use this method when my original and target are images, like pix2pix or semantic segmentation tasks? I asked this question someone referred to this post for a detailed explanation.