|
|
|
@ -33,6 +33,8 @@ void ConvOp::InferShape(framework::InferShapeContext* ctx) const {
|
|
|
|
|
int input_channels = in_dims[1];
|
|
|
|
|
int output_channels = filter_dims[0];
|
|
|
|
|
|
|
|
|
|
PADDLE_ENFORCE(in_dims.size() == 4 || in_dims.size() == 5,
|
|
|
|
|
"Conv intput should be 4-D or 5-D tensor.");
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
in_dims.size(), filter_dims.size(),
|
|
|
|
|
"Conv input dimension and filter dimension should be the same.");
|
|
|
|
@ -62,26 +64,30 @@ Conv2DOpMaker::Conv2DOpMaker(framework::OpProto* proto,
|
|
|
|
|
: OpProtoAndCheckerMaker(proto, op_checker) {
|
|
|
|
|
AddInput(
|
|
|
|
|
"Input",
|
|
|
|
|
"The input tensor of convolution operator. "
|
|
|
|
|
"(Tensor), the input tensor of convolution 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.");
|
|
|
|
|
AddInput("Filter",
|
|
|
|
|
"The filter tensor of convolution operator."
|
|
|
|
|
"(Tensor), the filter tensor of convolution operator."
|
|
|
|
|
"The format of the filter tensor is MCHW, where M is the number of "
|
|
|
|
|
"output image channels, C is the number of input image channels, "
|
|
|
|
|
"H and W is height and width of filter. "
|
|
|
|
|
"If the groups attribute is greater than 1, C equal the number of "
|
|
|
|
|
"input image channels divided by the groups.");
|
|
|
|
|
AddOutput("Output",
|
|
|
|
|
"The output tensor of convolution operator."
|
|
|
|
|
"The format of output tensor is also NCHW.");
|
|
|
|
|
AddAttr<std::vector<int>>("strides", "strides of convolution operator.")
|
|
|
|
|
"(Tensor), the output tensor of convolution 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.");
|
|
|
|
|
AddAttr<std::vector<int>>(
|
|
|
|
|
"strides", "(vector default:{1, 1}), strides of convolution operator.")
|
|
|
|
|
.SetDefault({1, 1});
|
|
|
|
|
AddAttr<std::vector<int>>("paddings", "paddings of convolution operator.")
|
|
|
|
|
AddAttr<std::vector<int>>(
|
|
|
|
|
"paddings", "(vector default:{0, 0}), paddings of convolution operator.")
|
|
|
|
|
.SetDefault({0, 0});
|
|
|
|
|
AddAttr<int>(
|
|
|
|
|
"groups",
|
|
|
|
|
"group size of convolution operator. "
|
|
|
|
|
"(int, default:1), group size of convolution operator. "
|
|
|
|
|
"Refer to grouped convolution in Alex Krizhevsky's paper: "
|
|
|
|
|
"when group=2, the first half of the filters are only connected to the "
|
|
|
|
|
"first half of the input channels, and the second half only connected "
|
|
|
|
@ -91,6 +97,21 @@ Conv2DOpMaker::Conv2DOpMaker(framework::OpProto* proto,
|
|
|
|
|
The convolution operation calculates the output based on the input, filter
|
|
|
|
|
and strides, paddings, groups parameters. The size of each dimension of the
|
|
|
|
|
parameters is checked in the infer-shape.
|
|
|
|
|
Input(Input, Filter) and output(Output) 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:
|
|
|
|
|
Input shape: (N, C_in, H_in, W_in)
|
|
|
|
|
Filter shape: (C_out, C_in, H_f, W_f)
|
|
|
|
|
Output:
|
|
|
|
|
Output shape: (N, C_out, H_out, W_out)
|
|
|
|
|
where
|
|
|
|
|
H_out = (H_in - filter_size[0] + 2 * paddings[0]) / strides[0] + 1;
|
|
|
|
|
W_out = (W_in - filter_size[1] + 2 * paddings[1]) / strides[1] + 1;
|
|
|
|
|
)DOC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -115,15 +136,15 @@ Conv3DOpMaker::Conv3DOpMaker(framework::OpProto* proto,
|
|
|
|
|
"The format of output tensor is also NCDHW.");
|
|
|
|
|
AddAttr<std::vector<int>>(
|
|
|
|
|
"strides",
|
|
|
|
|
"(vector, default {0,0,0}), the strides of convolution operator.")
|
|
|
|
|
"(vector, default:{0, 0, 0}), the strides of convolution operator.")
|
|
|
|
|
.SetDefault({1, 1, 1});
|
|
|
|
|
AddAttr<std::vector<int>>(
|
|
|
|
|
"paddings",
|
|
|
|
|
"(vector, default {0,0,0}), the paddings of convolution operator.")
|
|
|
|
|
"(vector, default:{0, 0, 0}), the paddings of convolution operator.")
|
|
|
|
|
.SetDefault({0, 0, 0});
|
|
|
|
|
AddAttr<int>(
|
|
|
|
|
"groups",
|
|
|
|
|
"(int, default 1) the group size of convolution operator. "
|
|
|
|
|
"(int, default:1) the group size of convolution operator. "
|
|
|
|
|
"Refer to grouped convolution in Alex Krizhevsky's paper: "
|
|
|
|
|
"when group=2, the first half of the filters are only connected to the "
|
|
|
|
|
"first half of the input channels, and the second half only connected "
|
|
|
|
|