Center crop and resize in compose or sequential transform

brunoj: <p>Hello! I have a question that what actually does the resize and center crop do? I have a signal image with dimensions 432x288 and I want to apply Alexnet for 28x28 size. Now I’m confused how to change size here. I tried to visualize the behavior using PyTorch documents but don’t understand it. How can I achieve a 28x28 size what should I pass here in resize and centercrop. Also what impact does compose and sequential transform have? I’m attaching my attempt:</p>
<p>transform = transforms.Compose([<br>
transforms.Grayscale(1),<br>
transforms.Resize(28),<br>
transforms.CenterCrop(28),<br>
transforms.ToTensor()<br>
<span class="hashtag-raw">#transforms</span>.Normalize(mean=[0.16592294], std=[0.31460345])<br>
])</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/c/0cfe60c8860174b5fb1c6da328aa9af37b93cdd9.png" data-download-href="https://discuss.pytorch.org/uploads/default/0cfe60c8860174b5fb1c6da328aa9af37b93cdd9" title="Screenshot (13)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/c/0cfe60c8860174b5fb1c6da328aa9af37b93cdd9_2_690x388.png" alt="Screenshot (13)" data-base62-sha1="1QWJohR2T9q8Il7oCGH3lQl2lsZ" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/c/0cfe60c8860174b5fb1c6da328aa9af37b93cdd9_2_690x388.png, https://discuss.pytorch.org/uploads/default/optimized/3X/0/c/0cfe60c8860174b5fb1c6da328aa9af37b93cdd9_2_1035x582.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/0/c/0cfe60c8860174b5fb1c6da328aa9af37b93cdd9_2_1380x776.png 2x" data-dominant-color="F1F0F1"><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">Screenshot (13)</span><span class="informations">1920×1080 215 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><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/c/5c3bcb472de12993983f64dd75ecb283d6696357.png" data-download-href="https://discuss.pytorch.org/uploads/default/5c3bcb472de12993983f64dd75ecb283d6696357" title="Screenshot (14)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/c/5c3bcb472de12993983f64dd75ecb283d6696357_2_690x388.png" alt="Screenshot (14)" data-base62-sha1="d9W2chrIGJd8SazDWpk0AxdHLWT" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/c/5c3bcb472de12993983f64dd75ecb283d6696357_2_690x388.png, https://discuss.pytorch.org/uploads/default/optimized/3X/5/c/5c3bcb472de12993983f64dd75ecb283d6696357_2_1035x582.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/5/c/5c3bcb472de12993983f64dd75ecb283d6696357_2_1380x776.png 2x" data-dominant-color="F1F1F1"><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">Screenshot (14)</span><span class="informations">1920×1080 206 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>

brunoj: <p>besides how can I visualize once resize the image and centercrop the resized one? I want to check this thing right after transform part considering my rgb image will be now grayscaled.</p>

ptrblck: <p>Try to pass the <code>size</code> argument as a <code>tuple</code> to make sure both spatial dimensions are resized.<br>
A center crop of the same size after a resize operation should not be needed as you would just slice the entire image again without changing anything.<br>
You could apply the transformations separately and check the intermediate outputs.</p>

brunoj: <p>ok but can you tell me what i the difference in resize and center crop? why they both are needed as i have seen others doing both at the same time.</p>

ptrblck: <p>The resize transformation resizes the input image by interpolating values to create the desired output size.<br>
Center crop on the other hand just crops the image from the center pixel using the specific size.<br>
You don’t need the crop the image if the size won’t change.<br>
Others would most likely use it for data augmentation with different sizes.</p>