|
|
|
@ -89,64 +89,73 @@ class MaxPool2dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
: OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
AddInput(
|
|
|
|
|
"X",
|
|
|
|
|
"(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.");
|
|
|
|
|
"(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 is the height of the image, "
|
|
|
|
|
"and W is the width of the image.");
|
|
|
|
|
AddOutput("Out",
|
|
|
|
|
"(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.");
|
|
|
|
|
"(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 is the height of the image "
|
|
|
|
|
"and W is the width of the image.");
|
|
|
|
|
AddOutput("Mask",
|
|
|
|
|
"(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."
|
|
|
|
|
"The value in it is the index in current feature map");
|
|
|
|
|
"(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 is the height of the image, "
|
|
|
|
|
"and W is the width of the image. "
|
|
|
|
|
"It represents the index in the current feature map.");
|
|
|
|
|
|
|
|
|
|
AddAttr<std::vector<int>>("ksize",
|
|
|
|
|
"(vector ), the pooling window size(height, "
|
|
|
|
|
"width) of pooling operator."
|
|
|
|
|
"(vector<int>) The pooling window size(height, "
|
|
|
|
|
"width) of pooling operator. "
|
|
|
|
|
"If globalPooling = true, ksize and paddings "
|
|
|
|
|
"will be ignored."); // TODO(Chengduo): Add
|
|
|
|
|
// checker. (Currently,
|
|
|
|
|
// TypedAttrChecker don't support vector type.)
|
|
|
|
|
AddAttr<bool>(
|
|
|
|
|
"globalPooling",
|
|
|
|
|
"(bool default: false), whether to use the global pooling."
|
|
|
|
|
"(bool, default false) Whether to use the global pooling. "
|
|
|
|
|
"If globalPooling = true, ksize and paddings will be ignored.")
|
|
|
|
|
.SetDefault(false);
|
|
|
|
|
AddAttr<std::vector<int>>(
|
|
|
|
|
"strides",
|
|
|
|
|
"(vector, default:{1, 1}), strides(height, width) of pooling operator.")
|
|
|
|
|
AddAttr<std::vector<int>>("strides",
|
|
|
|
|
"(vector<int>, default {1, 1}), strides(height, "
|
|
|
|
|
"width) of pooling operator.")
|
|
|
|
|
.SetDefault({1, 1}); // TODO(Chengduo): Add checker. (Currently,
|
|
|
|
|
// TypedAttrChecker don't support vector type.)
|
|
|
|
|
AddAttr<std::vector<int>>(
|
|
|
|
|
"paddings",
|
|
|
|
|
"(vector defalut:{0, 0}), paddings(height, width) of pooling operator."
|
|
|
|
|
"(vector<int>, defalut {0, 0}), paddings(height, width) of pooling "
|
|
|
|
|
"operator. "
|
|
|
|
|
"If globalPooling = true, paddings and will be ignored.")
|
|
|
|
|
.SetDefault({0, 0}); // TODO(Chengduo): Add checker. (Currently,
|
|
|
|
|
// TypedAttrChecker don't support vector type.)
|
|
|
|
|
|
|
|
|
|
AddComment(R"DOC(
|
|
|
|
|
MaxPool2d Operator.
|
|
|
|
|
|
|
|
|
|
The maxPooling2d with index operation calculates the output and the mask
|
|
|
|
|
based on the input and ksize, strides, paddings parameters. Input(X) and
|
|
|
|
|
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.
|
|
|
|
|
based on the input, ksize, strides, and paddings parameters. Input(X) and
|
|
|
|
|
output(Out, Mask) are in NCHW format, where N is batch size, C is the
|
|
|
|
|
number of channels, H is the height of the feature,
|
|
|
|
|
and W is the width of the 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)
|
|
|
|
|
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)
|
|
|
|
|
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;
|
|
|
|
|
$$
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -156,70 +165,76 @@ class MaxPool3dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
MaxPool3dWithIndexOpMaker(framework::OpProto *proto,
|
|
|
|
|
framework::OpAttrChecker *op_checker)
|
|
|
|
|
: OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
AddInput(
|
|
|
|
|
"X",
|
|
|
|
|
"(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.");
|
|
|
|
|
AddInput("X",
|
|
|
|
|
"(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, and D, H and W are the depth, height and "
|
|
|
|
|
"width of "
|
|
|
|
|
"the image, respectively");
|
|
|
|
|
AddOutput("Out",
|
|
|
|
|
"(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.");
|
|
|
|
|
"(Tensor) The output tensor of pooling operator. "
|
|
|
|
|
"The format of output tensor is also NCDHW, "
|
|
|
|
|
"where N is the batch size, C is the number of channels, "
|
|
|
|
|
"and D, H and W are the depth, height and "
|
|
|
|
|
"width of the image, respectively.");
|
|
|
|
|
AddOutput("Mask",
|
|
|
|
|
"(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."
|
|
|
|
|
"The value in it is the index in current feature map");
|
|
|
|
|
"(Tensor) The Mask tensor of pooling operator. "
|
|
|
|
|
"The format of output tensor is also NCDHW, "
|
|
|
|
|
"where N is the batch size, C is the number of channels, and "
|
|
|
|
|
"D, H and W are the depth, height and width "
|
|
|
|
|
"of the image, respectively. "
|
|
|
|
|
"It represents the index in the current feature map.");
|
|
|
|
|
|
|
|
|
|
AddAttr<std::vector<int>>("ksize",
|
|
|
|
|
"(vector), the pooling window size(depth, "
|
|
|
|
|
"height, width) of pooling "
|
|
|
|
|
"operator."
|
|
|
|
|
"(vector<int>) The pooling window size(depth, "
|
|
|
|
|
"height, width) of pooling operator. "
|
|
|
|
|
"If globalPooling = true, ksize and paddings "
|
|
|
|
|
"will be ignored."); // TODO(Chengduo): Add
|
|
|
|
|
// checker. (Currently,
|
|
|
|
|
// TypedAttrChecker don't support vector type.)
|
|
|
|
|
AddAttr<bool>(
|
|
|
|
|
"globalPooling",
|
|
|
|
|
"(bool default: false), whether to use the global pooling."
|
|
|
|
|
"(bool, default false) Whether to use the global pooling. "
|
|
|
|
|
"If globalPooling = true, ksize and paddings will be ignored.")
|
|
|
|
|
.SetDefault(false);
|
|
|
|
|
AddAttr<std::vector<int>>("strides",
|
|
|
|
|
"(vector, default:{1,1,1}), strides(depth, "
|
|
|
|
|
"(vector<int>, default {1,1,1}), strides(depth, "
|
|
|
|
|
"height, width) of pooling operator.")
|
|
|
|
|
.SetDefault({1, 1, 1}); // TODO(Chengduo): Add checker. (Currently,
|
|
|
|
|
// TypedAttrChecker don't support vector type.)
|
|
|
|
|
AddAttr<std::vector<int>>(
|
|
|
|
|
"paddings",
|
|
|
|
|
"(vector defalut:{0,0,0}), paddings(depth, "
|
|
|
|
|
"height, width) of pooling operator."
|
|
|
|
|
"(vector, defalut {0,0,0}), paddings(depth, "
|
|
|
|
|
"height, width) of pooling operator. "
|
|
|
|
|
"If globalPooling = true, paddings and ksize will be ignored.")
|
|
|
|
|
.SetDefault({0, 0, 0}); // TODO(Chengduo): Add checker. (Currently,
|
|
|
|
|
// TypedAttrChecker don't support vector type.)
|
|
|
|
|
|
|
|
|
|
AddComment(R"DOC(
|
|
|
|
|
MaxPool3d Operator.
|
|
|
|
|
|
|
|
|
|
The maxpooling3d with index operation calculates the output and the mask
|
|
|
|
|
based on the input and ksize, strides, paddings parameters.
|
|
|
|
|
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.
|
|
|
|
|
Input(X) and output(Out, Mask) are in NCDHW format, where N is batch
|
|
|
|
|
size, C is the number of channels, and D, H and W are the depth, height and
|
|
|
|
|
width of the feature, respectively.
|
|
|
|
|
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)
|
|
|
|
|
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)
|
|
|
|
|
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;
|
|
|
|
|
$$
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|