|
|
|
@ -640,7 +640,7 @@ def max_pool2d(x,
|
|
|
|
|
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
|
|
|
|
|
The default value is 0.
|
|
|
|
|
ceil_mode (bool): when True, will use `ceil` instead of `floor` to compute the output shape
|
|
|
|
|
return_indices (bool): Whether to return the max indices along with the outputs.
|
|
|
|
|
return_indices (bool): Whether to return the max indices along with the outputs. Default False, only support `"NCHW"` data format
|
|
|
|
|
data_format (string): The data format of the input and output data. An optional string from: `"NCHW"`, `"NHWC"`.
|
|
|
|
|
The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of:
|
|
|
|
|
`[batch_size, input_channels, input_height, input_width]`.
|
|
|
|
@ -690,15 +690,30 @@ def max_pool2d(x,
|
|
|
|
|
padding, padding_algorithm = _update_padding_nd(
|
|
|
|
|
padding, num_dims=2, channel_last=channel_last, ceil_mode=ceil_mode)
|
|
|
|
|
|
|
|
|
|
if data_format == "NHWC" and return_indices:
|
|
|
|
|
raise ValueError(
|
|
|
|
|
"When setting return_indices to true, data_format must be set to NCHW in API:max_pool2d"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if in_dygraph_mode():
|
|
|
|
|
output = core.ops.max_pool2d_with_index(
|
|
|
|
|
x, 'ksize', kernel_size, 'global_pooling', False, 'strides', stride,
|
|
|
|
|
'paddings', padding, 'padding_algorithm', padding_algorithm,
|
|
|
|
|
'use_cudnn', True, 'ceil_mode', ceil_mode, 'use_mkldnn', False,
|
|
|
|
|
'exclusive', True, 'data_format', data_format)
|
|
|
|
|
return output if return_indices else output[0]
|
|
|
|
|
if data_format == "NCHW":
|
|
|
|
|
output = core.ops.max_pool2d_with_index(
|
|
|
|
|
x, 'ksize', kernel_size, 'global_pooling', False, 'strides',
|
|
|
|
|
stride, 'paddings', padding, 'padding_algorithm',
|
|
|
|
|
padding_algorithm, 'use_cudnn', True, 'ceil_mode', ceil_mode,
|
|
|
|
|
'use_mkldnn', False, 'exclusive', True, 'data_format',
|
|
|
|
|
data_format)
|
|
|
|
|
return output if return_indices else output[0]
|
|
|
|
|
elif data_format == "NHWC" and not return_indices:
|
|
|
|
|
output = core.ops.pool2d(
|
|
|
|
|
x, 'pooling_type', 'max', 'ksize', kernel_size,
|
|
|
|
|
'global_pooling', False, 'padding_algorithm', padding_algorithm,
|
|
|
|
|
'strides', stride, 'paddings', padding, 'use_cudnn', True,
|
|
|
|
|
'ceil_mode', ceil_mode, 'use_mkldnn', False, 'exclusive', True,
|
|
|
|
|
'data_format', data_format)
|
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
|
op_type = 'max_pool2d_with_index'
|
|
|
|
|
op_type = 'max_pool2d_with_index' if data_format == "NCHW" else "max_pool2d"
|
|
|
|
|
helper = LayerHelper(op_type, **locals())
|
|
|
|
|
dtype = helper.input_dtype()
|
|
|
|
|
pool_out = helper.create_variable_for_type_inference(dtype)
|
|
|
|
@ -755,7 +770,7 @@ def max_pool3d(x,
|
|
|
|
|
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
|
|
|
|
|
The default value is 0.
|
|
|
|
|
ceil_mode (bool): ${ceil_mode_comment}
|
|
|
|
|
return_indices (bool): Whether to return the max indices along with the outputs.
|
|
|
|
|
return_indices (bool): Whether to return the max indices along with the outputs. Default False. Only support "NDCHW" data_format.
|
|
|
|
|
data_format (string): The data format of the input and output data. An optional string from: `"NCDHW"`, `"NDHWC"`.
|
|
|
|
|
The default is `"NCDHW"`. When it is `"NCDHW"`, the data is stored in the order of:
|
|
|
|
|
`[batch_size, input_channels, input_depth, input_height, input_width]`.
|
|
|
|
@ -801,15 +816,30 @@ def max_pool3d(x,
|
|
|
|
|
padding, padding_algorithm = _update_padding_nd(
|
|
|
|
|
padding, 3, channel_last=channel_last, ceil_mode=ceil_mode)
|
|
|
|
|
|
|
|
|
|
if data_format == "NDHWC" and return_indices:
|
|
|
|
|
raise ValueError(
|
|
|
|
|
"When setting return_indices to true, data_format must be set to NCDHW in API:max_pool3d"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if in_dygraph_mode():
|
|
|
|
|
output = core.ops.max_pool3d_with_index(
|
|
|
|
|
x, 'pooling_type', 'max', 'ksize', kernel_size, 'strides', stride,
|
|
|
|
|
'paddings', padding, 'global_pooling', False, 'padding_algorithm',
|
|
|
|
|
padding_algorithm, 'use_cudnn', True, 'ceil_mode', ceil_mode,
|
|
|
|
|
'use_mkldnn', False, 'exclusive', True, 'data_format', data_format)
|
|
|
|
|
return output if return_indices else output[0]
|
|
|
|
|
if data_format == "NCDHW":
|
|
|
|
|
output = core.ops.max_pool3d_with_index(
|
|
|
|
|
x, 'pooling_type', 'max', 'ksize', kernel_size, 'strides',
|
|
|
|
|
stride, 'paddings', padding, 'global_pooling', False,
|
|
|
|
|
'padding_algorithm', padding_algorithm, 'use_cudnn', True,
|
|
|
|
|
'ceil_mode', ceil_mode, 'use_mkldnn', False, 'exclusive', True,
|
|
|
|
|
'data_format', data_format)
|
|
|
|
|
return output if return_indices else output[0]
|
|
|
|
|
elif data_format == "NDHWC" and not return_indices:
|
|
|
|
|
output = core.ops.pool3d(
|
|
|
|
|
x, 'pooling_type', 'max', 'ksize', kernel_size,
|
|
|
|
|
'global_pooling', False, 'padding_algorithm', padding_algorithm,
|
|
|
|
|
'strides', stride, 'paddings', padding, 'use_cudnn', True,
|
|
|
|
|
'ceil_mode', ceil_mode, 'use_mkldnn', False, 'exclusive', True,
|
|
|
|
|
'data_format', data_format)
|
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
|
op_type = "max_pool3d_with_index"
|
|
|
|
|
op_type = "max_pool3d_with_index" if data_format == "NCDHW" else "max_pool3d"
|
|
|
|
|
helper = LayerHelper(op_type, **locals())
|
|
|
|
|
dtype = helper.input_dtype()
|
|
|
|
|
pool_out = helper.create_variable_for_type_inference(dtype)
|
|
|
|
|