Functioning of Torch transform on a batch

Ajinkya_Ambatwar: <p>Hello, I have a very simple doubt that’s bothering me.<br>
I want to know, when I create a transform for a dataloader which takes a batch_size=32, do all the transforms happen exactly same to all the 32 samples in the batch?<br>
For eg.</p>
<pre><code class="lang-auto">transforms = compose([RandomAffine(10), toTensor()])
# random affine transformation within (-10,10) degrees
ds = utils.DataLoader(some_custom_data_loader, transforms, batch_size = 32)
</code></pre>
<p>Now if I take any one batch generated from it, will all the samples in it have exactly same affine transformation(in degrees), say 5 deg to all of them?<br>
Or will each sample(out of 32) have a different transformation (like [5, -1, 0, 9, -2,…(32 samples)] degrees)?</p>
<p>Excuse me if this is too simple doubt!<br>
Thank you in advance!</p>

ariG23498: <p>Hey <a class="mention" href="/u/ajinkya_ambatwar">@Ajinkya_Ambatwar</a></p>
<p>I have made a <a href="https://gist.github.com/ariG23498/e23ef78cbd8655ffd17590db66f6d797" rel="noopener nofollow ugc">GIST</a> that takes an image and transforms is with <code>RandomAffine(10)</code>. This indeed randomly transforms each image in the batch with a random degree.</p>
<p>I would also like to add that, in the code snippet you have provided, I guess you have mistyped <code>utils.DataLoader</code>, it should have been <code>utils.data.DataLoader</code>. Another little thing to add here is that a DataSet has a transform parameter. The GIST provided has all that you would need for an ablation study.</p>
<p>Hope this might help you <img src="https://discuss.pytorch.org/images/emoji/apple/grinning_face_with_smiling_eyes.png?v=12" title=":grinning_face_with_smiling_eyes:" class="emoji" alt=":grinning_face_with_smiling_eyes:" loading="lazy" width="20" height="20"></p>
<h2><a name="screen-shot-1" class="anchor" href="#screen-shot-1"></a>Screen-Shot</h2>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/5/05cf844b54f5b884ec42843ebf8653758a531379.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/05cf844b54f5b884ec42843ebf8653758a531379" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/5/05cf844b54f5b884ec42843ebf8653758a531379_2_237x500.jpeg" alt="image" data-base62-sha1="PoZnwAFpEoi6LEjFDPlNKlGQM9" width="237" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/5/05cf844b54f5b884ec42843ebf8653758a531379_2_237x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/0/5/05cf844b54f5b884ec42843ebf8653758a531379_2_355x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/0/5/05cf844b54f5b884ec42843ebf8653758a531379_2_474x1000.jpeg 2x" data-dominant-color="D0CEC9"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">532×1122 97.3 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

Ajinkya_Ambatwar: <p>Hey <a class="mention" href="/u/arig23498">@ariG23498</a> , thank you for a very clear explanation. I had one more doubt related to compose transforms. If I compose few transformations say RandomAffine, RandomCrop etc. are all the transformations applied on to the image in a single iteration? Or say few of the transforms are selected and applied in a single iteration?</p>

ariG23498: <p>A compose is a composition of many transforms all together. You can think of a compose as just another complex transform. To answer your question, yes, a compose should apply all the transforms it is made up of, to the image in a single operation.</p>

Ajinkya_Ambatwar: <p>Thank you! That’s helpful!!</p>