nn/nn_utils.py
def conv_conv_pool(input_, n_filters, training, name, kernel_size=(3, 3),
                   conv_stride=(1, 1), pool=True, pool_size=(2, 2), pool_stride=(2, 2),
                   activation=tf.nn.relu, padding='same', bn=True, dropout=False, dropout_rate=None):
    """
    Do multiple convolution and one pooling, this is the basic component in many CNNs
    :param input_: input variable
    :param n_filters: #filters in each convolutional layers, could be a list
    :param training: indicates it is in training or not
    :param name: name for this variable scope
    :param kernel_size: kernel size
    :param conv_stride: filter stride for convolutional layers
    :param pool: use pooling or not
    :param pool_size: size of the pooling
    :param pool_stride: stride of the pooling
    :param activation: activation function to use
    :param padding: which padding scheme to use in convolutional layers
    :param bn: use batch normalization or not
    :param dropout: use dropout or not
    :param dropout_rate: drop out rate
    :return:
    """
    net = input_

    with tf.variable_scope('layer{}'.format(name)):
        for i, F in enumerate(n_filters):
            net = tf.layers.conv2d(net, F, kernel_size, activation=None, strides=conv_stride,
                                   padding=padding, name='conv_{}'.format(i + 1))
            if bn:
                net = tf.layers.batch_normalization(net, training=training, name='bn_{}'.format(i + 1))
            net = activation(net, name='relu_{}'.format(name, i + 1))
            if dropout:
                net = tf.layers.dropout(net, rate=dropout_rate, training=training,
                                        name='drop_{}'.format(name, i + 1))

        if pool is False:
            return net

        pool = tf.layers.max_pooling2d(net, pool_size, strides=pool_stride, name='pool_{}'.format(name))
        return net, pool

    Do multiple convolution and one pooling, this is the basic component in many CNNs
    :param input_: input variable
    :param n_filters: #filters in each convolutional layers, could be a list
    :param training: indicates it is in training or not
    :param name: name for this variable scope
    :param kernel_size: kernel size
    :param conv_stride: filter stride for convolutional layers
    :param pool: use pooling or not
    :param pool_size: size of the pooling
    :param pool_stride: stride of the pooling
    :param activation: activation function to use
    :param padding: which padding scheme to use in convolutional layers
    :param bn: use batch normalization or not
    :param dropout: use dropout or not
    :param dropout_rate: drop out rate
    :return:
    
Do multiple convolution and one pooling, this is the basic component in many CNNs
Do multiple convolution and one pooling this is the basic component in many CNNs
def conv_conv_pool(input_, n_filters, training, name, kernel_size=(3, 3),
                   conv_stride=(1, 1), pool=True, pool_size=(2, 2), pool_stride=(2, 2),
                   activation=tf.nn.relu, padding='same', bn=True, dropout=False, dropout_rate=None):
    net = input_
    with tf.variable_scope('layer{}'.format(name)):
        for i, F in enumerate(n_filters):
            net = tf.layers.conv2d(net, F, kernel_size, activation=None, strides=conv_stride,
                                   padding=padding, name='conv_{}'.format(i + 1))
            if bn:
                net = tf.layers.batch_normalization(net, training=training, name='bn_{}'.format(i + 1))
            net = activation(net, name='relu_{}'.format(name, i + 1))
            if dropout:
                net = tf.layers.dropout(net, rate=dropout_rate, training=training,
                                        name='drop_{}'.format(name, i + 1))
        if pool is False:
            return net
        pool = tf.layers.max_pooling2d(net, pool_size, strides=pool_stride, name='pool_{}'.format(name))
        return net, pool
def conv_conv_pool ( input_ , n_filters , training , name , kernel_size = ( 3 , 3 ) , conv_stride = ( 1 , 1 ) , pool = True , pool_size = ( 2 , 2 ) , pool_stride = ( 2 , 2 ) , activation = tf . nn . relu , padding = 'same' , bn = True , dropout = False , dropout_rate = None ) : net = input_ with tf . variable_scope ( 'layer{}' . format ( name ) ) : for i , F in enumerate ( n_filters ) : net = tf . layers . conv2d ( net , F , kernel_size , activation = None , strides = conv_stride , padding = padding , name = 'conv_{}' . format ( i + 1 ) ) if bn : net = tf . layers . batch_normalization ( net , training = training , name = 'bn_{}' . format ( i + 1 ) ) net = activation ( net , name = 'relu_{}' . format ( name , i + 1 ) ) if dropout : net = tf . layers . dropout ( net , rate = dropout_rate , training = training , name = 'drop_{}' . format ( name , i + 1 ) ) if pool is False : return net pool = tf . layers . max_pooling2d ( net , pool_size , strides = pool_stride , name = 'pool_{}' . format ( name ) ) return net , pool
Do multiple convolution and one pooling, this is the basic component in many CNNs
Do multiple convolution and one pooling this is the basic component in many CNNs
"""
    Do multiple convolution and one pooling, this is the basic component in many CNNs
    :param input_: input variable
    :param n_filters: #filters in each convolutional layers, could be a list
    :param training: indicates it is in training or not
    :param name: name for this variable scope
    :param kernel_size: kernel size
    :param conv_stride: filter stride for convolutional layers
    :param pool: use pooling or not
    :param pool_size: size of the pooling
    :param pool_stride: stride of the pooling
    :param activation: activation function to use
    :param padding: which padding scheme to use in convolutional layers
    :param bn: use batch normalization or not
    :param dropout: use dropout or not
    :param dropout_rate: drop out rate
    :return:
    """
None
input_
None
n_filters
filters in each convolutional layers, could be a list
filters in each convolutional layers could be a list
training
indicates it is in training or not
indicates it is in training or not
name
name for this variable scope
name for this variable scope
kernel_size
None
conv_stride
filter stride for convolutional layers
filter stride for convolutional layers
pool
use pooling or not
use pooling or not
pool_size
size of the pooling
size of the pooling
pool_stride
stride of the pooling
stride of the pooling
activation
activation function to use
activation function to use
padding
which padding scheme to use in convolutional layers
which padding scheme to use in convolutional layers
bn
use batch normalization or not
use batch normalization or not
dropout
use dropout or not
use dropout or not
dropout_rate
drop out rate
drop out rate