Skip to content
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

Merged
merged 25 commits into from
Sep 30, 2017
Merged

Add pool op #4146

merged 25 commits into from
Sep 30, 2017

Conversation

chengduoZH
Copy link
Contributor

@chengduoZH chengduoZH commented Sep 18, 2017

Add pool op.

  • Add pooling2d max and average (gpu and cpu implementations)
  • Add pooling3d max and average (gpu and cpu implementations)
  • Add unit test pooling2d and pooling3d

fixed #4231
fixed #3692
fixed #4165
fixed #4164

@@ -0,0 +1,154 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

namespace math {

template <typename PoolProcess, typename T>
class Pool2dForwardFunctor<platform::CPUPlace, PoolProcess, T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和Operator命名一致,用Pool2dPool2dGrad ? (是否要Functor后缀?)

Copy link
Contributor Author

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

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; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process -> compute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#define FLT_MAX __FLT_MAX__
/////////////////////

namespace pool {
Copy link
Contributor

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 路径。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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());
Copy link
Contributor

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());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"strides(height, width) of pooling operator."
"default {1,1}")
.SetDefault({1, 1})
.AddCustomChecker(GreaterThanChecker_pool({0, 0}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GreaterThanChecker_pool({1, 1}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"strides"是可以等于1的

}

private:
struct GreaterThanChecker_pool {
Copy link
Contributor

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里加吧。

Copy link
Contributor Author

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.

"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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image -> feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

AddAttr<std::vector<int>>(
"ksize", "pooling size(height, width) of pooling operator.")
.AddCustomChecker(GreaterThanChecker_pool({0, 0}));
AddAttr<int>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use bool type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@chengduoZH chengduoZH force-pushed the Add_pool_op branch 5 times, most recently from 10681ca to 49a17aa Compare September 26, 2017 08:49
@chengduoZH chengduoZH force-pushed the Add_pool_op branch 3 times, most recently from b4d0e74 to 08fb06b Compare September 27, 2017 14:44
@chengduoZH chengduoZH force-pushed the Add_pool_op branch 2 times, most recently from 37c9fc2 to e1e3859 Compare September 29, 2017 07:11
@chengduoZH chengduoZH force-pushed the Add_pool_op branch 2 times, most recently from eb6f3d5 to 26d3009 Compare September 29, 2017 13:54
hedaoyuan
hedaoyuan previously approved these changes Sep 30, 2017
self.paddings = [0, 0, 0]


class TestCase3(TestPool3d_Op):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestCase4?

Copy link
Contributor Author

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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestCase3 repeated definition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@chengduoZH chengduoZH merged commit 4f5491b into PaddlePaddle:develop Sep 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pooling2D_ave Operator. Pooling3d_average Operator. Pooling3d_max Operator. Pooling2D_max Operator.
4 participants