Beispiel #1
0
 def _make_sequential(self,key):
     definition = {
         'pixel_norm'   :    lambda *config: PixelwiseNormalization(),
         'truncation'   :    lambda *config: TruncationTrick(
                                 num_target=8, threshold=0.7, output_num=18, style_dim=512 ),
         'fc'           :    lambda *config: EqualizedFullyConnect(
                                 in_dim=config[0],out_dim=config[1], lr=0.01),
         'b'            :    lambda *config: AddChannelwiseBias(out_channels=config[0], lr=0.01),
         'bias'         :    lambda *config: AddChannelwiseBias(out_channels=config[0], lr=1.0),
         'amp'          :    lambda *config: Amplify(2**0.5),
         'Lrelu'        :    lambda *config: nn.LeakyReLU(negative_slope=0.2),
         'EqConvT3x3EX' :    lambda *config: EqualizedFusedConvTransposed2d(
                                 in_channels=config[0], out_channels=config[1],
                                 kernel_size=3, stride=1, padding=1, lr=1.0),
         'EqConv3x3'    :    lambda *config: EqualizedConv2d(
                                 in_channels=config[0], out_channels=config[1],
                                 kernel_size=3, stride=1, padding=1, lr=1.0),
         'EqConv1x1'    :    lambda *config: EqualizedConv2d(
                                 in_channels=config[0], out_channels=config[1],
                                 kernel_size=1, stride=1, padding=0, lr=1.0),
         'noiseE'       :    lambda *config: ElementwiseNoise(ch=config[0], size_hw=config[1]),
         'blur3x3'      :    lambda *config: Blur3x3(),
         'up'           :    lambda *config: nn.Upsample(
                                 scale_factor=2,mode='nearest'),
         'adain'        :    lambda *config: EqualizedAdaIN(
                                 fmap_ch=config[0], style_ch=512, lr=1.0),
     }
     return nn.Sequential(*[ definition[k](*cfg) for k,*cfg in self.structure[key]])
 def _make_sequential(self, key):
     definition = {
         'pixel_norm':
         lambda *config: PixelwiseNormalization(),
         'truncation':
         lambda *config: TruncationTrick(
             num_target=10, threshold=0.7, output_num=18, style_dim=512),
         'fc':
         lambda *config: EqualizedFullyConnect(
             in_dim=config[0], out_dim=config[1], lr=0.01),
         'b':
         lambda *config: AddChannelwiseBias(out_channels=config[0], lr=0.01
                                            ),
         'bias':
         lambda *config: AddChannelwiseBias(out_channels=config[0], lr=1.0),
         'amp':
         lambda *config: Amplify(2**0.5),
         'Lrelu':
         lambda *config: nn.LeakyReLU(negative_slope=0.2),
         'EqModConvT3x3':
         lambda *config: EqualizedModulatedConvTranspose2d(
             in_channels=config[0],
             out_channels=config[1],
             kernel_size=3,
             stride=2,
             padding=0,
             demodulate=True,
             lr=1.0,
             style_dim=512),
         'EqModConv3x3':
         lambda *config: EqualizedModulatedConv2d(in_channels=config[0],
                                                  out_channels=config[1],
                                                  kernel_size=3,
                                                  stride=1,
                                                  padding=1,
                                                  demodulate=True,
                                                  lr=1.0,
                                                  style_dim=512),
         'EqModConv1x1':
         lambda *config: EqualizedModulatedConv2d(in_channels=config[0],
                                                  out_channels=config[1],
                                                  kernel_size=1,
                                                  stride=1,
                                                  padding=0,
                                                  demodulate=False,
                                                  lr=1.0,
                                                  style_dim=512),
         'noiseP':
         lambda *config: PixelwiseNoise(resolution=config[0]),
         'blurEX':
         lambda *config: FusedBlur3x3(),
     }
     return nn.Sequential(
         *[definition[k](*cfg) for k, *cfg in self.structure[key]])
    def __init__(self,
                 in_channels,
                 out_channels,
                 kernel_size,
                 style_dim,
                 padding,
                 stride,
                 demodulate=True,
                 lr=1):
        super().__init__()

        self.padding, self.stride = padding, stride
        self.demodulate = demodulate

        self.weight = nn.Parameter(
            torch.randn(in_channels, out_channels, kernel_size, kernel_size))
        torch.nn.init.normal_(self.weight.data, mean=0.0, std=1.0 / lr)
        self.weight_scaler = 1 / (in_channels * kernel_size *
                                  kernel_size)**0.5 * lr

        self.fc = EqualizedFullyConnect(style_dim, in_channels, lr)
        self.bias = AddChannelwiseBias(in_channels, lr)
Beispiel #4
0
 def __init__(self, fmap_ch, style_ch, lr):
     super().__init__()
     # lr = 1.0
     self.fc = EqualizedFullyConnect(style_ch, fmap_ch*2, lr)
     self.bias = AddChannelwiseBias(fmap_ch*2,lr)