def get_nonspade_norm_layer(opt, norm_type='instance'):

    def get_out_channel(layer):
        if hasattr(layer, 'out_channels'):
            return getattr(layer, 'out_channels')
        return layer.weight.size(0)

    def add_norm_layer(layer):
        nonlocal norm_type
        if norm_type.startswith('spectral'):
            layer = spectral_norm(layer)
            subnorm_type = norm_type[len('spectral'):]
        if ((subnorm_type == 'none') or (len(subnorm_type) == 0)):
            return layer
        if (getattr(layer, 'bias', None) is not None):
            delattr(layer, 'bias')
            layer.register_parameter('bias', None)
        if (subnorm_type == 'batch'):
            norm_layer = nn.BatchNorm2d(get_out_channel(layer), affine=True)
        elif (subnorm_type == 'sync_batch'):
            norm_layer = SynchronizedBatchNorm2d(get_out_channel(layer), affine=True)
        elif (subnorm_type == 'instance'):
            norm_layer = nn.InstanceNorm2d(get_out_channel(layer), affine=False)
        else:
            raise ValueError(('normalization layer %s is not recognized' % subnorm_type))
        return nn.Sequential(layer, norm_layer)
    return add_norm_layer
def get_nonspade_norm_layer(opt, norm_type='instance'):

    def get_out_channel(layer):
        if hasattr(layer, 'out_channels'):
            return getattr(layer, 'out_channels')
        return layer.weight.size(0)

    def add_norm_layer(layer):
        nonlocal norm_type
        if norm_type.startswith('spectral'):
            layer = spectral_norm(layer)
            subnorm_type = norm_type[len('spectral'):]
        if ((subnorm_type == 'none') or (len(subnorm_type) == 0)):
            return layer
        if (getattr(layer, 'bias', None) is not None):
            delattr(layer, 'bias')
            layer.register_parameter('bias', None)
        if (subnorm_type == 'batch'):
            norm_layer = nn.BatchNorm2d(get_out_channel(layer), affine=True)
        elif (subnorm_type == 'sync_batch'):
            norm_layer = SynchronizedBatchNorm2d(get_out_channel(layer), affine=True)
        elif (subnorm_type == 'instance'):
            norm_layer = nn.InstanceNorm2d(get_out_channel(layer), affine=False)
        else:
            raise ValueError(('normalization layer %s is not recognized' % subnorm_type))
        return nn.Sequential(layer, norm_layer)
    return add_norm_layer