Codewithsalty commited on
Commit
ef4db92
·
verified ·
1 Parent(s): 5760faf

Update TumorModel.py

Browse files
Files changed (1) hide show
  1. TumorModel.py +38 -37
TumorModel.py CHANGED
@@ -1,37 +1,38 @@
1
- import torch.nn as nn
2
-
3
- class TumorClassification(nn.Module):
4
- def __init__(self):
5
- super().__init__()
6
- self.con1d = nn.Conv2d(1, 32, 3, padding=1)
7
- self.con2d = nn.Conv2d(32, 64, 3, padding=1)
8
- self.con3d = nn.Conv2d(64, 128, 3, padding=1)
9
- self.pool = nn.MaxPool2d(2, 2)
10
- self.fc1 = nn.Linear(128 * 28 * 28, 512)
11
- self.fc2 = nn.Linear(512, 256)
12
- self.output = nn.Linear(256, 4)
13
- self.relu = nn.ReLU()
14
-
15
- def forward(self, x):
16
- x = self.pool(self.relu(self.con1d(x)))
17
- x = self.pool(self.relu(self.con2d(x)))
18
- x = self.pool(self.relu(self.con3d(x)))
19
- x = x.view(x.size(0), -1)
20
- x = self.relu(self.fc1(x))
21
- x = self.relu(self.fc2(x))
22
- return self.output(x)
23
-
24
- class GliomaStageModel(nn.Module):
25
- def __init__(self):
26
- super().__init__()
27
- self.fc1 = nn.Linear(9, 100)
28
- self.fc2 = nn.Linear(100, 50)
29
- self.fc3 = nn.Linear(50, 30)
30
- self.out = nn.Linear(30, 4)
31
- self.relu = nn.ReLU()
32
-
33
- def forward(self, x):
34
- x = self.relu(self.fc1(x))
35
- x = self.relu(self.fc2(x))
36
- x = self.relu(self.fc3(x))
37
- return self.out(x)
 
 
1
+ import torch.nn as nn
2
+ import torch.nn.functional as F
3
+
4
+ # Tumor Classification CNN
5
+ class TumorClassification(nn.Module):
6
+ def __init__(self):
7
+ super(TumorClassification, self).__init__()
8
+ self.con1d = nn.Conv2d(1, 32, kernel_size=3, padding=1)
9
+ self.con2d = nn.Conv2d(32, 64, kernel_size=3, padding=1)
10
+ self.con3d = nn.Conv2d(64, 128, kernel_size=3, padding=1)
11
+ self.pool = nn.MaxPool2d(2, 2)
12
+ self.fc1 = nn.Linear(128 * 29 * 29, 512)
13
+ self.fc2 = nn.Linear(512, 256)
14
+ self.output = nn.Linear(256, 4)
15
+
16
+ def forward(self, x):
17
+ x = self.pool(F.relu(self.con1d(x)))
18
+ x = self.pool(F.relu(self.con2d(x)))
19
+ x = self.pool(F.relu(self.con3d(x)))
20
+ x = x.view(x.size(0), -1)
21
+ x = F.relu(self.fc1(x))
22
+ x = F.relu(self.fc2(x))
23
+ return self.output(x)
24
+
25
+ # Glioma Stage Predictor
26
+ class GliomaStageModel(nn.Module):
27
+ def __init__(self):
28
+ super(GliomaStageModel, self).__init__()
29
+ self.fc1 = nn.Linear(9, 100)
30
+ self.fc2 = nn.Linear(100, 50)
31
+ self.fc3 = nn.Linear(50, 30)
32
+ self.out = nn.Linear(30, 4)
33
+
34
+ def forward(self, x):
35
+ x = F.relu(self.fc1(x))
36
+ x = F.relu(self.fc2(x))
37
+ x = F.relu(self.fc3(x))
38
+ return self.out(x)