summary

paddle. summary ( net, input_size, dtypes=None ) [source]

Prints a string summary of the network.

Parameters
  • net (Layer) – the network which must be a subinstance of Layer.

  • input_size (tuple|InputSpec|list[tuple|InputSpec]) – size of input tensor. if model only have one input, input_size can be tuple or InputSpec. if model have multiple input, input_size must be a list which contain every input’s shape. Note that input_size only dim of batch_size can be None or -1.

  • dtypes (str, optional) – if dtypes is None, ‘float32’ will be used, Default: None.

Returns

a summary of the network including total params and total trainable params.

Return type

Dict

Examples

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

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