-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pool op #4146
Add pool op #4146
Conversation
ea4805c
to
af49f7b
Compare
dae5052
to
118e091
Compare
5e25693
to
f6e69d7
Compare
@@ -0,0 +1,154 @@ | |||
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change file name: pool_test_maxPool2d.cc
Filenames should be all lowercase and can include underscores (_) or dashes (-).
https://google.github.io/styleguide/cppguide.html#File_Names
finish = clock(); | ||
totaltime = (double)(finish - start) / CLOCKS_PER_SEC; | ||
totaltime /= times; | ||
std::cout << "\nMaxPool3dBackwardFunctor: " << totaltime << "s" << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these debug code when merging code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/operators/math/pooling.cc
Outdated
namespace math { | ||
|
||
template <typename PoolProcess, typename T> | ||
class Pool2dForwardFunctor<platform::CPUPlace, PoolProcess, T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
和Operator命名一致,用Pool2d
和 Pool2dGrad
? (是否要Functor后缀?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename Pool2dForwardFunctor
-> Pool2dFunctor
, Pool2dBackwardFunctor
-> Pool2dGradFunctor
paddle/operators/math/pooling.h
Outdated
class maxPool { | ||
public: | ||
DEVICE inline T initial() { return static_cast<T>(-FLT_MAX); } | ||
DEVICE inline void process(T& y, const T& x) { y = y > x ? y : x; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process -> compute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/operators/math/pooling.h
Outdated
#define FLT_MAX __FLT_MAX__ | ||
///////////////////// | ||
|
||
namespace pool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果要加namespace pool
,需要新建paddle/operators/math/pool
路径。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/operators/pool_op.cc
Outdated
void InferShape(const framework::InferShapeContext &ctx) const override { | ||
auto in = ctx.Input<Tensor>("X"); | ||
auto d_in = ctx.Output<Tensor>(framework::GradVarName("X")); | ||
if (d_in) d_in->Resize(in->dims()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backward只有一个输出的,可以不用判断,直接写成:
d_in->Resize(in->dims());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/operators/pool_op.cc
Outdated
"strides(height, width) of pooling operator." | ||
"default {1,1}") | ||
.SetDefault({1, 1}) | ||
.AddCustomChecker(GreaterThanChecker_pool({0, 0})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GreaterThanChecker_pool({1, 1}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"strides"是可以等于1的
paddle/operators/pool_op.cc
Outdated
} | ||
|
||
private: | ||
struct GreaterThanChecker_pool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
命名规则:https://google.github.io/styleguide/cppguide.html#Type_Names
另外可以直接给paddle/framework/attribute.h
里加吧。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The custom checker has been removed, waiting for the vector data checker to be added and then PR fixes.
paddle/operators/pool_op.cc
Outdated
"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."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
image -> feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/operators/pool_op.cc
Outdated
AddAttr<std::vector<int>>( | ||
"ksize", "pooling size(height, width) of pooling operator.") | ||
.AddCustomChecker(GreaterThanChecker_pool({0, 0})); | ||
AddAttr<int>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use bool type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
10681ca
to
49a17aa
Compare
20491de
to
dfc8d3c
Compare
b4d0e74
to
08fb06b
Compare
08fb06b
to
3c0f079
Compare
37c9fc2
to
e1e3859
Compare
eb6f3d5
to
26d3009
Compare
26d3009
to
2d8a5b9
Compare
self.paddings = [0, 0, 0] | ||
|
||
|
||
class TestCase3(TestPool3d_Op): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestCase4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
self.paddings = [0, 0] | ||
|
||
|
||
class TestCase3(TestPool2d_Op): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestCase3 repeated definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Add pool op.
fixed #4231
fixed #3692
fixed #4165
fixed #4164