Example #1
0
 def __init__(self, in_ch, out_ch, initialW, sn=True):
     super(DiscriminatorBlock, self).__init__()
     with self.init_scope():
         if sn:
             self.c0 = SNConvolution2D(in_ch,
                                       in_ch,
                                       3,
                                       1,
                                       1,
                                       initialW=initialW)
             self.c1 = SNConvolution2D(in_ch,
                                       out_ch,
                                       3,
                                       1,
                                       1,
                                       initialW=initialW)
         else:
             self.c0 = L.Convolution2D(in_ch,
                                       in_ch,
                                       3,
                                       1,
                                       1,
                                       initialW=initialW)
             self.c1 = L.Convolution2D(in_ch,
                                       out_ch,
                                       3,
                                       1,
                                       1,
                                       initialW=initialW)
Example #2
0
 def __init__(self,
              in_channels,
              out_channels,
              ksize=3,
              pad=1,
              activation=F.relu):
     super(OptimizedBlock, self).__init__()
     initializer = chainer.initializers.GlorotUniform(math.sqrt(2))
     initializer_sc = chainer.initializers.GlorotUniform()
     self.activation = activation
     with self.init_scope():
         self.c1 = SNConvolution2D(in_channels,
                                   out_channels,
                                   ksize=ksize,
                                   pad=pad,
                                   initialW=initializer)
         self.c2 = SNConvolution2D(out_channels,
                                   out_channels,
                                   ksize=ksize,
                                   pad=pad,
                                   initialW=initializer)
         self.c_sc = SNConvolution2D(in_channels,
                                     out_channels,
                                     ksize=1,
                                     pad=0,
                                     initialW=initializer_sc)
Example #3
0
 def __init__(self,
              in_channels,
              out_channels,
              hidden_channels=None,
              ksize=3,
              pad=1,
              activation=F.relu,
              downsample=False):
     super(BlockDisc, self).__init__()
     initializer = chainer.initializers.GlorotUniform(math.sqrt(2))
     initializer_sc = chainer.initializers.GlorotUniform()
     self.activation = activation
     self.downsample = downsample
     self.learnable_sc = (in_channels != out_channels) or downsample
     hidden_channels = in_channels if hidden_channels is None else hidden_channels
     with self.init_scope():
         self.c1 = SNConvolution2D(in_channels,
                                   hidden_channels,
                                   ksize=ksize,
                                   pad=pad,
                                   initialW=initializer)
         self.c2 = SNConvolution2D(hidden_channels,
                                   out_channels,
                                   ksize=ksize,
                                   pad=pad,
                                   initialW=initializer)
         if self.learnable_sc:
             self.c_sc = SNConvolution2D(in_channels,
                                         out_channels,
                                         ksize=1,
                                         pad=0,
                                         initialW=initializer_sc)
Example #4
0
File: net.py Project: min9813/GAN
    def __init__(self, output_dim=1, wscale=0.02, ch=512, bottom_width=4):
        w = chainer.initializers.Normal(wscale)
        super(SNMnistDiscriminator, self).__init__()
        with self.init_scope():
            self.c0 = SNConvolution2D(1,
                                      ch // 4,
                                      ksize=4,
                                      stride=2,
                                      pad=1,
                                      initialW=w)
            self.c1 = SNConvolution2D(ch // 4,
                                      ch // 2,
                                      ksize=4,
                                      stride=2,
                                      pad=2,
                                      initialW=w)
            self.c2 = SNConvolution2D(ch // 2,
                                      ch,
                                      ksize=4,
                                      stride=2,
                                      pad=1,
                                      initialW=w)

            self.lout = SNLinear(bottom_width * bottom_width * ch,
                                 output_dim,
                                 initialW=w)
 def __init__(self, ch):
     w = chainer.initializers.HeNormal()
     super(SNOptimizedResBlock1, self).__init__()
     with self.init_scope():
         self.c0 = SNConvolution2D(3, ch, 3, 1, 1, initialW=w)
         self.c1 = SNConvolution2D(ch, ch, 3, 1, 1, initialW=w)
         self.cs = SNConvolution2D(3, ch, 1, initialW=w)
 def __init__(self, ch):
     w = chainer.initializers.HeNormal()
     super(SNDownResBlock2, self).__init__()
     with self.init_scope():
         self.c0 = SNConvolution2D(ch, ch, 3, 1, 1, initialW=w) # differ from DownResBlock1
         self.c1 = SNConvolution2D(ch, ch, 3, 1, 1, initialW=w)
         self.cs = SNConvolution2D(ch, ch, 3, 1, 1, initialW=w) # differ from DownResBlock1
Example #7
0
 def __init__(self, in_ch, out_ch, initialW):
     super(SNDiscriminatorBlock, self).__init__()
     with self.init_scope():
         self.c0 = SNConvolution2D(in_ch, in_ch, 3, 1, 1, initialW=initialW)
         self.c1 = SNConvolution2D(in_ch,
                                   out_ch,
                                   3,
                                   1,
                                   1,
                                   initialW=initialW)
Example #8
0
 def __init__(self, ch=512, wscale=0.02):
     w = chainer.initializers.Normal(wscale)
     super(SNPGGANDiscriminator, self).__init__()
     with self.init_scope():
         self.in1 = SNConvolution2D(3, ch // 8, 1, 1, 0, initialW=w)
         self.b1 = SNDiscriminatorBlock(ch // 8, ch // 4, initialW=w)
         self.b2 = SNDiscriminatorBlock(ch // 4, ch // 2, initialW=w)
         self.b3 = SNDiscriminatorBlock(ch // 2, ch, initialW=w)
         self.out0 = SNConvolution2D(ch, ch, 3, 1, 1, initialW=w)
         self.out1 = SNConvolution2D(ch, ch, 4, 1, 0, initialW=w)
         self.out2 = SNLinear(ch, 1, initialW=w)
Example #9
0
    def __init__(self, ch=512, wscale=0.02, sn=True):
        super(Discriminator32, self).__init__()
        w = chainer.initializers.Normal(wscale)
        with self.init_scope():
            if sn:
                print('sn')
                self.in_ = SNConvolution2D(3, ch // 8, 1, 1, 0, initialW=w)
            else:
                print('sn_free')
                self.in_ = L.Convolution2D(3, ch // 8, 1, 1, 0, initialW=w)

            self.b3 = DiscriminatorBlock(ch // 8, ch // 4, initialW=w, sn=sn)
            self.b2 = DiscriminatorBlock(ch // 4, ch // 2, initialW=w, sn=sn)
            self.b1 = DiscriminatorBlock(ch // 2, ch, initialW=w, sn=sn)

            if sn:
                self.out0 = SNConvolution2D(ch, ch, 3, 1, 1, initialW=w)
                self.out1 = SNConvolution2D(ch, ch, 4, 1, 0, initialW=w)
                self.out2 = SNLinear(ch, 1, initialW=w)
            else:
                self.out0 = L.Convolution2D(ch, ch, 3, 1, 1, initialW=w)
                self.out1 = L.Convolution2D(ch, ch, 4, 1, 0, initialW=w)
                self.out2 = L.Linear(ch, 1, initialW=w)
Example #10
0
 def __init__(self, bottom_width=4, ch=512, wscale=0.02, output_dim=1):
     w = chainer.initializers.Normal(wscale)
     super(SNDCGANDiscriminator, self).__init__()
     with self.init_scope():
         self.c0_0 = SNConvolution2D(3, ch // 8, 3, 1, 1, initialW=w)
         self.c0_1 = SNConvolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w)
         self.c1_0 = SNConvolution2D(ch // 4, ch // 4, 3, 1, 1, initialW=w)
         self.c1_1 = SNConvolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w)
         self.c2_0 = SNConvolution2D(ch // 2, ch // 2, 3, 1, 1, initialW=w)
         self.c2_1 = SNConvolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w)
         self.c3_0 = SNConvolution2D(ch // 1, ch // 1, 3, 1, 1, initialW=w)
         self.l4 = SNLinear(bottom_width * bottom_width * ch,
                            output_dim,
                            initialW=w)