MCPcopy Create free account
hub / github.com/NVlabs/SPADE / __init__

Method __init__

models/networks/normalization.py:67–94  ·  view source on GitHub ↗
(self, config_text, norm_nc, label_nc)

Source from the content-addressed store, hash-verified

65# |label_nc|: the #channels of the input semantic map, hence the input dim of SPADE
66class SPADE(nn.Module):
67 def __init__(self, config_text, norm_nc, label_nc):
68 super().__init__()
69
70 assert config_text.startswith('spade')
71 parsed = re.search('spade(\D+)(\d)x\d', config_text)
72 param_free_norm_type = str(parsed.group(1))
73 ks = int(parsed.group(2))
74
75 if param_free_norm_type == 'instance':
76 self.param_free_norm = nn.InstanceNorm2d(norm_nc, affine=False)
77 elif param_free_norm_type == 'syncbatch':
78 self.param_free_norm = SynchronizedBatchNorm2d(norm_nc, affine=False)
79 elif param_free_norm_type == 'batch':
80 self.param_free_norm = nn.BatchNorm2d(norm_nc, affine=False)
81 else:
82 raise ValueError('%s is not a recognized param-free norm type in SPADE'
83 % param_free_norm_type)
84
85 # The dimension of the intermediate embedding space. Yes, hardcoded.
86 nhidden = 128
87
88 pw = ks // 2
89 self.mlp_shared = nn.Sequential(
90 nn.Conv2d(label_nc, nhidden, kernel_size=ks, padding=pw),
91 nn.ReLU()
92 )
93 self.mlp_gamma = nn.Conv2d(nhidden, norm_nc, kernel_size=ks, padding=pw)
94 self.mlp_beta = nn.Conv2d(nhidden, norm_nc, kernel_size=ks, padding=pw)
95
96 def forward(self, x, segmap):
97

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected