Skip to content

Commit 86e58b2

Browse files
author
chengduo
authored
Merge pull request #5457 from chengduoZH/fix_pool_attr_name
fix_pool_op_attr_name
2 parents 870650d + cdf5e87 commit 86e58b2

File tree

9 files changed

+42
-41
lines changed

9 files changed

+42
-41
lines changed

paddle/operators/pool_cudnn_op.cu

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class PoolCudnnOpKernel : public framework::OpKernel<T> {
3737
const T *input_data = input->data<T>();
3838
T *output_data = output->mutable_data<T>(ctx.GetPlace());
3939

40-
std::string pooling_type = ctx.Attr<std::string>("poolingType");
40+
std::string pooling_type = ctx.Attr<std::string>("pooling_type");
4141
std::vector<int> ksize = ctx.Attr<std::vector<int>>("ksize");
4242
std::vector<int> strides = ctx.Attr<std::vector<int>>("strides");
4343
std::vector<int> paddings = ctx.Attr<std::vector<int>>("paddings");
44-
if (ctx.Attr<bool>("globalPooling")) {
44+
if (ctx.Attr<bool>("global_pooling")) {
4545
for (size_t i = 0; i < ksize.size(); ++i) {
4646
paddings[i] = 0;
4747
ksize[i] = static_cast<int>(input->dims()[i + 2]);
@@ -92,12 +92,12 @@ class PoolCudnnGradOpKernel : public framework::OpKernel<T> {
9292
ctx.Input<Tensor>(framework::GradVarName("Out"));
9393
Tensor *input_grad = ctx.Output<Tensor>(framework::GradVarName("X"));
9494

95-
std::string pooling_type = ctx.Attr<std::string>("poolingType");
95+
std::string pooling_type = ctx.Attr<std::string>("pooling_type");
9696
std::vector<int> ksize = ctx.Attr<std::vector<int>>("ksize");
9797
std::vector<int> strides = ctx.Attr<std::vector<int>>("strides");
9898
std::vector<int> paddings = ctx.Attr<std::vector<int>>("paddings");
9999

100-
if (ctx.Attr<bool>("globalPooling")) {
100+
if (ctx.Attr<bool>("global_pooling")) {
101101
for (size_t i = 0; i < ksize.size(); ++i) {
102102
paddings[i] = 0;
103103
ksize[i] = static_cast<int>(input->dims()[i + 2]);

paddle/operators/pool_op.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ void PoolOp::InferShape(framework::InferShapeContext *ctx) const {
2929

3030
auto in_x_dims = ctx->GetInputDim("X");
3131

32-
std::string pooling_type = ctx->Attrs().Get<std::string>("poolingType");
32+
std::string pooling_type = ctx->Attrs().Get<std::string>("pooling_type");
3333
std::vector<int> ksize = ctx->Attrs().Get<std::vector<int>>("ksize");
3434
std::vector<int> strides = ctx->Attrs().Get<std::vector<int>>("strides");
3535
std::vector<int> paddings = ctx->Attrs().Get<std::vector<int>>("paddings");
3636

3737
PADDLE_ENFORCE(in_x_dims.size() == 4 || in_x_dims.size() == 5,
3838
"Pooling intput should be 4-D or 5-D tensor.");
3939

40-
if (ctx->Attrs().Get<bool>("globalPooling")) {
40+
if (ctx->Attrs().Get<bool>("global_pooling")) {
4141
ksize.resize(static_cast<size_t>(in_x_dims.size()) - 2);
4242
for (size_t i = 0; i < ksize.size(); ++i) {
4343
paddings[i] = 0;
@@ -83,20 +83,20 @@ Pool2dOpMaker::Pool2dOpMaker(framework::OpProto *proto,
8383
"H is the height of the feature, "
8484
"and W is the width of the feature.");
8585

86-
AddAttr<std::string>("poolingType",
86+
AddAttr<std::string>("pooling_type",
8787
"(string), pooling type, can be \"max\" for max-pooling "
8888
"and \"avg\" for average-pooling.")
8989
.InEnum({"max", "avg"});
9090
AddAttr<std::vector<int>>("ksize",
9191
"(vector<int>) The pooling window "
9292
"size(height, width) of the pooling operator. "
93-
"If globalPooling = true, ksize and paddings will "
93+
"If global_pooling = true, ksize and paddings will "
9494
"be ignored."); // TODO(Chengduo): Add checker.
9595
// (Currently,
9696
// TypedAttrChecker don't support vector type.)
97-
AddAttr<bool>("globalPooling",
97+
AddAttr<bool>("global_pooling",
9898
"(bool, default false) Whether to use the global pooling. "
99-
"If globalPooling = true, ksize and paddings will be ignored.")
99+
"If global_pooling = true, ksize and paddings will be ignored.")
100100
.SetDefault(false);
101101
AddAttr<std::vector<int>>("strides",
102102
"(vector<int>, default {1, 1}), strides(height, "
@@ -107,15 +107,15 @@ Pool2dOpMaker::Pool2dOpMaker(framework::OpProto *proto,
107107
"paddings",
108108
"(vector<int>, defalut {0,0}), paddings(height, width) of pooling "
109109
"operator."
110-
"If globalPooling = true, paddings and ksize will be ignored.")
110+
"If global_pooling = true, paddings and ksize will be ignored.")
111111
.SetDefault({0, 0}); // TODO(Chengduo): Add checker. (Currently,
112112
// TypedAttrChecker don't support vector type.)
113113

114114
AddComment(R"DOC(
115115
Pool2d Operator.
116116
117117
The pooling2d operation calculates the output based on
118-
the input, poolingType and ksize, strides, paddings parameters.
118+
the input, pooling_type and ksize, strides, paddings parameters.
119119
Input(X) and output(Out) are in NCHW format, where N is batch size, C is the
120120
number of channels, H is the height of the feature, and W is the width of the feature.
121121
Parameters(ksize, strides, paddings) are two elements.
@@ -152,21 +152,22 @@ Pool3dOpMaker::Pool3dOpMaker(framework::OpProto *proto,
152152
"the number of channels, and D, H and W is the depth, height and "
153153
"width of the feature, respectively.");
154154

155-
AddAttr<std::string>("poolingType",
155+
AddAttr<std::string>("pooling_type",
156156
"(string) Pooling type, can be \"max\" for max-pooling "
157157
"and \"avg\" for average-pooling.")
158158
.InEnum({"max", "avg"});
159159
AddAttr<std::vector<int>>(
160160
"ksize",
161161
"(vector<int>) The pooling window size(depth, height, "
162162
"width) of pooling operator. "
163-
"If globalPooling = true, ksize and paddings will "
163+
"If global_pooling = true, ksize and paddings will "
164164
"be ignored."); // TODO(Chengduo): Add checker.
165165
// (Currently,
166166
// TypedAttrChecker don't support vector type.)
167-
AddAttr<bool>("globalPooling",
168-
"(bool, default false) Whether to use the global pooling. "
169-
"If globalPooling = true, ksize and paddings wille be ignored.")
167+
AddAttr<bool>(
168+
"global_pooling",
169+
"(bool, default false) Whether to use the global pooling. "
170+
"If global_pooling = true, ksize and paddings wille be ignored.")
170171
.SetDefault(false);
171172
AddAttr<std::vector<int>>(
172173
"strides",
@@ -178,15 +179,15 @@ Pool3dOpMaker::Pool3dOpMaker(framework::OpProto *proto,
178179
"paddings",
179180
"(vector<int>, defalut {0,0,0}), paddings(depth, height, "
180181
"width) of pooling operator. "
181-
"If globalPooling = true, ksize and paddings will be ignored.")
182+
"If global_pooling = true, ksize and paddings will be ignored.")
182183
.SetDefault({0, 0, 0}); // TODO(Chengduo): Add checker. (Currently,
183184
// TypedAttrChecker don't support vector type.)
184185

185186
AddComment(R"DOC(
186187
Pool3d Operator.
187188
188189
The pooling3d operation calculates the output based on
189-
the input, poolingType, ksize, strides, and paddings parameters.
190+
the input, pooling_type, ksize, strides, and paddings parameters.
190191
Input(X) and output(Out) are in NCDHW format, where N is batch
191192
size, C is the number of channels, and D, H and W are the depth, height and
192193
width of the feature, respectively. Parameters(ksize, strides, paddings)

paddle/operators/pool_op.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class PoolKernel : public framework::OpKernel<T> {
5757
const Tensor* in_x = context.Input<Tensor>("X");
5858
Tensor* out = context.Output<Tensor>("Out");
5959

60-
std::string pooling_type = context.Attr<std::string>("poolingType");
60+
std::string pooling_type = context.Attr<std::string>("pooling_type");
6161
std::vector<int> ksize = context.Attr<std::vector<int>>("ksize");
6262
std::vector<int> strides = context.Attr<std::vector<int>>("strides");
6363
std::vector<int> paddings = context.Attr<std::vector<int>>("paddings");
64-
if (context.Attr<bool>("globalPooling")) {
64+
if (context.Attr<bool>("global_pooling")) {
6565
for (size_t i = 0; i < ksize.size(); ++i) {
6666
paddings[i] = 0;
6767
ksize[i] = static_cast<int>(in_x->dims()[i + 2]);
@@ -119,12 +119,12 @@ class PoolGradKernel : public framework::OpKernel<T> {
119119
context.Input<Tensor>(framework::GradVarName("Out"));
120120
Tensor* in_x_grad = context.Output<Tensor>(framework::GradVarName("X"));
121121

122-
std::string pooling_type = context.Attr<std::string>("poolingType");
122+
std::string pooling_type = context.Attr<std::string>("pooling_type");
123123
std::vector<int> ksize = context.Attr<std::vector<int>>("ksize");
124124
std::vector<int> strides = context.Attr<std::vector<int>>("strides");
125125
std::vector<int> paddings = context.Attr<std::vector<int>>("paddings");
126126

127-
if (context.Attr<bool>("globalPooling")) {
127+
if (context.Attr<bool>("global_pooling")) {
128128
for (size_t i = 0; i < ksize.size(); ++i) {
129129
paddings[i] = 0;
130130
ksize[i] = static_cast<int>(in_x->dims()[i + 2]);

paddle/operators/pool_with_index_op.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MaxPoolWithIndexOp : public framework::OperatorWithKernel {
4444
PADDLE_ENFORCE(in_x_dims.size() == 4 || in_x_dims.size() == 5,
4545
"Pooling intput should be 4-D or 5-D tensor.");
4646

47-
if (ctx->Attrs().Get<bool>("globalPooling")) {
47+
if (ctx->Attrs().Get<bool>("global_pooling")) {
4848
ksize.resize(static_cast<size_t>(in_x_dims.size()) - 2);
4949
for (size_t i = 0; i < ksize.size(); ++i) {
5050
paddings[i] = 0;
@@ -110,14 +110,14 @@ class MaxPool2dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker {
110110
AddAttr<std::vector<int>>("ksize",
111111
"(vector<int>) The pooling window size(height, "
112112
"width) of pooling operator. "
113-
"If globalPooling = true, ksize and paddings "
113+
"If global_pooling = true, ksize and paddings "
114114
"will be ignored."); // TODO(Chengduo): Add
115115
// checker. (Currently,
116116
// TypedAttrChecker don't support vector type.)
117117
AddAttr<bool>(
118-
"globalPooling",
118+
"global_pooling",
119119
"(bool, default false) Whether to use the global pooling. "
120-
"If globalPooling = true, ksize and paddings will be ignored.")
120+
"If global_pooling = true, ksize and paddings will be ignored.")
121121
.SetDefault(false);
122122
AddAttr<std::vector<int>>("strides",
123123
"(vector<int>, default {1, 1}), strides(height, "
@@ -128,7 +128,7 @@ class MaxPool2dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker {
128128
"paddings",
129129
"(vector<int>, defalut {0, 0}), paddings(height, width) of pooling "
130130
"operator. "
131-
"If globalPooling = true, paddings and will be ignored.")
131+
"If global_pooling = true, paddings and will be ignored.")
132132
.SetDefault({0, 0}); // TODO(Chengduo): Add checker. (Currently,
133133
// TypedAttrChecker don't support vector type.)
134134

@@ -188,14 +188,14 @@ class MaxPool3dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker {
188188
AddAttr<std::vector<int>>("ksize",
189189
"(vector<int>) The pooling window size(depth, "
190190
"height, width) of pooling operator. "
191-
"If globalPooling = true, ksize and paddings "
191+
"If global_pooling = true, ksize and paddings "
192192
"will be ignored."); // TODO(Chengduo): Add
193193
// checker. (Currently,
194194
// TypedAttrChecker don't support vector type.)
195195
AddAttr<bool>(
196-
"globalPooling",
196+
"global_pooling",
197197
"(bool, default false) Whether to use the global pooling. "
198-
"If globalPooling = true, ksize and paddings will be ignored.")
198+
"If global_pooling = true, ksize and paddings will be ignored.")
199199
.SetDefault(false);
200200
AddAttr<std::vector<int>>("strides",
201201
"(vector<int>, default {1,1,1}), strides(depth, "
@@ -206,7 +206,7 @@ class MaxPool3dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker {
206206
"paddings",
207207
"(vector, defalut {0,0,0}), paddings(depth, "
208208
"height, width) of pooling operator. "
209-
"If globalPooling = true, paddings and ksize will be ignored.")
209+
"If global_pooling = true, paddings and ksize will be ignored.")
210210
.SetDefault({0, 0, 0}); // TODO(Chengduo): Add checker. (Currently,
211211
// TypedAttrChecker don't support vector type.)
212212

paddle/operators/pool_with_index_op.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class MaxPoolWithIndexKernel : public framework::OpKernel<T> {
3535
std::vector<int> ksize = context.Attr<std::vector<int>>("ksize");
3636
std::vector<int> strides = context.Attr<std::vector<int>>("strides");
3737
std::vector<int> paddings = context.Attr<std::vector<int>>("paddings");
38-
if (context.Attr<bool>("globalPooling")) {
38+
if (context.Attr<bool>("global_pooling")) {
3939
for (size_t i = 0; i < ksize.size(); ++i) {
4040
paddings[i] = 0;
4141
ksize[i] = static_cast<int>(in_x->dims()[i + 2]);
@@ -72,7 +72,7 @@ class MaxPoolWithIndexGradKernel : public framework::OpKernel<T> {
7272
std::vector<int> ksize = context.Attr<std::vector<int>>("ksize");
7373
std::vector<int> strides = context.Attr<std::vector<int>>("strides");
7474
std::vector<int> paddings = context.Attr<std::vector<int>>("paddings");
75-
if (context.Attr<bool>("globalPooling")) {
75+
if (context.Attr<bool>("global_pooling")) {
7676
for (size_t i = 0; i < ksize.size(); ++i) {
7777
paddings[i] = 0;
7878
ksize[i] = static_cast<int>(in_x_grad->dims()[i + 2]);

python/paddle/v2/framework/layers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ def pool2d(input,
440440
inputs={"X": input},
441441
outputs={"Out": pool_out},
442442
attrs={
443-
"poolingType": pool_type,
443+
"pooling_type": pool_type,
444444
"ksize": pool_size,
445-
"globalPooling": global_pooling,
445+
"global_pooling": global_pooling,
446446
"strides": pool_stride,
447447
"paddings": pool_padding
448448
})

python/paddle/v2/framework/tests/test_pool2d_op.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def setUp(self):
6161
'strides': self.strides,
6262
'paddings': self.paddings,
6363
'ksize': self.ksize,
64-
'poolingType': self.pool_type,
65-
'globalPooling': self.global_pool,
64+
'pooling_type': self.pool_type,
65+
'global_pooling': self.global_pool,
6666
}
6767

6868
self.outputs = {'Out': output.astype('float32')}

python/paddle/v2/framework/tests/test_pool3d_op.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def setUp(self):
6767
'strides': self.strides,
6868
'paddings': self.paddings,
6969
'ksize': self.ksize,
70-
'poolingType': self.pool_type,
71-
'globalPooling': self.global_pool,
70+
'pooling_type': self.pool_type,
71+
'global_pooling': self.global_pool,
7272
}
7373

7474
self.outputs = {'Out': output.astype('float32')}

python/paddle/v2/framework/tests/test_pool_max_op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def setUp(self):
8686
'strides': self.strides,
8787
'paddings': self.paddings,
8888
'ksize': self.ksize,
89-
'globalPooling': self.global_pool,
89+
'global_pooling': self.global_pool,
9090
}
9191

9292
self.inputs = {'X': input}

0 commit comments

Comments
 (0)