import tensorflow as tf

def pool(inp, name, kind, size, stride, padding='SAME'):
    
    assert kind in ['max', 'avg']
    
    strides = [1, stride, stride, 1]
    sizes = [1, size, size, 1]
    
    with tf.variable_scope(name):
        if kind == 'max':
            out = tf.nn.max_pool(inp, sizes, strides=strides, padding=padding, name=kind)
        else:
            out = tf.nn.avg_pool(inp, sizes, strides=strides, padding=padding, name=kind)
    
    return out
