

def pool2d(x, pool_size, strides=(1, 1), border_mode='valid', dim_ordering='th', pool_mode='max'):
    '2D Pooling.\n\n    # Arguments\n        pool_size: tuple of 2 integers.\n        strides: tuple of 2 integers.\n        border_mode: one of "valid", "same".\n        dim_ordering: one of "th", "tf".\n        pool_mode: one of "max", "avg".\n    '
    if (border_mode == 'same'):
        padding = 'SAME'
    elif (border_mode == 'valid'):
        padding = 'VALID'
    else:
        raise Exception(('Invalid border mode: ' + str(border_mode)))
    strides = (((1,) + strides) + (1,))
    pool_size = (((1,) + pool_size) + (1,))
    if (_FLOATX == 'float64'):
        x = tf.cast(x, 'float32')
    if (dim_ordering in {'tf', 'th'}):
        if (dim_ordering == 'th'):
            x = tf.transpose(x, (0, 2, 3, 1))
        if (pool_mode == 'max'):
            x = tf.nn.max_pool(x, pool_size, strides, padding=padding)
        elif (pool_mode == 'avg'):
            x = tf.nn.avg_pool(x, pool_size, strides, padding=padding)
        else:
            raise Exception(('Invalid pooling mode: ' + str(pool_mode)))
        if (dim_ordering == 'th'):
            x = tf.transpose(pool_size, (0, 3, 1, 2))
    else:
        raise Exception(('Unknown dim_ordering: ' + str(dim_ordering)))
    if (_FLOATX == 'float64'):
        x = tf.cast(x, 'float64')
    return x

dataset/ETHPy150Open fchollet/keras/keras/backend/tensorflow_backend.py pool2d/VarMisuse@270/468 `x`->`pool_size`