Spaces:
Runtime error
Runtime error
Update newapi.py
Browse files
newapi.py
CHANGED
@@ -28,7 +28,7 @@ app.add_middleware(
|
|
28 |
transform = transforms.Compose([
|
29 |
transforms.Resize((224, 224)),
|
30 |
transforms.ToTensor(),
|
31 |
-
transforms.Normalize(mean=[0.5
|
32 |
])
|
33 |
|
34 |
# Define your model directly inside this file (to avoid import errors)
|
@@ -37,19 +37,23 @@ import torch.nn as nn
|
|
37 |
class BrainTumorModel(nn.Module):
|
38 |
def __init__(self):
|
39 |
super(BrainTumorModel, self).__init__()
|
40 |
-
self.
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
nn.Flatten(),
|
48 |
-
nn.Linear(32 * 54 * 54, 2),
|
49 |
-
)
|
50 |
|
51 |
def forward(self, x):
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
# Load model
|
55 |
model_path = "BTD_model.pth"
|
|
|
28 |
transform = transforms.Compose([
|
29 |
transforms.Resize((224, 224)),
|
30 |
transforms.ToTensor(),
|
31 |
+
transforms.Normalize(mean=[0.5], std=[0.5]),
|
32 |
])
|
33 |
|
34 |
# Define your model directly inside this file (to avoid import errors)
|
|
|
37 |
class BrainTumorModel(nn.Module):
|
38 |
def __init__(self):
|
39 |
super(BrainTumorModel, self).__init__()
|
40 |
+
self.con1d = nn.Conv2d(3, 32, kernel_size=3)
|
41 |
+
self.con2d = nn.Conv2d(32, 64, kernel_size=3)
|
42 |
+
self.con3d = nn.Conv2d(64, 128, kernel_size=3)
|
43 |
+
self.pool = nn.MaxPool2d(2)
|
44 |
+
self.fc1 = nn.Linear(128 * 25 * 25, 256)
|
45 |
+
self.fc2 = nn.Linear(256, 128)
|
46 |
+
self.output = nn.Linear(128, 2)
|
|
|
|
|
|
|
47 |
|
48 |
def forward(self, x):
|
49 |
+
x = self.pool(torch.relu(self.con1d(x)))
|
50 |
+
x = self.pool(torch.relu(self.con2d(x)))
|
51 |
+
x = self.pool(torch.relu(self.con3d(x)))
|
52 |
+
x = x.view(-1, 128 * 25 * 25)
|
53 |
+
x = torch.relu(self.fc1(x))
|
54 |
+
x = torch.relu(self.fc2(x))
|
55 |
+
x = self.output(x)
|
56 |
+
return x
|
57 |
|
58 |
# Load model
|
59 |
model_path = "BTD_model.pth"
|