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

fix summary trainable_params bug #42798

Merged
merged 2 commits into from
May 18, 2022

Conversation

wangna11BD
Copy link
Contributor

@wangna11BD wangna11BD commented May 17, 2022

PR types

Bug fixes

PR changes

APIs

Describe

Some network layers contain both trainable parameters and non-trainable parameters. This PR fixes that paddle.summary could only record the parameters of the entire layer as trainable or non-trainable parameters, resulting in incorrect calculation of trainable parameters.

Example:
.. code-block:: python

import paddle
import paddle.nn as nn

class LeNet(nn.Layer):
    def __init__(self, num_classes=10):
        super(LeNet, self).__init__()
        self.num_classes = num_classes
        self.features = nn.Sequential(
            nn.Conv2D(1, 6, 3, stride=1, padding=1),
            nn.BatchNorm2D(6),
            nn.ReLU(),
            nn.MaxPool2D(2, 2),
            nn.Conv2D(6, 16, 5, stride=1, padding=0),
            nn.ReLU(),
            nn.MaxPool2D(2, 2))

        if num_classes > 0:
            self.fc = nn.Sequential(
                nn.Linear(400, 120),
                nn.Linear(120, 84),
                nn.Linear(84, 10))

    def forward(self, inputs):
        x = self.features(inputs)

        if self.num_classes > 0:
            x = paddle.flatten(x, 1)
            x = self.fc(x)
        return x

lenet = LeNet()
status = lenet.state_dict()
params_info = paddle.summary(lenet, (1, 1, 28, 28))
print(params_info)

previous incorrect output :
image

correct output :
image

Corresponding issue #40057

@paddle-bot-old
Copy link

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot-old paddle-bot-old bot added contributor External developers status: proposed labels May 17, 2022
LielinJiang
LielinJiang previously approved these changes May 17, 2022
@LielinJiang LielinJiang merged commit e33b9db into PaddlePaddle:develop May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants