def __init__(self, input_channel, n_blocks=9, dropout=False): super(ResnetGenerator, self).__init__() self.conv0 = ConvBN(input_channel, 32, 7, 1) self.conv1 = ConvBN(32, 64, 3, 2, padding=1) self.conv2 = ConvBN(64, 128, 3, 2, padding=1) dim = 128 self.resnet_blocks = [] for i in range(n_blocks): block = self.add_sublayer("generator_%d" % (i + 1), ResnetBlock(dim, dropout)) self.resnet_blocks.append(block) self.deconv0 = DeConvBN(dim, 32 * 2, 3, 2, padding=[1, 1], outpadding=[0, 1, 0, 1]) self.deconv1 = DeConvBN(32 * 2, 32, 3, 2, padding=[1, 1], outpadding=[0, 1, 0, 1]) self.conv3 = ConvBN(32, input_channel, 7, 1, norm=False, act=False, use_bias=True)
def __init__(self, input_channel, d_dims=64, d_nlayers=3): super(NLayerDiscriminator, self).__init__() self.conv0 = ConvBN(input_channel, d_dims, 4, 2, 1, norm=False, use_bias=True, relufactor=0.2) nf_mult, nf_mult_prev = 1, 1 self.conv_layers = [] for n in range(1, d_nlayers): nf_mult_prev = nf_mult nf_mult = min(2**n, 8) conv = self.add_sublayer( 'discriminator_%d' % (n), ConvBN(d_dims * nf_mult_prev, d_dims * nf_mult, 4, 2, 1, relufactor=0.2)) self.conv_layers.append(conv) nf_mult_prev = nf_mult nf_mult = min(2**d_nlayers, 8) self.conv4 = ConvBN(d_dims * nf_mult_prev, d_dims * nf_mult, 4, 1, 1, relufactor=0.2) self.conv5 = ConvBN(d_dims * nf_mult, 1, 4, 1, 1, norm=False, act=None, use_bias=True, relufactor=0.2)
def __init__(self, dim, dropout=False): super(ResnetBlock, self).__init__() self.dropout = dropout self.conv0 = ConvBN(dim, dim, 3, 1) self.conv1 = ConvBN(dim, dim, 3, 1, act=None)