本文整理汇总了Python中tensorflow.python.ops.nn.max_pool方法的典型用法代码示例。如果您正苦于以下问题:Python nn.max_pool方法的具体用法?Python nn.max_pool怎么用?Python nn.max_pool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.ops.nn
的用法示例。
在下文中一共展示了nn.max_pool方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tensorflow.python.ops import nn [as 别名]
# 或者: from tensorflow.python.ops.nn import max_pool [as 别名]
def __init__(self, pool_size, strides,
padding='valid', data_format='channels_last',
name=None, **kwargs):
super(MaxPooling1D, self).__init__(
nn.max_pool,
pool_size=pool_size,
strides=strides,
padding=padding,
data_format=data_format,
name=name,
**kwargs)
示例2: pool2d
# 需要导入模块: from tensorflow.python.ops import nn [as 别名]
# 或者: from tensorflow.python.ops.nn import max_pool [as 别名]
def pool2d(x,
pool_size,
strides=(1, 1),
padding='valid',
data_format=None,
pool_mode='max'):
"""2D Pooling.
Arguments:
x: Tensor or variable.
pool_size: tuple of 2 integers.
strides: tuple of 2 integers.
padding: one of `"valid"`, `"same"`.
data_format: one of `"channels_first"`, `"channels_last"`.
pool_mode: one of `"max"`, `"avg"`.
Returns:
A tensor, result of 2D pooling.
Raises:
ValueError: if `data_format` is neither `channels_last` or
`channels_first`.
ValueError: if `pool_mode` is neither `max` or `avg`.
"""
if data_format is None:
data_format = image_data_format()
if data_format not in {'channels_first', 'channels_last'}:
raise ValueError('Unknown data_format ' + str(data_format))
padding = _preprocess_padding(padding)
strides = (1,) + strides + (1,)
pool_size = (1,) + pool_size + (1,)
x = _preprocess_conv2d_input(x, data_format)
if pool_mode == 'max':
x = nn.max_pool(x, pool_size, strides, padding=padding)
elif pool_mode == 'avg':
x = nn.avg_pool(x, pool_size, strides, padding=padding)
else:
raise ValueError('Invalid pooling mode:', pool_mode)
return _postprocess_conv2d_output(x, data_format)
示例3: max_pool2d
# 需要导入模块: from tensorflow.python.ops import nn [as 别名]
# 或者: from tensorflow.python.ops.nn import max_pool [as 别名]
def max_pool2d(inputs,
kernel_size,
stride=2,
padding='VALID',
data_format=DATA_FORMAT_NHWC,
outputs_collections=None,
scope=None):
"""Adds a 2D Max Pooling op.
It is assumed that the pooling is done per image but not in batch or channels.
Args:
inputs: A 4-D tensor of shape `[batch_size, height, width, channels]` if
`data_format` is `NHWC`, and `[batch_size, channels, height, width]` if
`data_format` is `NCHW`.
kernel_size: A list of length 2: [kernel_height, kernel_width] of the
pooling kernel over which the op is computed. Can be an int if both
values are the same.
stride: A list of length 2: [stride_height, stride_width].
Can be an int if both strides are the same. Note that presently
both strides must have the same value.
padding: The padding method, either 'VALID' or 'SAME'.
data_format: A string. `NHWC` (default) and `NCHW` are supported.
outputs_collections: The collections to which the outputs are added.
scope: Optional scope for name_scope.
Returns:
A `Tensor` representing the results of the pooling operation.
Raises:
ValueError: if `data_format` is neither `NHWC` nor `NCHW`.
ValueError: If 'kernel_size' is not a 2-D list
"""
if data_format not in (DATA_FORMAT_NCHW, DATA_FORMAT_NHWC):
raise ValueError('data_format has to be either NCHW or NHWC.')
with ops.name_scope(scope, 'MaxPool2D', [inputs]) as sc:
inputs = ops.convert_to_tensor(inputs)
kernel_h, kernel_w = utils.two_element_tuple(kernel_size)
stride_h, stride_w = utils.two_element_tuple(stride)
if data_format == DATA_FORMAT_NHWC:
ksize = [1, kernel_h, kernel_w, 1]
strides = [1, stride_h, stride_w, 1]
else:
ksize = [1, 1, kernel_h, kernel_w]
strides = [1, 1, stride_h, stride_w]
outputs = nn.max_pool(inputs,
ksize=ksize,
strides=strides,
padding=padding,
data_format=data_format)
return utils.collect_named_outputs(outputs_collections, sc, outputs)