How does the Pytorch model view the input dimension output dimension of each layer

In PyTorch, torchsummarythe library can be used to output the structure and parameter statistics of the PyTorch model, which can facilitate us to view information such as the input and output dimensions and the number of parameters of each layer.

Install torchsummarythe library:

pip install torchsummary

The method of use is as follows:

import torch
from torchsummary import summary

# 定义一个模型
model = torch.nn.Sequential(
)

# 打印模型所有层的参数统计
summary(model, (3, 32, 32))

Among them, modelis the model to be viewed, (3, 32, 32)indicating the input dimension of the model, that is, C = 3, H = 32, W = 32. After running, you can see information such as the input and output dimensions of all layers and the number of parameters.

There is a big pit
AttributeError: 'xxx' object has no attribute 'size'
AttributeError: 'int' object has no attribute 'size'
Similar errors

pip uninstall torchsummary
pip install torch-summary

Solve the problem

Guess you like

Origin blog.csdn.net/qq_22815083/article/details/129622393