Spaces:
Runtime error
Runtime error
Update TumorModel.py
Browse files- 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(
|
| 6 |
-
self.
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
def forward(self, x):
|
| 26 |
-
|
| 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(
|
| 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.
|
| 44 |
-
self.out = nn.Linear(30, 2)
|
| 45 |
|
| 46 |
def forward(self, x):
|
| 47 |
-
x =
|
| 48 |
-
x =
|
| 49 |
-
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)
|