Codewithsalty commited on
Commit
2376ea4
·
verified ·
1 Parent(s): e57c445

Update TumorModel.py

Browse files
Files changed (1) hide show
  1. TumorModel.py +25 -35
TumorModel.py CHANGED
@@ -2,49 +2,39 @@ import torch.nn as nn
2
 
3
  class TumorClassification(nn.Module):
4
  def __init__(self):
5
- super(TumorClassification, self).__init__()
6
- self.con1d = nn.Conv2d(1, 32, kernel_size=3, padding=1)
7
- self.relu1 = nn.ReLU()
8
- self.pool1 = nn.MaxPool2d(2)
9
-
10
- self.con2d = nn.Conv2d(32, 64, kernel_size=3, padding=1)
11
- self.relu2 = nn.ReLU()
12
- self.pool2 = nn.MaxPool2d(2)
13
-
14
- self.con3d = nn.Conv2d(64, 128, kernel_size=3, padding=1)
15
- self.relu3 = nn.ReLU()
16
- self.pool3 = nn.MaxPool2d(2)
17
-
18
- self.flatten = nn.Flatten()
19
- self.fc1 = nn.Linear(128 * 28 * 28, 512)
20
- self.relu4 = nn.ReLU()
21
- self.fc2 = nn.Linear(512, 256)
22
- self.relu5 = nn.ReLU()
23
- self.output = nn.Linear(256, 4)
24
 
25
  def forward(self, x):
26
- x = self.pool1(self.relu1(self.con1d(x)))
27
- x = self.pool2(self.relu2(self.con2d(x)))
28
- x = self.pool3(self.relu3(self.con3d(x)))
29
- x = self.flatten(x)
30
- x = self.relu4(self.fc1(x))
31
- x = self.relu5(self.fc2(x))
32
- return self.output(x)
33
-
34
 
35
  class GliomaStageModel(nn.Module):
36
  def __init__(self):
37
- super(GliomaStageModel, self).__init__()
38
  self.fc1 = nn.Linear(9, 100)
39
- self.relu1 = nn.ReLU()
40
  self.fc2 = nn.Linear(100, 50)
41
- self.relu2 = nn.ReLU()
42
  self.fc3 = nn.Linear(50, 30)
43
- self.relu3 = nn.ReLU()
44
- self.out = nn.Linear(30, 2)
45
 
46
  def forward(self, x):
47
- x = self.relu1(self.fc1(x))
48
- x = self.relu2(self.fc2(x))
49
- x = self.relu3(self.fc3(x))
50
  return self.out(x)
 
2
 
3
  class TumorClassification(nn.Module):
4
  def __init__(self):
5
+ super().__init__()
6
+ self.model = nn.Sequential(
7
+ nn.Conv2d(1, 32, 3, 1, 1), # con1d
8
+ nn.ReLU(),
9
+ nn.MaxPool2d(2),
10
+
11
+ nn.Conv2d(32, 64, 3, 1, 1), # con2d
12
+ nn.ReLU(),
13
+ nn.MaxPool2d(2),
14
+
15
+ nn.Conv2d(64, 128, 3, 1, 1), # con3d
16
+ nn.ReLU(),
17
+ nn.MaxPool2d(2),
18
+
19
+ nn.Flatten(),
20
+ nn.Linear(128 * 26 * 26, 512), # 128×26×26 = 86528
21
+ nn.ReLU(),
22
+ nn.Linear(512, 4) # 4 classes
23
+ )
24
 
25
  def forward(self, x):
26
+ return self.model(x)
 
 
 
 
 
 
 
27
 
28
  class GliomaStageModel(nn.Module):
29
  def __init__(self):
30
+ super().__init__()
31
  self.fc1 = nn.Linear(9, 100)
 
32
  self.fc2 = nn.Linear(100, 50)
 
33
  self.fc3 = nn.Linear(50, 30)
34
+ self.out = nn.Linear(30, 4) # 4 stages
 
35
 
36
  def forward(self, x):
37
+ x = nn.functional.relu(self.fc1(x))
38
+ x = nn.functional.relu(self.fc2(x))
39
+ x = nn.functional.relu(self.fc3(x))
40
  return self.out(x)