title: PyTorch : How to apply the same random transformation to multiple image?
body: <p>I am writing a simple transformation for a dataset which contains many pairs of images. As a data augmentation, I want to apply some random transformation for each pair but the images in that pair should be transformed in the same way.
  For example, given a pair of two images <code>A</code> and <code>B</code>, if <code>A</code> is flipped horizontally, <code>B</code> must be flipped horizontally as <code>A</code>. Then the next pair <code>C</code> and <code>D</code> should be differently transformed from <code>A</code> and <code>B</code> but <code>C</code> and <code>D</code> are transformed in the same way. I am trying that in the way below</p>
  <pre class="lang-py prettyprint-override"><code>import random
  import numpy as np
  import torchvision.transforms as transforms
  from PIL import Image
  
  img_a = Image.open(&quot;sample_ajpg&quot;) # note that two images have the same size
  img_b = Image.open(&quot;sample_b.png&quot;)
  img_c, img_d = Image.open(&quot;sample_c.jpg&quot;), Image.open(&quot;sample_d.png&quot;)
  
  transform = transforms.RandomChoice(
      [transforms.RandomHorizontalFlip(), 
       transforms.RandomVerticalFlip()]
  )
  random.seed(0)
  display(transform(img_a))
  display(transform(img_b))
  
  random.seed(1)
  display(transform(img_c))
  display(transform(img_d))
  </code></pre>
  <p>Yet、 the above code does not choose the same transformation and as I tested, it is dependent on the number of times <code>transform</code> is called.</p>
  <p>Is there any way to force <code>transforms.RandomChoice</code> to use the same transform when specified?</p>