Skip to content

contribs.torchsummary.summary

Function ยท Source

summary_str, params_info = mdnc.contribs.torchsummary.summary_str(
    model, input_size, batch_size=-1, device='cuda:0', dtypes=None
)

Iterate the whole pytorch model and summarize the infomation as a Keras-style text report. The output would be store in a str.

Arguments

Requries

Argument Type Description
model nn.Module The pyTorch network module instance. It is to be analyzed.
input_size (seq/int, ) A sequence (list/tuple) or a sequence of sequnces, indicating the size of the each model input variable.
batch_size int The batch size used for testing and displaying the results.
device str or
torch.device
Should be set according to the deployed device of the argument model.
dtypes (torch.dtype, ) A sequence of torch data type for each input variable. If set None, would use float type for all variables.

Returns

Argument Description
summary_str The summary text report.
params_info A tuple of two values. The first value is the total parameter numbers. The second value is the trainable parameter numbers.

Examples

See the example of mdnc.contribs.torchsummary.summary

Tip

This function could be used for generating the text log file:

1
2
3
4
...
with open('my_module.log', 'w') as f:
    report, _ = mdnc.contribs.torchsummary.summary_string(model, ...)
    f.write(report)


Last update: March 14, 2021

Comments