# Path: utils/layers.py
# def batch_norm2(layer, **kwargs):
#     nonlinearity = getattr(layer, 'nonlinearity', None)
#     if nonlinearity is not None:
#         layer.nonlinearity = nn.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:
#         from lasagne.layers.special import NonlinearityLayer
#         layer = NonlinearityLayer(layer, nonlinearity, name='%s_nl' % layer.name)
#     return layer


import lasagne as nn
from lasagne.layers import dnn
from utils.layers import batch_norm2 as batch_norm


def conv2dbn(l, name, **kwargs):
    """ Batch normalized DNN Conv2D Layer """
    l = nn.layers.dnn.Conv2DDNNLayer(
        l, name=name,
        **kwargs
    )

# Path: utils/layers.py
# def batch_norm2(layer, **kwargs):
#     nonlinearity = getattr(layer, 'nonlinearity', None)
#     if nonlinearity is not None:
#         layer.nonlinearity = nn.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:
#         from lasagne.layers.special import NonlinearityLayer
#         layer = NonlinearityLayer(layer, nonlinearity, name='%s_nl' % layer.name)
#     return layer


# Path: utils/layer_macros.py
import lasagne as nn
from lasagne.layers import dnn
from utils.layers import batch_norm2 as batch_norm



def conv2dbn(l, name, **kwargs):
    """ Batch normalized DNN Conv2D Layer """
    l = nn.layers.dnn.Conv2DDNNLayer(
        l, name=name,
        **kwargs
    )

    l = batch_norm(l, name='%sbn' % name)