How to fix convolution output size

0000000000000
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:

        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)
        )

the outpute i’ve gote :

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]

so the probleme is the output of Conv2d of self.last_one_down_2_p2 suppose to be 512 but i’ve got 128
can anone help me to solve it?

nn.PixelShuffle will change the number of output channels as described in the docs:

Input: (N, L, H_in, W_in) where L= C * upscale_factor**2
Output: (N, C, H_out, W_out) where H_out = H_in * upscale_factor and W_out = W_in * upscale_factor

In your case, upscale_factor=2, so the input channels are defined as L = 512 = 128 * 2**2, and the output channels thus C = 128.

2 Likes

@ptrblck Thank you for your response. It was of great help. :heart_eyes: :smiling_face_with_three_hearts:
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. :exploding_head: