Skip to content

Commit b93ee66

Browse files
authored
Merge branch 'magnus-branch' into main
2 parents 661b622 + 5ff4aaf commit b93ee66

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ bin/
88
wandb/
99
wandb_api.py
1010

11+
#Magnus specific
12+
docker/*
13+
1114
# Byte-compiled / optimized / DLL files
1215
__pycache__/
1316
*.py[cod]

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ def main():
2424
------
2525
2626
"""
27+
2728
args = get_args()
2829

30+
2931
createfolders(args.datafolder, args.resultfolder, args.modelfolder)
3032

3133
device = args.device

utils/metrics/EntropyPred.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ class EntropyPrediction(nn.Module):
55
def __init__(self):
66
super().__init__()
77

8-
def __call__(self, y_true, y_false):
8+
def __call__(self, y_true, y_false_logits):
99
return
10+
11+
def __reset__(self):
12+
pass

utils/models/magnus_model.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,63 @@
22

33

44
class MagnusModel(nn.Module):
5-
def __init__(self):
5+
def __init__(self,
6+
imagesize: int,
7+
imagechannels: int,
8+
n_classes:int=10):
9+
10+
"""
11+
Magnus model contains the model for Magnus' part of the homeexam.
12+
This class contains a neural network consisting of three linear layers of 133 neurons each,
13+
with ReLU activation between each layer.
14+
15+
Args
16+
----
17+
imagesize (int): Expected size of input image. This is needed to scale first layer input
18+
imagechannels (int): Expected number of image channels. This is needed to scale first layer input
19+
n_classes (int): Number of classes we are to provide.
20+
21+
Returns
22+
-------
23+
MagnusModel (nn.Module): Neural network as described above in this docstring.
24+
"""
25+
26+
627
super().__init__()
28+
self.imagesize = imagesize
29+
self.imagechannels = imagechannels
30+
31+
self.layer1 = nn.Sequential(*([
32+
nn.Linear(self.imagechannels*self.imagesize*self.imagesize, 133),
33+
nn.ReLU()
34+
]))
35+
self.layer2 = nn.Sequential(*([
36+
nn.Linear(133, 133),
37+
nn.ReLU()
38+
]))
39+
self.layer3 = nn.Sequential(*([
40+
nn.Linear(133, n_classes),
41+
nn.ReLU()
42+
]))
743

844
def forward(self, x):
9-
return
45+
"""
46+
Forward pass of MagnusModel
47+
48+
Args
49+
----
50+
x (th.Tensor): Four-dimensional tensor in the form (Batch Size x Channels x Image Height x Image Width)
51+
52+
Returns
53+
-------
54+
out (th.Tensor): Class-logits of network given input x
55+
"""
56+
assert len(x.size) == 4
57+
58+
x = x.view(x.size(0), -1)
59+
60+
x = self.layer1(x)
61+
x = self.layer2(x)
62+
out = self.layer3(x)
63+
64+
return out

0 commit comments

Comments
 (0)