Spaces:
Sleeping
Sleeping
Update TumorModel.py
Browse files- TumorModel.py +38 -37
TumorModel.py
CHANGED
|
@@ -1,37 +1,38 @@
|
|
| 1 |
-
import torch.nn as nn
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
self.
|
| 9 |
-
self.
|
| 10 |
-
self.
|
| 11 |
-
self.
|
| 12 |
-
self.
|
| 13 |
-
self.
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
x = self.pool(
|
| 18 |
-
x = self.pool(
|
| 19 |
-
x =
|
| 20 |
-
x =
|
| 21 |
-
x =
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
self.
|
| 30 |
-
self.
|
| 31 |
-
self.
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
x =
|
| 36 |
-
x =
|
| 37 |
-
|
|
|
|
|
|
| 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)
|