def get_initializer(name, activation=None):
    """
    generate initializer
    Args:
        name (str): initializer name
        activation (str): activation
    return: initializer
    """
    if activation in [None, 'id', 'identity', 'linear', 'modrelu']:
        nonlinearity = 'linear'
    elif activation in ['relu', 'tanh', 'sigmoid']:
        nonlinearity = activation
    elif activation in ['gelu', 'swish', 'silu']:
        nonlinearity = 'relu' # Close to ReLU so approximate with ReLU's gain
    else:
        raise NotImplementedError(f'get_initializer: activation {activation} not supported')

    if name == 'uniform':
        initializer = partial(nn.init.kaiming_uniform_, nonlinearity=nonlinearity)
    elif name == 'normal':
        initializer = partial(nn.init.kaiming_normal_, nonlinearity=nonlinearity)
    elif name == 'xavier':
        initializer = nn.init.xavier_normal_
    elif name == 'zero':
        initializer = partial(nn.init.constant_, val=0)
    elif name == 'one':
        initializer = partial(nn.init.constant_, val=1)
    else:
        raise NotImplementedError(f'get_initializer: initializer type {name} not supported')

    return initializer
generate initializer
Args:
name (str): initializer name
activation (str): activation
return: initializer
towhee/models/vis4mer/get_initializer.py