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 new API paddle.nn.initializer.Dirac #37389

Merged
merged 3 commits into from
Nov 25, 2021

Conversation

zhwesky2010
Copy link
Contributor

@zhwesky2010 zhwesky2010 commented Nov 19, 2021

PR types

New features

PR changes

APIs

Describe

paddle.nn.initializer.Dirac

Initialize the 3D/4D/5D Tensor with Dirac delta function. It can reserve the feature of convolution layer input, which means that as many channels are reserved as possible.

attr = paddle.ParamAttr(initializer=paddle.nn.initializer.Dirac())
conv = paddle.nn.Conv1D(3, 2, 3, weight_attr=attr)
# conv.weight:
# Tensor(shape=[2, 3, 3], dtype=float32, place=CPUPlace, stop_gradient=False,
#       [[[0., 1., 0.],
#         [0., 0., 0.],
#         [0., 0., 0.]],
# 
#        [[0., 0., 0.],
#         [0., 1., 0.],
#         [0., 0., 0.]]])

input = paddle.rand([8, 3, 10])
output = conv(input)
input.shape  # [8, 3, 10]
output.shape # [8, 2, 8]
paddle.equal_all(output, input[:, 0:2, 1:9])
# [True]
# It means output is almost the same with input, 2 channels are reserved.

FireShot Capture 262 - Dirac-API Document-PaddlePaddle Deep Learning Platform - 10 136 157 23

@paddle-bot-old
Copy link

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

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

@TCChenlong TCChenlong left a comment

Choose a reason for hiding this comment

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

LGTM

param(bool|int|float, optional): optional parameter for somme nonlinearity function. Now, it only applies to 'leaky_relu'. Default: None,
it will be calculated as 0.01 in the formula.
nonlinearity(str): name of nonlinearity activation function. If it is a linear function, which is one of
"linear/conv1d/conv2d/conv3d/conv1d_transpose/conv2d_transpose/conv3d_transpose" , will return 1.0
Copy link
Contributor

Choose a reason for hiding this comment

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

will return 1.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This API returns a float number.

@zhwesky2010 zhwesky2010 merged commit bbb9b28 into PaddlePaddle:develop Nov 25, 2021
Zjq9409 pushed a commit to Zjq9409/Paddle that referenced this pull request Dec 10, 2021
* add new API paddle.nn.initializer.Dirac

* fix doc
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.

None yet

4 participants