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

Function add_norm_layer

models/networks/normalization.py:24–48  ·  view source on GitHub ↗
(layer)

Source from the content-addressed store, hash-verified

22
23 # this function will be returned
24 def add_norm_layer(layer):
25 nonlocal norm_type
26 if norm_type.startswith('spectral'):
27 layer = spectral_norm(layer)
28 subnorm_type = norm_type[len('spectral'):]
29
30 if subnorm_type == 'none' or len(subnorm_type) == 0:
31 return layer
32
33 # remove bias in the previous layer, which is meaningless
34 # since it has no effect after normalization
35 if getattr(layer, 'bias', None) is not None:
36 delattr(layer, 'bias')
37 layer.register_parameter('bias', None)
38
39 if subnorm_type == 'batch':
40 norm_layer = nn.BatchNorm2d(get_out_channel(layer), affine=True)
41 elif subnorm_type == 'sync_batch':
42 norm_layer = SynchronizedBatchNorm2d(get_out_channel(layer), affine=True)
43 elif subnorm_type == 'instance':
44 norm_layer = nn.InstanceNorm2d(get_out_channel(layer), affine=False)
45 else:
46 raise ValueError('normalization layer %s is not recognized' % subnorm_type)
47
48 return nn.Sequential(layer, norm_layer)
49
50 return add_norm_layer
51

Callers

nothing calls this directly

Calls 1

get_out_channelFunction · 0.85

Tested by

no test coverage detected