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)
def __init__(self, in_channels, out_channels, hidden_channels=None, ksize=3, pad=1, activation=F.relu, downsample=False): super(Block, self).__init__() initializer = chainer.initializers.GlorotUniform(math.sqrt(2)) initializer_sc = chainer.initializers.GlorotUniform() self.activation = activation self.downsample = 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) self.c_sc = SNConvolution2D(in_channels, out_channels, ksize=1, pad=0, initialW=initializer_sc)
def __init__(self, in_size, in_channel, out_channel): super(ResBlock, self).__init__() with self.init_scope(): self.HyperBN = HyperBatchNormalization(in_size, in_channel) self.conv0 = SNConvolution2D(in_channel, out_channel, 3, 1, 1) self.HyperBN_1 = HyperBatchNormalization(in_size, out_channel) self.conv1 = SNConvolution2D(out_channel, out_channel, 3, 1, 1) self.conv_sc = SNConvolution2D(in_channel, out_channel, 1, 1, 0)
def __init__(self, ch): self.ch = ch super(NonLocalBlock, self).__init__() with self.init_scope(): self.theta = SNConvolution2D(ch, ch // 8, 1, 1, 0, nobias=True) self.phi = SNConvolution2D(ch, ch // 8, 1, 1, 0, nobias=True) self.g = SNConvolution2D(ch, ch // 2, 1, 1, 0, nobias=True) self.o_conv = SNConvolution2D(ch // 2, ch, 1, 1, 0, nobias=True) self.gamma = L.Parameter(np.array(0, dtype="float32"))
def __init__(self, in_channels, out_channels, hidden_channels=None, ksize=3, pad=1, activation=F.relu, downsample=False): super(Block, 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) self.c_sc.u = np.ones((1, out_channels)).astype(np.float32) self.c1.u = np.ones((1, 128)).astype(np.float32) self.c2.u = np.ones((1, 128)).astype(np.float32)
def __init__(self, ch=96): self.ch = ch super(Generator, self).__init__() with self.init_scope(): self.linear = L.Linear(1000, 128, nobias=True) self.G_linear = SNLinear(20, 4 * 4 * 16 * ch) self.GBlock = ResBlock(148, 16 * ch, 16 * ch) self.GBlock_1 = ResBlock(148, 16 * ch, 8 * ch) self.GBlock_2 = ResBlock(148, 8 * ch, 8 * ch) self.GBlock_3 = ResBlock(148, 8 * ch, 4 * ch) self.GBlock_4 = ResBlock(148, 4 * ch, 2 * ch) self.attention = NonLocalBlock(2 * ch) self.GBlock_5 = ResBlock(148, 2 * ch, ch) self.ScaledCrossReplicaBN = L.BatchNormalization(ch) self.conv_2d = SNConvolution2D(ch, 3, 3, 1, 1)