Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,27 +44,26 @@ class SqueezeNet(nn.Module):
|
|
44 |
x = self.avgpool(self.conv10(self.fire9(x)))
|
45 |
return torch.flatten(x, start_dim=1)
|
46 |
|
47 |
-
|
48 |
-
model = SqueezeNet(out_channels=1) # Adjust output channels if needed
|
49 |
model.load_state_dict(torch.load("squeezenet.pth", map_location=torch.device('cpu')))
|
50 |
model.eval()
|
51 |
|
52 |
transform = transforms.Compose([
|
53 |
-
transforms.Resize((128, 128)),
|
54 |
-
transforms.ToTensor(),
|
55 |
-
transforms.Normalize([0.5], [0.5])
|
56 |
])
|
57 |
|
58 |
def classify_brain_tumor(image):
|
59 |
-
image = transform(image).unsqueeze(0)
|
60 |
with torch.no_grad():
|
61 |
output = model(image)
|
62 |
-
prediction = torch.sigmoid(output).item()
|
63 |
return "Tumor" if prediction >= 0.5 else "No Tumor"
|
64 |
|
65 |
interface = gr.Interface(
|
66 |
fn=classify_brain_tumor,
|
67 |
-
inputs=gr.
|
68 |
outputs="text",
|
69 |
title="Brain Tumor Classification",
|
70 |
description="Upload an MRI image to classify if it has a tumor or not."
|
|
|
44 |
x = self.avgpool(self.conv10(self.fire9(x)))
|
45 |
return torch.flatten(x, start_dim=1)
|
46 |
|
47 |
+
model = SqueezeNet(out_channels=1)
|
|
|
48 |
model.load_state_dict(torch.load("squeezenet.pth", map_location=torch.device('cpu')))
|
49 |
model.eval()
|
50 |
|
51 |
transform = transforms.Compose([
|
52 |
+
transforms.Resize((128, 128)),
|
53 |
+
transforms.ToTensor(),
|
54 |
+
transforms.Normalize([0.5], [0.5])
|
55 |
])
|
56 |
|
57 |
def classify_brain_tumor(image):
|
58 |
+
image = transform(image).unsqueeze(0)
|
59 |
with torch.no_grad():
|
60 |
output = model(image)
|
61 |
+
prediction = torch.sigmoid(output).item()
|
62 |
return "Tumor" if prediction >= 0.5 else "No Tumor"
|
63 |
|
64 |
interface = gr.Interface(
|
65 |
fn=classify_brain_tumor,
|
66 |
+
inputs=gr.Image(type="pil"),
|
67 |
outputs="text",
|
68 |
title="Brain Tumor Classification",
|
69 |
description="Upload an MRI image to classify if it has a tumor or not."
|