File size: 894 Bytes
7671040 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | from __future__ import annotations
import torch
from torch import nn
class ProbabilisticTinyCNN(nn.Module):
def __init__(self) -> None:
super().__init__()
self.features = nn.Sequential(
nn.Conv2d(1, 8, kernel_size=3, padding=1),
nn.GELU(),
nn.Conv2d(8, 8, kernel_size=3, padding=1, groups=8),
nn.GELU(),
nn.Conv2d(8, 12, kernel_size=1),
nn.GELU(),
nn.Dropout2d(0.08),
nn.MaxPool2d(2),
)
self.classifier = nn.Sequential(
nn.Flatten(),
nn.Dropout(0.12),
nn.Linear(12 * 4 * 4, 10),
)
def forward(self, pixels: torch.Tensor) -> torch.Tensor:
return self.classifier(self.features(pixels))
def parameter_count(model: nn.Module) -> int:
return sum(parameter.numel() for parameter in model.parameters())
|