Convolutional model yields different inputs on parts of image and whole image

Julien_Despois: <p>Hi there,</p>
<p>I am working on a <strong>fully convolutional autoencoder</strong>, which I train on 256x256 patches of my 1024x1024 images using torchvision RandomCrop data augmentation method on the fly.</p>
<p>I see very different results when using my model to predict one 256x256 patch, versus the whole 1024x1024 source image. From my understanding the local weights of the convolutional kernels should learn to recognize the same patterns in both cases as the scale between the patches and full image is conserved.</p>
<p>Am I missing something?</p>
<p>Thanks in advance!</p>
<p>Julien</p>

ptrblck: <aside class="quote no-group" data-username="Julien_Despois" data-post="1" data-topic="57789">
<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/julien_despois/48/16530_2.png" class="avatar"> Julien_Despois:</div>
<blockquote>
<p>From my understanding the local weights of the convolutional kernels should learn to recognize the same patterns in both cases as the scale between the patches and full image is conserved.</p>
</blockquote>
</aside>
<p>I’m not sure I’m understanding this claim correctly, but how would the kernels preserve the scale, if you increase the spatial resolution by 4x?</p>

Julien_Despois: <p>I mean if I take a 1024x1024 image, split it into 256x256 chunks and train on these chunks, running the resulting trained fully convolutional model on the full 1024x1024 model should work, as each feature map should be simply 4 times as wide and high as the ones during training, but that shouldn’t matter as at the kernel level (say 5x5) the resolution is still the same. I should get an output of size 1024x1024 (as I do get) instead of the 256x256 I have in training.  No?</p>

ptrblck: <p>Thanks for clarifying the use case, as I’ve misunderstood it.<br>
Yes, you should get the same output (besides the edges from the smaller patches due to padding).</p>
<p>Could you post the code you are using to recreate the larger output?</p>

Julien_Despois: <p>I effectively see differences when the input is scaled (sliding a patch on the large image works fine, but as soon as I change the input image from 256px (size of the patch during training) to 512 then 1024 on the full image, the output of the StarGAN progressively degrades. Here is the model I use. Could it be beacause of the InstanceNorm2D?</p>
<p>Generator(<br>
(encoder): Sequential(<br>
(0): Conv2d(5, 64, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3))<br>
(1): InstanceNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(2): ReLU(inplace)<br>
(3): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1))<br>
(4): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(5): ReLU(inplace)<br>
(6): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1))<br>
(7): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(8): ReLU(inplace)<br>
(9): ResidualBlock(<br>
(main): Sequential(<br>
(0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(1): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(2): ReLU(inplace)<br>
(3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(4): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
)<br>
)<br>
(10): ResidualBlock(<br>
(main): Sequential(<br>
(0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(1): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(2): ReLU(inplace)<br>
(3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(4): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
)<br>
)<br>
(11): ResidualBlock(<br>
(main): Sequential(<br>
(0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(1): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(2): ReLU(inplace)<br>
(3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(4): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
)<br>
)<br>
(12): ResidualBlock(<br>
(main): Sequential(<br>
(0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(1): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(2): ReLU(inplace)<br>
(3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(4): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
)<br>
)<br>
(13): ResidualBlock(<br>
(main): Sequential(<br>
(0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(1): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(2): ReLU(inplace)<br>
(3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(4): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
)<br>
)<br>
(14): ResidualBlock(<br>
(main): Sequential(<br>
(0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(1): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(2): ReLU(inplace)<br>
(3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(4): InstanceNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
)<br>
)<br>
)<br>
(decoder): Sequential(<br>
(0): Upsample(scale_factor=2, mode=nearest)<br>
(1): Conv2d(256, 128, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))<br>
(2): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(3): ReLU(inplace)<br>
(4): Upsample(scale_factor=2, mode=nearest)<br>
(5): Conv2d(128, 64, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))<br>
(6): InstanceNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(7): ReLU(inplace)<br>
(8): Conv2d(64, 4, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3))<br>
(9): Tanh()<br>
)<br>
)</p>
<p>Thanks again!</p>