Skip to content

Commit 5ff4aaf

Browse files
committed
Fixing and adding docstrings
1 parent c30149e commit 5ff4aaf

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

main.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,23 @@ def main():
8080
parser.add_argument(
8181
"--metric",
8282
type=str,
83-
default=["entropy"],
83+
default="entropy",
8484
choices=["entropy", "f1", "recall", "precision", "accuracy"],
8585
nargs="+",
8686
help="Which metric to use for evaluation",
8787
)
88+
parser.add_argument('--imagesize',
89+
type=int,
90+
default=28,
91+
help='Size of images')
92+
parser.add_argument('--imagechannels',
93+
type=int,
94+
default=1,
95+
choices=[1,3],
96+
help='Number of color channels in the image.')
97+
98+
99+
88100

89101
# Training specific values
90102
parser.add_argument(

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: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,33 @@
33

44
class MagnusModel(nn.Module):
55
def __init__(self,
6-
imgsize: int,
7-
channels: int,
6+
imagesize: int,
7+
imagechannels: int,
88
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+
927
super().__init__()
10-
self.imgsize = imgsize
11-
self.channels = channels
28+
self.imagesize = imagesize
29+
self.imagechannels = imagechannels
1230

1331
self.layer1 = nn.Sequential(*([
14-
nn.Linear(self.channels*self.imgsize*self.imgsize, 133),
32+
nn.Linear(self.imagechannels*self.imagesize*self.imagesize, 133),
1533
nn.ReLU()
1634
]))
1735
self.layer2 = nn.Sequential(*([
@@ -24,12 +42,23 @@ def __init__(self,
2442
]))
2543

2644
def forward(self, x):
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+
"""
2756
assert len(x.size) == 4
2857

2958
x = x.view(x.size(0), -1)
3059

3160
x = self.layer1(x)
3261
x = self.layer2(x)
33-
x = self.layer3(x)
62+
out = self.layer3(x)
3463

35-
return x
64+
return out

0 commit comments

Comments
 (0)