-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluations.py
41 lines (31 loc) · 990 Bytes
/
evaluations.py
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
import torch
import torch.nn as nn
import torch.nn.functional as F
class Net(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(3, 1, 1, bias=False)
self.conv2 = nn.Conv2d(3, 1, 1, bias=False)
self.fc1 = nn.Linear(1024, 10)
def forward(self, x):
x = F.relu(self.conv1(x))
x = F.relu(self.conv2(x))
x = torch.flatten(x, 1)
x = F.relu(self.fc1(x))
return x
net = Net()
def is_trainable(net):
zeros = torch.zeros((1, 3, 32, 32)) # input tensor of shape (batch_size, channels, height, width)
# Check that we can pass a dummy input through the network without errors.
try:
output = net(zeros)
except Exception as e:
return False
# Network output shape must match number of classes in CIFAR-10.
if output.shape != (1, 10):
return False
return True
def main():
print(is_trainable(net))
if __name__ == '__main__':
main()