MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / flops

Function flops

python/paddle/hapi/dynamic_flops.py:40–145  ·  view source on GitHub ↗

Print a table about the FLOPs of network. Args: net (paddle.nn.Layer||paddle.static.Program): The network which could be a instance of paddle.nn.Layer in dygraph or paddle.static.Program in static graph. input_size (list): size of input tensor. Note that the

(
    net: Layer | Program,
    input_size: list[int],
    custom_ops: _CustomOpsAlias | None = None,
    print_detail: bool = False,
)

Source from the content-addressed store, hash-verified

38
39
40def flops(
41 net: Layer | Program,
42 input_size: list[int],
43 custom_ops: _CustomOpsAlias | None = None,
44 print_detail: bool = False,
45) -> int:
46 """Print a table about the FLOPs of network.
47
48 Args:
49 net (paddle.nn.Layer||paddle.static.Program): The network which could be a instance of paddle.nn.Layer in
50 dygraph or paddle.static.Program in static graph.
51 input_size (list): size of input tensor. Note that the batch_size in argument ``input_size`` only support 1.
52 custom_ops (A dict of function, optional): A dictionary which key is the class of specific operation such as
53 paddle.nn.Conv2D and the value is the function used to count the FLOPs of this operation. This
54 argument only work when argument ``net`` is an instance of paddle.nn.Layer. The details could be found
55 in following example code. Default is None.
56 print_detail (bool, optional): Whether to print the detail information, like FLOPs per layer, about the net FLOPs.
57 Default is False.
58
59 Returns:
60 Int: A number about the FLOPs of total network.
61
62 Examples:
63 .. code-block:: pycon
64
65 >>> import paddle
66 >>> import paddle.nn as nn
67
68 >>> class LeNet(nn.Layer):
69 ... def __init__(self, num_classes=10):
70 ... super().__init__()
71 ... self.num_classes = num_classes
72 ... self.features = nn.Sequential(
73 ... nn.Conv2D(1, 6, 3, stride=1, padding=1),
74 ... nn.ReLU(),
75 ... nn.MaxPool2D(2, 2),
76 ... nn.Conv2D(6, 16, 5, stride=1, padding=0),
77 ... nn.ReLU(),
78 ... nn.MaxPool2D(2, 2),
79 ... )
80 ...
81 ... if num_classes > 0:
82 ... self.fc = nn.Sequential(
83 ... nn.Linear(400, 120),
84 ... nn.Linear(120, 84),
85 ... nn.Linear(84, 10),
86 ... )
87 ...
88 ... def forward(self, inputs):
89 ... x = self.features(inputs)
90 ...
91 ... if self.num_classes > 0:
92 ... x = paddle.flatten(x, 1)
93 ... x = self.fc(x)
94 ... return x
95 >>> lenet = LeNet()
96 >>> # m is the instance of nn.Layer, x is the input of layer, y is the output of layer.
97 >>> def count_leaky_relu(m, x, y):

Callers

nothing calls this directly

Calls 4

unwrap_decoratorsFunction · 0.90
dynamic_flopsFunction · 0.85
static_flopsFunction · 0.85
warnMethod · 0.45

Tested by

no test coverage detected