

def batch_norm(layer, **kwargs):
    "\n    Apply batch normalization to an existing layer. This is a convenience\n    function modifying an existing layer to include batch normalization: It\n    will steal the layer's nonlinearity if there is one (effectively\n    introducing the normalization right before the nonlinearity), remove\n    the layer's bias if there is one (because it would be redundant), and add\n    a :class:`BatchNormLayer` and :class:`NonlinearityLayer` on top.\n\n    Parameters\n    ----------\n    layer : A :class:`Layer` instance\n        The layer to apply the normalization to; note that it will be\n        irreversibly modified as specified above\n    **kwargs\n        Any additional keyword arguments are passed on to the\n        :class:`BatchNormLayer` constructor.\n\n    Returns\n    -------\n    BatchNormLayer or NonlinearityLayer instance\n        A batch normalization layer stacked on the given modified `layer`, or\n        a nonlinearity layer stacked on top of both if `layer` was nonlinear.\n\n    Examples\n    --------\n    Just wrap any layer into a :func:`batch_norm` call on creating it:\n\n    >>> from lasagne.layers import InputLayer, DenseLayer, batch_norm\n    >>> from lasagne.nonlinearities import tanh\n    >>> l1 = InputLayer((64, 768))\n    >>> l2 = batch_norm(DenseLayer(l1, num_units=500, nonlinearity=tanh))\n\n    This introduces batch normalization right before its nonlinearity:\n\n    >>> from lasagne.layers import get_all_layers\n    >>> [l.__class__.__name__ for l in get_all_layers(l2)]\n    ['InputLayer', 'DenseLayer', 'BatchNormLayer', 'NonlinearityLayer']\n    "
    nonlinearity = getattr(layer, 'nonlinearity', None)
    if (nonlinearity is not None):
        layer.nonlinearity = lasagne.nonlinearities.identity
    if (hasattr(layer, 'b') and (layer.b is not None)):
        del layer.params[layer.b]
        layer.b = None
    layer = BatchNormLayer(layer, **kwargs)
    if (nonlinearity is not None):
        layer = L.NonlinearityLayer(layer, nonlinearity)
    return nonlinearity

dataset/ETHPy150Open rllab/rllab/rllab/core/lasagne_layers.py batch_norm/VarMisuse@118/723 `layer`->`nonlinearity`