Skip to content

Commit 182f04a

Browse files
committed
ruffed
1 parent bff4ed8 commit 182f04a

File tree

5 files changed

+32
-38
lines changed

5 files changed

+32
-38
lines changed

main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def main():
2727

2828
args = get_args()
2929

30-
3130
createfolders(args.datafolder, args.resultfolder, args.modelfolder)
3231

3332
device = args.device

utils/arg_parser.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ def get_args():
4444
"--modelname",
4545
type=str,
4646
default="MagnusModel",
47-
choices=["MagnusModel", "ChristianModel", "SolveigModel", "JanModel", "JohanModel"],
47+
choices=[
48+
"MagnusModel",
49+
"ChristianModel",
50+
"SolveigModel",
51+
"JanModel",
52+
"JohanModel",
53+
],
4854
help="Model which to be trained on",
4955
)
5056
parser.add_argument(
@@ -96,12 +102,9 @@ def get_args():
96102
help="If true, the code will not run the training loop.",
97103
)
98104
args = parser.parse_args()
99-
100-
105+
101106
assert args.epoch > 0, "Epoch should be a positive integer."
102107
assert args.learning_rate > 0, "Learning rate should be a positive float."
103108
assert args.batchsize > 0, "Batch size should be a positive integer."
104-
105-
106-
109+
107110
return args

utils/load_metric.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class MetricWrapper(nn.Module):
10-
1110
"""
1211
Wrapper class for metrics, that runs multiple metrics on the same data.
1312
@@ -46,9 +45,7 @@ class MetricWrapper(nn.Module):
4645
{'entropy': [], 'f1': [], 'precision': []}
4746
"""
4847

49-
5048
def __init__(self, *metrics, num_classes):
51-
5249
super().__init__()
5350
self.metrics = {}
5451
self.num_classes = num_classes

utils/metrics/EntropyPred.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ def __call__(self, y_true, y_false_logits):
99
return
1010

1111
def __reset__(self):
12-
pass
12+
pass

utils/models/magnus_model.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,39 @@
22

33

44
class MagnusModel(nn.Module):
5-
def __init__(self,
6-
imagesize: int,
7-
imagechannels: int,
8-
n_classes:int=10):
9-
5+
def __init__(self, imagesize: int, imagechannels: int, n_classes: int = 10):
106
"""
11-
Magnus model contains the model for Magnus' part of the homeexam.
7+
Magnus model contains the model for Magnus' part of the homeexam.
128
This class contains a neural network consisting of three linear layers of 133 neurons each,
139
with ReLU activation between each layer.
1410
1511
Args
1612
----
1713
imagesize (int): Expected size of input image. This is needed to scale first layer input
1814
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.
15+
n_classes (int): Number of classes we are to provide.
2016
2117
Returns
2218
-------
2319
MagnusModel (nn.Module): Neural network as described above in this docstring.
2420
"""
25-
26-
21+
2722
super().__init__()
28-
self.imagesize = imagesize
23+
self.imagesize = imagesize
2924
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-
]))
25+
26+
self.layer1 = nn.Sequential(
27+
*(
28+
[
29+
nn.Linear(
30+
self.imagechannels * self.imagesize * self.imagesize, 133
31+
),
32+
nn.ReLU(),
33+
]
34+
)
35+
)
36+
self.layer2 = nn.Sequential(*([nn.Linear(133, 133), nn.ReLU()]))
37+
self.layer3 = nn.Sequential(*([nn.Linear(133, n_classes), nn.ReLU()]))
4338

4439
def forward(self, x):
4540
"""
@@ -48,17 +43,17 @@ def forward(self, x):
4843
Args
4944
----
5045
x (th.Tensor): Four-dimensional tensor in the form (Batch Size x Channels x Image Height x Image Width)
51-
46+
5247
Returns
5348
-------
5449
out (th.Tensor): Class-logits of network given input x
5550
"""
5651
assert len(x.size) == 4
57-
52+
5853
x = x.view(x.size(0), -1)
59-
54+
6055
x = self.layer1(x)
6156
x = self.layer2(x)
6257
out = self.layer3(x)
63-
58+
6459
return out

0 commit comments

Comments
 (0)