MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / pool2d

Function pool2d

tensorflow/python/keras/backend.py:5112–5167  ·  view source on GitHub ↗

2D Pooling. Arguments: x: Tensor or variable. pool_size: tuple of 2 integers. strides: tuple of 2 integers. padding: string, `"same"` or `"valid"`. data_format: string, `"channels_last"` or `"channels_first"`. pool_mode: string, `"max"` or `"avg"`. Returns:

(x,
           pool_size,
           strides=(1, 1),
           padding='valid',
           data_format=None,
           pool_mode='max')

Source from the content-addressed store, hash-verified

5110
5111@keras_export('keras.backend.pool2d')
5112def pool2d(x,
5113 pool_size,
5114 strides=(1, 1),
5115 padding='valid',
5116 data_format=None,
5117 pool_mode='max'):
5118 """2D Pooling.
5119
5120 Arguments:
5121 x: Tensor or variable.
5122 pool_size: tuple of 2 integers.
5123 strides: tuple of 2 integers.
5124 padding: string, `"same"` or `"valid"`.
5125 data_format: string, `"channels_last"` or `"channels_first"`.
5126 pool_mode: string, `"max"` or `"avg"`.
5127
5128 Returns:
5129 A tensor, result of 2D pooling.
5130
5131 Raises:
5132 ValueError: if `data_format` is neither `"channels_last"` or
5133 `"channels_first"`.
5134 ValueError: if `pool_size` is not a tuple of 2 integers.
5135 ValueError: if `strides` is not a tuple of 2 integers.
5136 ValueError: if `pool_mode` is neither `"max"` or `"avg"`.
5137 """
5138 if data_format is None:
5139 data_format = image_data_format()
5140 if data_format not in {'channels_first', 'channels_last'}:
5141 raise ValueError('Unknown data_format: ' + str(data_format))
5142 if len(pool_size) != 2:
5143 raise ValueError('`pool_size` must be a tuple of 2 integers.')
5144 if len(strides) != 2:
5145 raise ValueError('`strides` must be a tuple of 2 integers.')
5146
5147 x, tf_data_format = _preprocess_conv2d_input(x, data_format)
5148 padding = _preprocess_padding(padding)
5149 if tf_data_format == 'NHWC':
5150 strides = (1,) + strides + (1,)
5151 pool_size = (1,) + pool_size + (1,)
5152 else:
5153 strides = (1, 1) + strides
5154 pool_size = (1, 1) + pool_size
5155
5156 if pool_mode == 'max':
5157 x = nn.max_pool(
5158 x, pool_size, strides, padding=padding, data_format=tf_data_format)
5159 elif pool_mode == 'avg':
5160 x = nn.avg_pool(
5161 x, pool_size, strides, padding=padding, data_format=tf_data_format)
5162 else:
5163 raise ValueError('Invalid pooling mode: ' + str(pool_mode))
5164
5165 if data_format == 'channels_first' and tf_data_format == 'NHWC':
5166 x = array_ops.transpose(x, (0, 3, 1, 2)) # NHWC -> NCHW
5167 return x
5168
5169

Callers

nothing calls this directly

Calls 4

image_data_formatFunction · 0.85
_preprocess_conv2d_inputFunction · 0.85
_preprocess_paddingFunction · 0.85
transposeMethod · 0.80

Tested by

no test coverage detected