Data Augmentation Fashion MNIST Image

shubz_308: <p>Hi i need to Augment Fashion MNIST with vertical flip and random crop upto 5 pixels in x and y<br>
I used the following commands for training and test data for transform<br>
transform=transforms.Compose(<br>
[transforms.ToTensor(),<br>
transforms.RandomVerticalFlip(p=0.5),<br>
transforms.RandomCrop(5, padding=3, padding_mode=‘constant’),<br>
])</p>
<p>and i get this result.I think i am not doing it right.Any suggestions on how to improve it?</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/d/b/db891fb154a6d7f79e5713a287b65baff5838560.png" alt="image" data-base62-sha1="vk6lQG8yUnaeG2i9l5qCbjX4a9q" width="618" height="455"></p>

eqy: <p>In this case you probably want <code>RandomResizedCrop</code> instead: <a href="https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.RandomResizedCrop" class="inline-onebox" rel="noopener nofollow ugc">torchvision.transforms — Torchvision 0.11.0 documentation</a></p>
<p>Assuming your source images are 28x28, 5 pixels or 23x23 means a minimum scale of ~0.675. Could you check the output with <code>transforms.RandomResizedCrop(input_size, scale=(0.675, 1.0))</code> is what you’re looking for?</p>

shubz_308: <p>How do we check the images are 28 x28?</p>

shubz_308: <aside class="quote no-group" data-username="eqy" data-post="2" data-topic="136762">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/eqy/48/46233_2.png" class="avatar"> eqy:</div>
<blockquote>
<p>transforms.RandomResizedCrop(input_size, scale=(0.675, 1.0))</p>
</blockquote>
</aside>
<p>hmmm now the output is like this .I used inputsize as 23.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/a/8/a85f7d0b9e27e56dd4ea2029e1202b661905f309.png" alt="image" data-base62-sha1="o1uNtWZ4kzi7p4xC842hQLoqYIx" width="605" height="433"><br>
It seems way better.How did you decide the scale values to be 0.675 to 1?</p>

eqy: <blockquote>
<p>How do we check the images are 28 x28?</p>
</blockquote>
<p>You should be able to do this by printing <code>.shape</code> on the input tensor without any transformation (e.g., <code>transform=transforms.Compose( [transforms.ToTensor(),]</code>).</p>
<blockquote>
<p>How did you decide the scale values to be 0.675 to 1?</p>
</blockquote>
<p>This was a guess based on your description of cropping 5 pixels e.g., 23x23/28x28 is approximately 0.675, but this is ultimately a tunable hyperparameter and you can adjust this (e.g., based on validation accuracy).</p>

shubz_308: <p>Thank you so much for clarifying</p>

shubz_308: <p>If we were to use a normal randomcrop and pad,Is there still a possible way to do it?</p>

eqy: <p>This isn’t very common so I’m not sure what the cleanest way to do this is without writing a custom transformation.<br>
What does <code>transforms.RandomCrop(23)</code> give you? or <code>transforms.RandomCrop(28, padding=2)</code>? Note that I picked 2 in this case because I’m not sure if you meant 5 pixels long each axis or each border.</p>

shubz_308: <p>for transforms.RandomCrop(28,padding=2)<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/0/b06a72cc5d0a3e9b1c4f56e906ef5ba784572387.png" data-download-href="https://discuss.pytorch.org/uploads/default/b06a72cc5d0a3e9b1c4f56e906ef5ba784572387" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/b/0/b06a72cc5d0a3e9b1c4f56e906ef5ba784572387.png" alt="image" data-base62-sha1="paE6aw5mi261Gz79btkZhjqHaYL" width="690" height="435" data-dominant-color="BCBCBC"><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">793×501 16.9 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>
<p>for transforms.Randomcrop(23)<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/8/28b0eaafaf45611bbfe7af139289ae0a99c40dfd.png" data-download-href="https://discuss.pytorch.org/uploads/default/28b0eaafaf45611bbfe7af139289ae0a99c40dfd" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/2/8/28b0eaafaf45611bbfe7af139289ae0a99c40dfd.png" alt="image" data-base62-sha1="5NY8KK3F1XyxZB3Z29GzIHLbvAh" width="690" height="435" data-dominant-color="AAAAAA"><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">726×458 8.98 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>
<p>for transforms.ResizedCrop(23,scale=(0.675,1))<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/d/a/da152ca76e34550f614255cb9e403e05d6930246.png" alt="image" data-base62-sha1="v7fsblrzcFm43bvTqZsbKBlvWYu" width="689" height="433"></p>
<p>Hmm the task is to be 5 pixels crop in both x and y ,I guess it means 5 pixels each axis.Maybe its a bit open ended.</p>