Sayed_Nadim:

spectral_norm


I changed the mosel by the below code but I still got same problem
class ResidualBlock(nn.Module):
    def __init__(self, input_dim, output_dim, kernel_size, resample=None, hw=DIM):
        super(ResidualBlock, self).__init__()

        self.input_dim = input_dim
        self.output_dim = output_dim
        self.kernel_size = kernel_size
        self.resample = resample
        self.bn1 = None
        self.bn2 = None
        self.relu1 = nn.ReLU()
        self.relu2 = nn.ReLU()
        
        if resample == 'down':
            self.bn1 = nn.LayerNorm([input_dim, hw, hw])
            self.bn2 = nn.LayerNorm([input_dim, hw, hw])
        elif resample == 'up':
            self.bn1 = nn.BatchNorm2d(input_dim)
            self.bn2 = nn.BatchNorm2d(output_dim)
        elif resample == None:
            # TODO: ????
            self.bn1 = nn.BatchNorm2d(output_dim)
            self.bn2 = nn.LayerNorm([input_dim, hw, hw])
        else:
            raise Exception('invalid resample value')

        if resample == 'down':
            self.conv_shortcut = SpectralNorm(MeanPoolConv(input_dim, output_dim, kernel_size=1, he_init=False))
            self.conv_1 = SpectralNorm(MyConvo2d(input_dim, input_dim, kernel_size=kernel_size, bias=False))
            self.conv_2 = SpectralNorm(ConvMeanPool(input_dim, output_dim, kernel_size=kernel_size))
            
        elif resample == 'up':
            self.conv_shortcut = SpectralNorm(UpSampleConv(input_dim, output_dim, kernel_size=1, he_init=False))
            self.conv_1 = SpectralNorm(UpSampleConv(input_dim, output_dim, kernel_size=kernel_size, bias=False))
            self.conv_2 = SpectralNorm(MyConvo2d(output_dim, output_dim, kernel_size=kernel_size))
            
        elif resample == None:
            self.conv_shortcut = SpectralNorm(MyConvo2d(input_dim, output_dim, kernel_size=1, he_init=False))
            self.conv_1 = SpectralNorm(MyConvo2d(input_dim, input_dim, kernel_size=kernel_size, bias=False))
            self.conv_2 = SpectralNorm(MyConvo2d(input_dim, output_dim, kernel_size=kernel_size))
        else:
            raise Exception('invalid resample value')

    def forward(self, input):
        if self.input_dim == self.output_dim and self.resample == None:
            shortcut = input
        else:
            shortcut = self.conv_shortcut(input)

        output = input
        output = self.bn1(output)
        output = self.relu1(output)
        output = self.conv_1(output)
        output = self.bn2(output)
        output = self.relu2(output)
        output = self.conv_2(output)

        return shortcut + output