Return a normalization layer Parameters: norm_type (str) -- the name of the normalization layer: batch | instance | none For BatchNorm, we use learnable affine parameters and track running statistics (mean/stddev). For InstanceNorm, we do not use learnable affine parameters. We
(norm_type='instance')
| 16 | |
| 17 | |
| 18 | def get_norm_layer(norm_type='instance'): |
| 19 | """Return a normalization layer |
| 20 | |
| 21 | Parameters: |
| 22 | norm_type (str) -- the name of the normalization layer: batch | instance | none |
| 23 | |
| 24 | For BatchNorm, we use learnable affine parameters and track running statistics (mean/stddev). |
| 25 | For InstanceNorm, we do not use learnable affine parameters. We do not track running statistics. |
| 26 | """ |
| 27 | if norm_type == 'batch': |
| 28 | norm_layer = functools.partial(nn.BatchNorm2d, affine=True, track_running_stats=True) |
| 29 | elif norm_type == 'instance': |
| 30 | norm_layer = functools.partial(nn.InstanceNorm2d, affine=False, track_running_stats=False) |
| 31 | elif norm_type == 'none': |
| 32 | def norm_layer(x): return Identity() |
| 33 | else: |
| 34 | raise NotImplementedError('normalization layer [%s] is not found' % norm_type) |
| 35 | return norm_layer |
| 36 | |
| 37 | |
| 38 | def get_scheduler(optimizer, opt): |