The “convolution + batchnorm + activation” layer combination is an extremely powerful set which stabilizes training a lot. Since it appears in many model architectures, here I keep a tensorflow implementation for future reference.

def conv_bn_actv(input, filter_size, kernel, strides, activation="relu", padding="valid", name=None):

    assert isinstance(activation, str)

    if name:
        conv_name = "{}_conv".format(name)
    else:
        conv_name = None
    conv1 = tf.keras.layers.Conv2D(filter_size, kernel, strides=strides, padding=padding, name = conv_name)(input)

    if name:
        bn_name = "{}_bn".format(name)
    else:
        bn_name = None

    bn = tf.keras.layers.BatchNormalization(name=bn_name)(conv1)


    if name:
        actv_name = "{}_actv_{}".format(name, activation)
    else:
        actv_name = None

    actv = tf.keras.layers.Activation(activation, name = actv_name)(bn)

    return actv

0 Comments

Leave a Reply

Your email address will not be published.