def __init__(self, config_text, norm_nc, label_nc):
    super().__init__()
    assert config_text.startswith('spade')
    parsed = re.search('spade(\\D+)(\\d)x\\d', config_text)
    param_free_norm_type = str(parsed.group(1))
    ks = int(parsed.group(2))
    if (param_free_norm_type == 'instance'):
        self.param_free_norm = nn.InstanceNorm2d(norm_nc, affine=False)
    elif (param_free_norm_type == 'syncbatch'):
        self.param_free_norm = SynchronizedBatchNorm2d(norm_nc, affine=False)
    elif (param_free_norm_type == 'batch'):
        self.param_free_norm = nn.BatchNorm2d(norm_nc, affine=False)
    else:
        raise ValueError(('%s is not a recognized param-free norm type in SPADE' % param_free_norm_type))
    nhidden = 128
    pw = (ks // 2)
    self.mlp_shared = nn.Sequential(nn.Conv2d(label_nc, nhidden, kernel_size=ks, padding=pw), nn.ReLU())
    self.mlp_gamma = nn.Conv2d(nhidden, norm_nc, kernel_size=ks, padding=pw)
    self.mlp_beta = nn.Conv2d(nhidden, norm_nc, kernel_size=ks, padding=pw)
def __init__(self, config_text, norm_nc, label_nc):
    super().__init__()
    assert config_text.startswith('spade')
    parsed = re.search('spade(\\D+)(\\d)x\\d', config_text)
    param_free_norm_type = str(parsed.group(1))
    ks = int(parsed.group(2))
    if (param_free_norm_type == 'instance'):
        self.param_free_norm = nn.InstanceNorm2d(norm_nc, affine=False)
    elif (param_free_norm_type == 'syncbatch'):
        self.param_free_norm = SynchronizedBatchNorm2d(norm_nc, affine=False)
    elif (param_free_norm_type == 'batch'):
        self.param_free_norm = nn.BatchNorm2d(norm_nc, affine=False)
    else:
        raise ValueError(('%s is not a recognized param-free norm type in SPADE' % param_free_norm_type))
    nhidden = 128
    pw = (ks // 2)
    self.mlp_shared = nn.Sequential(nn.Conv2d(label_nc, nhidden, kernel_size=ks, padding=pw), nn.ReLU())
    self.mlp_gamma = nn.Conv2d(nhidden, norm_nc, kernel_size=ks, padding=pw)
    self.mlp_beta = nn.Conv2d(nhidden, norm_nc, kernel_size=ks, padding=pw)