| import torch | |
| import torch.nn as nn | |
| class MyNetwork(nn.Module): | |
| def __init__(self): | |
| super().__init__() | |
| self.model = nn.Sequential( | |
| nn.Conv2d(3, 32, 5, padding=2), | |
| nn.BatchNorm2d(32), | |
| nn.ReLU(), | |
| nn.MaxPool2d(2), | |
| nn.Conv2d(32, 64, 5, padding=2), | |
| nn.BatchNorm2d(64), | |
| nn.ReLU(), | |
| nn.MaxPool2d(2), | |
| nn.Conv2d(64, 128, 5, padding=2), | |
| nn.BatchNorm2d(128), | |
| nn.ReLU(), | |
| nn.MaxPool2d(2), | |
| nn.Conv2d(128, 256, 5, padding=2), | |
| nn.BatchNorm2d(256), | |
| nn.ReLU(), | |
| nn.MaxPool2d(2), | |
| nn.Flatten(), | |
| nn.Linear(1024, 256), | |
| nn.ReLU(), | |
| nn.Dropout(0.5), | |
| nn.Linear(256, 10) | |
| ) | |
| def forward(self, x): | |
| x = self.model(x) | |
| return x | |
| if __name__ == '__main__': | |
| mynetwork = MyNetwork() | |
| input = torch.ones((64, 3, 32, 32)) | |
| output = mynetwork(input) | |
| print(output.shape) | |
| total_params = sum(p.numel() for p in mynetwork.parameters()) | |
| print(f"Total params:{total_params}") | |
| print(f"Total params:{total_params / 1000000}M") | |