-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
31 lines (26 loc) · 842 Bytes
/
Copy pathmodel.py
File metadata and controls
31 lines (26 loc) · 842 Bytes
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
import torch
import torch.nn as nn
from torch.nn import functional as F
class ResNet(nn.Module):
"""
simple resnet with fully connected layers
and ReLU activations
if dim_list is (n,...,m) then the network will take in tensors with
'n' features and outputs 'm' values
"""
def __init__(self, dim_list: list[int]):
super().__init__()
in_dim, dim_list[0] = dim_list[0], 0
self.linears = nn.ModuleList(
[nn.Linear(a + in_dim, b) for (a, b) in zip(dim_list[:-1], dim_list[1:])]
)
def forward(self, x):
y = self.linears[0](x)
y = F.relu(y)
for layer in self.linears[1:-1]:
z = torch.hstack((x, y))
y = layer(z)
y = F.relu(y)
z = torch.hstack((x, y))
y = self.linears[-1](z)
return y