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

Method PoolParameters

tensorflow/core/kernels/pooling_ops_common.cc:52–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50} // namespace
51
52PoolParameters::PoolParameters(OpKernelContext* context,
53 const std::vector<int32>& ksize,
54 const std::vector<int32>& stride,
55 Padding padding, TensorFormat data_format,
56 const TensorShape& tensor_in_shape) {
57 // For maxpooling, tensor_in should have 2 spatial dimensions.
58 // Note: the total number of dimensions could be 4 for NHWC, NCHW,
59 // or 5 for NCHW_VECT_C.
60 OP_REQUIRES(context,
61 GetTensorSpatialDims(tensor_in_shape.dims(), data_format) == 2,
62 errors::InvalidArgument(
63 "tensor_in_shape must have 2 spatial dimensions. ",
64 tensor_in_shape.dims(), " ", data_format));
65
66 this->data_format = data_format;
67 depth = GetTensorDim(tensor_in_shape, data_format, 'C') *
68 (data_format == FORMAT_NCHW_VECT_C ? 4 : 1);
69 tensor_in_cols = GetTensorDim(tensor_in_shape, data_format, 'W');
70 tensor_in_rows = GetTensorDim(tensor_in_shape, data_format, 'H');
71 tensor_in_batch = GetTensorDim(tensor_in_shape, data_format, 'N');
72 window_rows = GetTensorDim(ksize, data_format, 'H');
73 window_cols = GetTensorDim(ksize, data_format, 'W');
74 depth_window = GetTensorDim(ksize, data_format, 'C');
75 row_stride = GetTensorDim(stride, data_format, 'H');
76 col_stride = GetTensorDim(stride, data_format, 'W');
77 depth_stride = GetTensorDim(stride, data_format, 'C');
78
79 // We only support 2D pooling across width/height and depthwise
80 // pooling, not a combination.
81 OP_REQUIRES(context,
82 (depth_window == 1 || (window_rows == 1 && window_cols == 1)),
83 errors::Unimplemented(
84 "MaxPooling supports exactly one of pooling across depth "
85 "or pooling across width/height."));
86
87 if (depth_window == 1) {
88 OP_REQUIRES_OK(
89 context, GetWindowedOutputSize(tensor_in_rows, window_rows, row_stride,
90 padding, &out_height, &pad_rows));
91 OP_REQUIRES_OK(
92 context, GetWindowedOutputSize(tensor_in_cols, window_cols, col_stride,
93 padding, &out_width, &pad_cols));
94 pad_depth = 0;
95 out_depth = depth;
96 } else {
97 OP_REQUIRES(context, depth_window > 0,
98 errors::InvalidArgument("depth_window must not be 0"));
99 // Our current version of depthwise max pooling does not support
100 // any padding, and expects the depth_window to equal the
101 // depth_stride (no overlapping).
102 OP_REQUIRES(
103 context, depth % depth_window == 0,
104 errors::Unimplemented("Depthwise max pooling requires the depth "
105 "window to evenly divide the input depth"));
106 OP_REQUIRES(
107 context, depth_stride == depth_window,
108 errors::Unimplemented("Depthwise max pooling requires the depth "
109 "window to equal the depth stride"));

Callers

nothing calls this directly

Calls 9

GetTensorSpatialDimsFunction · 0.85
InvalidArgumentFunction · 0.85
GetTensorDimFunction · 0.85
UnimplementedFunction · 0.85
DeviceTypeClass · 0.85
GetWindowedOutputSizeFunction · 0.50
dimsMethod · 0.45
device_typeMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected