Training maskrcnn with transforms

Joysn: <p>I am working through the tutorials and want to apply transformations to get more variety in the training images.<br>
In the tutorials, during training, the data preparation is done in the <code>Dataset.__get_item__</code> method.</p>
<p>This will lead to a procedure like this:</p>
<ul>
<li>feed dataset to training loop without transformations, run through epochs</li>
<li>feed dataset to training loop with a set of transformations, run through epochs</li>
<li>repeat previous step till all desired transformations have been applied</li>
</ul>
<p>Can this lead to a good model, or shouldnt the training use a combined dataset and sample from that randomly?</p>

ptrblck: <aside class="quote no-group" data-username="Joysn" data-post="1" data-topic="155897">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/j/77aa72/48.png" class="avatar"> Joysn:</div>
<blockquote>
<p>This will lead to a procedure like this:</p>
<ul>
<li>feed dataset to training loop without transformations, run through epochs</li>
<li>feed dataset to training loop with a set of transformations, run through epochs</li>
<li>repeat previous step till all desired transformations have been applied</li>
</ul>
</blockquote>
</aside>
<p>I’m not sure which tutorial you are referring to, but commonly the transformations are applied on each sample and there won’t be an epoch with “raw” samples (i.e. where the transformations weren’t applied to the samples).</p>
<p>Also, especially during training the transformations are “random”, i.e. there won’t be a point where <em>all</em> transformations were applied.</p>

Joysn: <p>I was referring to the tutorials at [1] and [2], where the transforms are optional. This gave me the impression that calls with and without transforms are desired.</p>
<p>Does it make sense to run training sessions with different transforms or should all transformations be given to the Dataset at once and let the randomness decide which ones to use in each epoch?</p>
<p>[1] <a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html" class="inline-onebox" rel="noopener nofollow ugc">TorchVision Object Detection Finetuning Tutorial — PyTorch Tutorials 1.12.0+cu102 documentation</a><br>
[2] <a href="https://pytorch.org/tutorials/beginner/basics/data_tutorial.html" class="inline-onebox" rel="noopener nofollow ugc">Datasets &amp; DataLoaders — PyTorch Tutorials 1.12.0+cu102 documentation</a></p>

ptrblck: <p>I think it depends on your use case, but the common approach would be to pass all (random) transformations to the <code>Dataset</code>, but I would also recommend to check reference implementations and see how these models are trained. If you want to select some transforms randomly you could use <code>torchvision.transforms.RandomChoice</code>.</p>

Joysn: <p>Ok, I think I made the wrong assumptions. I thought it is good for training to use the original data and transform it in several ways to get some variation. If my dataset has 20.000 samples, applying random transformations like this will end up with a dataset which has still 20.000 images. My assumption was that I will at minimum use the original dataset, and then transform each image multiple times with different transformations, to increase variety and will end up with a training dataset of 100.000 images.<br>
Therefore one of my thoughts was if I should build up a 100.000 images dataset which is used with shuffled sampling or if I use 20.000 images multiple times with different transformations.<br>
But then i am thinking if it is good to train with those transformations one after each other, and maybe introduce some bias into the model.</p>