pytorch利用torchsummary实现类似keras的model.summary()输出模型信息 发表于 2019-06-22 | 分类于 ML/DL 详见链接torchsummary 代码123456789101112131415161718192021import torchimport torch.nn as nnfrom torchsummary import summaryclass SimpleConv(nn.Module): def __init__(self): super(SimpleConv, self).__init__() self.features = nn.Sequential( nn.Conv2d(1, 1, kernel_size=3, stride=1, padding=1), nn.ReLU(), ) def forward(self, x, y): x1 = self.features(x) x2 = self.features(y) return x1, x2 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")model = SimpleConv().to(device)summary(model, [(1, 16, 16), (1, 28, 28)]) 结果1234567891011121314151617---------------------------------------------------------------- Layer (type) Output Shape Param #================================================================ Conv2d-1 [-1, 1, 16, 16] 10 ReLU-2 [-1, 1, 16, 16] 0 Conv2d-3 [-1, 1, 28, 28] 10 ReLU-4 [-1, 1, 28, 28] 0================================================================Total params: 20Trainable params: 20Non-trainable params: 0----------------------------------------------------------------Input size (MB): 0.77Forward/backward pass size (MB): 0.02Params size (MB): 0.00Estimated Total Size (MB): 0.78----------------------------------------------------------------