UpSample does not work!


(Siddhesh Thakur) #1
class Decode3d(nn.Module):
def __init__(self, input_channels, output_channels, conv_bias=True,
             lrelu_inplace=True, Trilinear = True, res = False):
    super(Decode3d, self).__init__()
    if Trilinear:
        self.up = nn.Upsample(scale_factor = 3, mode = 'trilinear', align_corners = True)
    else:
        self.up = nn.ConvTranspose3d(input_channels, input_channels,
                    kernel_size = 3, stride =2, output_padding = 1)
    self.lrelu_inplace = lrelu_inplace
    self.conv_bias = conv_bias
    self.input_channels = input_channels
    self.output_channels= output_channels
    self.residual = res
    self.conv1 = nn.Conv3d(input_channels, input_channels, kernel_size = 3,
                           stride = 1,padding = 1, bias=conv_bias)
    self.bn_1 = nn.InstanceNorm3d(input_channels, affine=True)
    self.conv2 = nn.Conv3d(output_channels, output_channels, kernel_size = 1,
                           stride = 1,padding = 0, bias=conv_bias)
    self.bn_2 = nn.InstanceNorm3d(output_channels, affine=True)

def forward(self, x1, x2):
    print("Decoding", x1.shape, x2.shape)
    x = self.up(x1)
    print("After upconv, X1 shape:", x1.shape)
    x = torch.cat([x1, x2], dim = 1)
    if self.residual == True:
        skip = x
    x = self.bn_1(x)
    x = F.leaky_relu(x)
    x = self.conv1(x)
    x = self.bn_2(x)
    x = F.leaky_relu(x)
    x = self.conv2(x)
    if self.residual == True:
        x = x + skip
    print("Exiting deconding", x.shape)
    return x

Hi,
I am trying to upsample and concatenate but for some reason Upsample does not seem to work? Is there something wrong with the syntax?


(Olof Harrysson) #2

You are printing the wrong variable. print("After upconv, X1 shape:", x1.shape) should be print("After upconv, X shape:", x.shape)


(Siddhesh Thakur) #3

Hi, I have solved it. You guys mentioned the wrong error but it lead me down a good road.

x = torch.cat([x1, x2], dim = 1) ###!Wrong
x = torch.cat([x, x2], dim = 1) ###Correct.

Cheers~