1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| net = nn.Sequential(nn.Linear(4,8), nn.ReLU(), nn.Linear(8,1)) for para in net.parameters(): para.shape for name, para in net.named_parameters(): print(name)
net[2].weight.data net[2].bias.data.device next(iter(net.parameters())).shape
net = torch.nn.Sequential(Reshape(), nn.Conv2d(1, 6, kernel_size=5, padding=2), nn.Sigmoid(), nn.AvgPool2d(kernel_size=2, stride=2), nn.Conv2d(6, 16, kernel_size=5), nn.Sigmoid(), nn.AvgPool2d(kernel_size=2, stride=2), nn.Flatten(), nn.Linear(16 * 5 * 5, 120), nn.Sigmoid(), nn.Linear(120, 84), nn.Sigmoid(), nn.Linear(84, 10)) X = torch.rand((1,1,28,28), dtype=torch.float32) for layer in net: X = layer(X) print(layer.__class__.__name__.ljust(20), 'outshape: ' ,X.shape)
|