diff --git a/paddle/operators/math/CMakeLists.txt b/paddle/operators/math/CMakeLists.txt index 2c1bc6d910fbfb5d37a0a9182a5de7bc7db94b8d..1a2f623ce7917b1e60656743e699271eab9c7011 100644 --- a/paddle/operators/math/CMakeLists.txt +++ b/paddle/operators/math/CMakeLists.txt @@ -3,14 +3,14 @@ if(WITH_GPU) nv_test(math_function_test SRCS math_function_test.cc DEPS math_function tensor) nv_library(softmax SRCS softmax.cc softmax.cu DEPS operator) nv_library(cross_entropy SRCS cross_entropy.cc cross_entropy.cu DEPS operator) - nv_library(pooling SRCS pooling.cc pooling.cu DEPS operator) + nv_library(pooling SRCS pooling.cc pooling.cu DEPS device_context) nv_library(vol2col SRCS vol2col.cc vol2col.cu DEPS device_context) else() cc_library(math_function SRCS math_function.cc im2col.cc DEPS cblas device_context operator) cc_test(math_function_test SRCS math_function_test.cc DEPS math_function tensor) cc_library(softmax SRCS softmax.cc DEPS operator) cc_library(cross_entropy SRCS cross_entropy.cc DEPS operator) - cc_library(pooling SRCS pooling.cc DEPS operator) + cc_library(pooling SRCS pooling.cc DEPS device_context) cc_library(vol2col SRCS vol2col.cc DEPS device_context) endif() diff --git a/paddle/operators/pool_op.cc b/paddle/operators/pool_op.cc index 25fd01844ba96108ce7b460f60930b020ff79b2c..c6d9aae13322ebcc9ebbe394d9b9831bd67fe632 100644 --- a/paddle/operators/pool_op.cc +++ b/paddle/operators/pool_op.cc @@ -35,7 +35,7 @@ void PoolOp::InferShape(framework::InferShapeContext *ctx) const { std::vector paddings = ctx->Attrs().Get>("paddings"); PADDLE_ENFORCE(in_x_dims.size() == 4 || in_x_dims.size() == 5, - "Pooling intput should be 4-D or 5-D"); + "Pooling intput should be 4-D or 5-D tensor."); if (ctx->Attrs().Get("globalPooling")) { ksize.resize(static_cast(in_x_dims.size()) - 2); @@ -70,11 +70,11 @@ Pool2dOpMaker::Pool2dOpMaker(framework::OpProto *proto, : OpProtoAndCheckerMaker(proto, op_checker) { AddInput( "X", - "The input tensor of pooling operator. " + "(Tensor) The input tensor of pooling operator. " "The format of input tensor is NCHW. Where N is batch size, C is the " "number of channels, H and W is the height and width of feature."); AddOutput("Out", - "The output tensor of pooling operator." + "(Tensor) The output tensor of pooling operator." "The format of output tensor is also NCHW." "Where N is batch size, C is " "the number of channels, H and W is the height and " @@ -87,7 +87,7 @@ Pool2dOpMaker::Pool2dOpMaker(framework::OpProto *proto, AddAttr>( "ksize", - "The pooling size(height, width) of pooling operator." + "The pooling window size(height, width) of pooling operator." "If globalPooling = true, ksize is ignored and need not be " "specified."); // TODO(Chengduo): Add checker. (Currently, // TypedAttrChecker don't support vector type.) @@ -99,12 +99,12 @@ Pool2dOpMaker::Pool2dOpMaker(framework::OpProto *proto, "If globalPooling = true, ksize is ignored and need not be specified.") .SetDefault(false); AddAttr>("strides", - "Strides(height, width) of pooling operator." + "The strides(height, width) of pooling window." "Default {1,1}.") .SetDefault({1, 1}); // TODO(Chengduo): Add checker. (Currently, // TypedAttrChecker don't support vector type.) AddAttr>("paddings", - "Paddings(height, width) of pooling operator." + "The zero padding(height, width) size on both sides" "Default {0,0}.") .SetDefault({0, 0}); // TODO(Chengduo): Add checker. (Currently, // TypedAttrChecker don't support vector type.) @@ -116,6 +116,17 @@ Input(X) and output(Out) are in NCHW format. Where N is batch size, C is the number of channels, H and W is the height and width of feature. Parameters(ksize, strides, paddings) are two elements. These two elements represent height and width, respectively. +The input(X) size and output(Out) size may be different. + +Example: + Input: + X shape: (N, C, H_in, W_in) + Output: + Out shape: (N, C, H_out, W_out) + Mask shape: (N, C, H_out, W_out) + where + H_out = (H_in - ksize[0] + 2 * paddings[0]) / strides[0] + 1; + W_out = (W_in - ksize[1] + 2 * paddings[1]) / strides[1] + 1; )DOC"); } @@ -124,12 +135,12 @@ Pool3dOpMaker::Pool3dOpMaker(framework::OpProto *proto, : OpProtoAndCheckerMaker(proto, op_checker) { AddInput( "X", - "The input tensor of pooling operator. " + "(Tensor) The input tensor of pooling operator. " "The format of input tensor is NCDHW. Where N is batch size, C is " "the number of channels, D, H and W is the depth, height and width of " "feature."); AddOutput("Out", - "The output tensor of pooling operator." + "(Tensor) The output tensor of pooling operator." "The format of output tensor is also NCDHW." "Where N is batch size, C is " "the number of channels, D, H and W is the depth, height and " @@ -142,7 +153,7 @@ Pool3dOpMaker::Pool3dOpMaker(framework::OpProto *proto, AddAttr>( "ksize", - "The pooling size(depth, height, width) of pooling operator." + "The pooling window size(depth, height, width) of pooling operator." "If globalPooling = true, ksize is ignored and need not be " "specified."); // TODO(Chengduo): Add checker. (Currently, // TypedAttrChecker don't support vector type.) @@ -172,6 +183,18 @@ Input(X) and output(Out) are in NCDHW format. Where N is batch size, C is the number of channels, D, H and W is the depth, height and width of feature. Parameters(ksize, strides, paddings) are three elements. These three elements represent depth, height and width, respectively. +The input(X) size and output(Out) size may be different. + +Example: + Input: + X shape: (N, C, D_in, H_in, W_in) + Output: + Out shape: (N, C, D_out, H_out, W_out) + Mask shape: (N, C, D_out, H_out, W_out) + where + D_out = (D_in - ksize[0] + 2 * paddings[0]) / strides[0] + 1; + H_out = (H_in - ksize[1] + 2 * paddings[1]) / strides[1] + 1; + W_out = (W_in - ksize[2] + 2 * paddings[2]) / strides[2] + 1; )DOC"); } } // namespace operators diff --git a/paddle/operators/pool_with_index_op.cc b/paddle/operators/pool_with_index_op.cc index ae6a81d8713d5e2d1583438f70a9cca0521d657b..005ee886934b193064cc739638398b3535db9274 100644 --- a/paddle/operators/pool_with_index_op.cc +++ b/paddle/operators/pool_with_index_op.cc @@ -43,7 +43,7 @@ class MaxPoolWithIndexOp : public framework::OperatorWithKernel { std::vector paddings = ctx->Attrs().Get>("paddings"); PADDLE_ENFORCE(in_x_dims.size() == 4 || in_x_dims.size() == 5, - "Pooling intput should be 4-D or 5-D"); + "Pooling intput should be 4-D or 5-D tensor."); if (ctx->Attrs().Get("globalPooling")) { ksize.resize(static_cast(in_x_dims.size()) - 2); @@ -74,8 +74,8 @@ class MaxPoolWithIndexOpGrad : public framework::OperatorWithKernel { protected: void InferShape(framework::InferShapeContext *ctx) const override { - PADDLE_ENFORCE(ctx->HasInput("X"), "Input(X) must not be null."); PADDLE_ENFORCE(ctx->HasInput("Mask"), "Input(Mask) must not be null."); + PADDLE_ENFORCE(ctx->HasInput("X"), "Input(X) must not be null."); PADDLE_ENFORCE(ctx->HasOutput(framework::GradVarName("X")), "Input(X@GRAD) should not be null."); ctx->SetOutputDim(framework::GradVarName("X"), ctx->GetInputDim("X")); @@ -89,17 +89,17 @@ class MaxPool2dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker { : OpProtoAndCheckerMaker(proto, op_checker) { AddInput( "X", - "The input tensor of pooling operator. " + "(Tensor) The input tensor of pooling operator. " "The format of input tensor is NCHW. Where N is batch size, C is the " "number of channels, H and W is the height and width of image."); AddOutput("Out", - "The output tensor of pooling operator." + "(Tensor) The output tensor of pooling operator." "The format of output tensor is also NCHW." "Where N is batch size, C is " "the number of channels, H and W is the height and " "width of image."); AddOutput("Mask", - "The Mask tensor of pooling operator." + "(Tensor) The Mask tensor of pooling operator." "The format of output tensor is also NCHW." "Where N is batch size, C is the number of channels, H and W " "is the height and width of image." @@ -107,7 +107,7 @@ class MaxPool2dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker { AddAttr>( "ksize", - "The pooling size(height, width) of pooling operator." + "The pooling window size(height, width) of pooling operator." "If globalPooling = true, ksize is ignored and need not be " "specified."); // TODO(Chengduo): Add checker. (Currently, // TypedAttrChecker don't support vector type.) @@ -119,13 +119,14 @@ class MaxPool2dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker { "If globalPooling = true, ksize is ignored and need not be specified.") .SetDefault(false); AddAttr>("strides", - "Strides(height, width) of pooling operator." + "The strides(height, width) of pooling window." "Default {1,1}.") .SetDefault({1, 1}); // TODO(Chengduo): Add checker. (Currently, // TypedAttrChecker don't support vector type.) - AddAttr>("paddings", - "Paddings(height, width) of pooling operator." - "Default {0,0}.") + AddAttr>( + "paddings", + "The zero padding(height, width) size on both sides" + "Default {0,0}.") .SetDefault({0, 0}); // TODO(Chengduo): Add checker. (Currently, // TypedAttrChecker don't support vector type.) @@ -136,6 +137,17 @@ output(Out, Mask) are in NCHW format. Where N is batch size, C is the number of channels, H and W is the height and width of feature. Parameters(ksize, strides, paddings) are two elements. These two elements represent height and width, respectively. +The input(X) size and output(Out, Mask) size may be different. + +Example: + Input: + X shape: (N, C, H_in, W_in) + Output: + Out shape: (N, C, H_out, W_out) + Mask shape: (N, C, H_out, W_out) + where + H_out = (H_in - ksize[0] + 2 * paddings[0]) / strides[0] + 1; + W_out = (W_in - ksize[1] + 2 * paddings[1]) / strides[1] + 1; )DOC"); } }; @@ -147,18 +159,18 @@ class MaxPool3dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker { : OpProtoAndCheckerMaker(proto, op_checker) { AddInput( "X", - "The input tensor of pooling operator. " + "(Tensor) The input tensor of pooling operator. " "The format of input tensor is NCDHW. Where N is batch size, C is " "the number of channels, D, H and W is the depth, height and width of " "image."); AddOutput("Out", - "The output tensor of pooling operator." + "(Tensor) The output tensor of pooling operator." "The format of output tensor is also NCDHW." "Where N is batch size, C is " "the number of channels, D, H and W is the depth, height and " "width of image."); AddOutput("Mask", - "The Mask tensor of pooling operator." + "(Tensor) The Mask tensor of pooling operator." "The format of output tensor is also NCDHW." "Where N is batch size, C is the number of channels, D, H and W " "is the depth, height and width of image." @@ -166,7 +178,7 @@ class MaxPool3dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker { AddAttr>( "ksize", - "The pooling size(depth, height, width) of pooling operator." + "The pooling window size(depth, height, width) of pooling operator." "If globalPooling = true, ksize is ignored and need not be " "specified."); // TODO(Chengduo): Add checker. (Currently, // TypedAttrChecker don't support vector type.) @@ -197,6 +209,18 @@ Input(X) and output(Out, Mask) are in NCDHW format. Where N is batch size, C is the number of channels, D, H and W is the depth, height and width of feature. Parameters(ksize, strides, paddings) are three elements. These three elements represent depth, height and width, respectively. +The input(X) size and output(Out, Mask) size may be different. + +Example: + Input: + X shape: (N, C, D_in, H_in, W_in) + Output: + Out shape: (N, C, D_out, H_out, W_out) + Mask shape: (N, C, D_out, H_out, W_out) + where + D_out = (D_in - ksize[0] + 2 * paddings[0]) / strides[0] + 1; + H_out = (H_in - ksize[1] + 2 * paddings[1]) / strides[1] + 1; + W_out = (W_in - ksize[2] + 2 * paddings[2]) / strides[2] + 1; )DOC"); } };