How to fix convolution output size

username: Parlak_Sair
cooked: <p><img src="https://discuss.pytorch.org/uploads/default/original/3X/b/4/b4be416c1684ea50e49ed64861315b66a38d1e6e.png" alt="0000000000000" data-base62-sha1="pMVz37E5V2dzbuCppHU4ZX8wO18" width="425" height="247"><br>
this is a part of the network i’m creating where the numbres presente the numbre on feature maps. This is the code i proposed:</p>
<pre><code class="lang-auto">        self.last_one_down_1=nn.Sequential(
          nn.BatchNorm2d(num_features=512),
          nn.ReLU()
        )
        self.last_one_down_2_p1=nn.Sequential(
          nn.Conv2d(in_channels=512,out_channels=1024,kernel_size=3),
          nn.ReLU()
        )
        self.last_one_down_2_p2=nn.Sequential(
          nn.Conv2d(in_channels=1024,out_channels=512,kernel_size=3),
          nn.ReLU(),
          nn.PixelShuffle(upscale_factor=2)
        )
</code></pre>
<p>the outpute i’ve gote :</p>
<pre><code class="lang-auto">after last_one_down_1 level ,input shape =  torch.Size([1, 512, 21, 31])
after last_one_down_2_p1 level ,input shape =  torch.Size([1, 1024, 19, 29])
after last_one_down_2_p2 level ,input shape =  torch.Size([1, 128, 34, 54]
</code></pre>
<p>so the probleme is the output of Conv2d of self.last_one_down_2_p2 suppose to be 512 but i’ve got 128<br>
can anone help me to solve it?</p>

username: ptrblck
cooked: <p><code>nn.PixelShuffle</code> will change the number of output channels as described in the <a href="https://pytorch.org/docs/stable/generated/torch.nn.PixelShuffle.html#torch.nn.PixelShuffle">docs</a>:</p>
<blockquote>
<p>Input: (N, L, H_in, W_in) where L= C * upscale_factor**2<br>
Output: (N, C, H_out, W_out) where H_out = H_in * upscale_factor and W_out = W_in * upscale_factor</p>
</blockquote>
<p>In your case, <code>upscale_factor=2</code>, so the input channels are defined as <code>L = 512 = 128 * 2**2</code>, and the output channels thus <code>C = 128</code>.</p>

username: Parlak_Sair
cooked: <p><a class="mention" href="/u/ptrblck">@ptrblck</a>  Thank you for your response. It was of great help. <img src="https://discuss.pytorch.org/images/emoji/apple/heart_eyes.png?v=12" title=":heart_eyes:" class="emoji" alt=":heart_eyes:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/smiling_face_with_three_hearts.png?v=12" title=":smiling_face_with_three_hearts:" class="emoji" alt=":smiling_face_with_three_hearts:" loading="lazy" width="20" height="20"><br>
In fact, I am trying to recreate the RUNet architecture for super image resolution and as a beginner it causes me a lot of problems and a terrible headache. <img src="https://discuss.pytorch.org/images/emoji/apple/exploding_head.png?v=12" title=":exploding_head:" class="emoji" alt=":exploding_head:" loading="lazy" width="20" height="20"><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/b/2b6c5a093837a80cc1fa0ddf467f92cec30b06b0.png" data-download-href="https://discuss.pytorch.org/uploads/default/2b6c5a093837a80cc1fa0ddf467f92cec30b06b0" title="RU-Net"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/b/2b6c5a093837a80cc1fa0ddf467f92cec30b06b0_2_690x322.png" alt="RU-Net" data-base62-sha1="6c8FLDsyYSpWVwkxdcGNilNyPTO" width="690" height="322" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/b/2b6c5a093837a80cc1fa0ddf467f92cec30b06b0_2_690x322.png, https://discuss.pytorch.org/uploads/default/original/3X/2/b/2b6c5a093837a80cc1fa0ddf467f92cec30b06b0.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/2/b/2b6c5a093837a80cc1fa0ddf467f92cec30b06b0.png 2x" data-dominant-color="E2E2E1"><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">RU-Net</span><span class="informations">887×414 41.2 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>