-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (39 loc) · 1.23 KB
/
main.py
File metadata and controls
51 lines (39 loc) · 1.23 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from torch import Tensor
from torch import nn
from torch import optim
from mlconfig import instantiate
from mlconfig import instantiate_as
from mlconfig import load
from mlconfig import register
register(optim.Adam)
@register
class LeNet(nn.Module):
def __init__(self, num_classes: int) -> None:
super().__init__()
self.num_classes = num_classes
self.features = nn.Sequential(
nn.Conv2d(1, 6, 5, bias=False),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
nn.Conv2d(6, 16, 5, bias=False),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
)
self.classifier = nn.Sequential(
nn.Linear(16 * 5 * 5, 120),
nn.ReLU(inplace=True),
nn.Linear(120, 84),
nn.ReLU(inplace=True),
nn.Linear(84, self.num_classes),
)
def forward(self, x: Tensor) -> Tensor:
x = self.features(x)
x = x.view(x.size(0), -1)
return self.classifier(x)
def main() -> None:
config = load("conf.yaml")
model = instantiate_as(config.model, nn.Module)
optimizer = instantiate(config.optimizer, model.parameters())
print(optimizer)
if __name__ == "__main__":
main()