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 unpool2d op & Expose max_unpool2d API #35056

Merged
merged 11 commits into from
Aug 27, 2021

Conversation

tink2123
Copy link
Contributor

@tink2123 tink2123 commented Aug 21, 2021

PR types

New features

PR changes

Ops

Describe

Add max_unpool2d operation

import paddle
import numpy as np
import paddle.nn.functional as F

data = paddle.to_tensor([[[[ 1.,  2,  3,  4],
                            [ 5,  6,  7,  8],
                            [ 9, 10, 11, 12],
                            [13, 14, 15, 16]]]])

output, indices = F.max_pool2d(data, kernel_size=2, stride=2, return_mask=True)
out = F.max_unpool2d(output, indices, kernel_size=2, stride=2,output_size=(5,5))
# paddle: Tensor(shape=[1, 1, 5, 5], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
#        [[[[0. , 0. , 0. , 0. , 0. ],
#           [6. , 0. , 8. , 0. , 0. ],
#           [0. , 0. , 0. , 14., 0. ],
#           [16., 0. , 0. , 0. , 0. ],
#           [0. , 0. , 0. , 0. , 0. ]]]])

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

int cidx = boffset / in_c_stride;
int out_offset = bidx * out_n_stride + cidx * out_c_stride;
int out_index = indices_data[i];
PADDLE_ENFORCE(out_index < out_c_stride,
Copy link
Contributor

Choose a reason for hiding this comment

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

为啥去掉这块的enforce呢?建议再check下数据数据检查

out_index, out_c_stride, out_index, out_c_stride);
output_data[out_offset + out_index] = input_data[i];
CUDA_KERNEL_LOOP(linearIndex, nthreads) {
int c = (linearIndex / input_width / input_height) % channels;
Copy link
Contributor

Choose a reason for hiding this comment

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

异常数据注意enforce,否则安全扫描可能有问题

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx,下一个PR中添加异常数据检查

@@ -54,6 +54,7 @@
from .pooling import AdaptiveMaxPool1D # noqa: F401
from .pooling import AdaptiveMaxPool2D # noqa: F401
from .pooling import AdaptiveMaxPool3D # noqa: F401
from .pooling import MaxUnPool2D
Copy link
Contributor

Choose a reason for hiding this comment

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

加上 # noqa: F401 ?

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, thx

@@ -16,9 +16,9 @@ limitations under the License. */

namespace ops = paddle::operators;
REGISTER_OP_CUDA_KERNEL(
unpool, ops::UnpoolKernel<paddle::platform::CUDADeviceContext, float>,
unpool2d, ops::UnpoolKernel<paddle::platform::CUDADeviceContext, float>,
Copy link
Contributor

Choose a reason for hiding this comment

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

因为改名,需要确认下是否之前有API使用了unpool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

在全景图里做了搜索,确认没有api使用过unpool

@tink2123 tink2123 changed the title add maxunppol2d op, test=develop add maxunpool2d op, test=develop Aug 25, 2021
@tink2123 tink2123 changed the title add maxunpool2d op, test=develop Add unpool2d op & Expose max_unpool2d API Aug 25, 2021
jeff41404
jeff41404 previously approved these changes Aug 26, 2021
Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

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

still need to improve docstring.

import numpy as np

data = paddle.to_tensor(np.random.uniform(-1, 1, [1, 1, 7, 7]).astype(np.float32))
pool_out, indices = F.max_pool2d(data, kernel_size=2, stride=2, padding=0, return_mask=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

构造数据可以直接用paddle.randn吧,这样可以不依赖numpy。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的~ 会在文档修复PR中更新example

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LG API

@ceci3 ceci3 merged commit ceee71a into PaddlePaddle:develop Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants