Codewithsalty commited on
Commit
f7685f7
·
verified ·
1 Parent(s): 21a3e5f

Update TumorModel.py

Browse files
Files changed (1) hide show
  1. TumorModel.py +19 -17
TumorModel.py CHANGED
@@ -1,29 +1,31 @@
1
  import torch.nn as nn
 
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):
 
1
  import torch.nn as nn
2
+ import torch
3
 
4
  class TumorClassification(nn.Module):
5
  def __init__(self):
6
  super().__init__()
7
+ self.con1d = nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=1)
8
+ self.con2d = nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1)
9
+ self.con3d = nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1)
10
+
11
+ self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
12
 
13
+ self.fc1 = nn.Linear(128 * 26 * 26, 512) # Must match training input size (208x208 image)
14
+ self.fc2 = nn.Linear(512, 256)
15
+ self.output = nn.Linear(256, 4)
16
 
17
+ self.relu = nn.ReLU()
 
 
 
 
 
 
 
 
18
 
19
  def forward(self, x):
20
+ x = self.pool(self.relu(self.con1d(x)))
21
+ x = self.pool(self.relu(self.con2d(x)))
22
+ x = self.pool(self.relu(self.con3d(x)))
23
+ x = x.view(x.size(0), -1)
24
+ x = self.relu(self.fc1(x))
25
+ x = self.relu(self.fc2(x))
26
+ x = self.output(x)
27
+ return x
28
+
29
 
30
  class GliomaStageModel(nn.Module):
31
  def __init__(self):