Spaces:
Running
Running
Update
Browse files- app.py +13 -9
- examples/{none.png β 0.png} +2 -2
- examples/{mild.png β 1.png} +2 -2
- examples/{moderate.png β 2.png} +2 -2
- examples/{proliferative.png β 3.png} +2 -2
- examples/4.png +3 -0
- examples/severe.png +0 -3
app.py
CHANGED
@@ -22,19 +22,23 @@ class Net2D(nn.Module):
|
|
22 |
return x[:, 0] if x.size(1) == 1 else x
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
weights = torch.load("model0.ckpt", map_location=torch.device("cpu"))["state_dict"]
|
26 |
-
weights = {k.replace("model.", "")
|
27 |
-
model = Net2D(weights)
|
28 |
|
29 |
|
30 |
def predict(Image):
|
31 |
img = torch.from_numpy(Image)
|
32 |
-
img = img[:, :, [2, 1, 0]]
|
33 |
img = img.permute(2, 0, 1)
|
34 |
img = img.unsqueeze(0)
|
35 |
-
img = img
|
36 |
-
img = img - 0.5
|
37 |
-
img = img * 2.0
|
38 |
with torch.no_grad():
|
39 |
grade = torch.softmax(model(img.float()), dim=1)[0]
|
40 |
cats = ["None", "Mild", "Moderate", "Severe", "Proliferative"]
|
@@ -44,6 +48,7 @@ def predict(Image):
|
|
44 |
return output_dict
|
45 |
|
46 |
|
|
|
47 |
image = gr.Image(shape=(512, 512), image_mode="RGB")
|
48 |
label = gr.Label(label="Grade")
|
49 |
|
@@ -51,12 +56,11 @@ demo = gr.Interface(
|
|
51 |
fn=predict,
|
52 |
inputs=image,
|
53 |
outputs=label,
|
54 |
-
examples=["examples/
|
55 |
-
"examples/proliferative.png"]
|
56 |
)
|
57 |
|
58 |
|
59 |
if __name__ == "__main__":
|
60 |
-
demo.launch(debug=True)
|
61 |
|
62 |
|
|
|
22 |
return x[:, 0] if x.size(1) == 1 else x
|
23 |
|
24 |
|
25 |
+
def rescale(x):
|
26 |
+
x = x / 255.0
|
27 |
+
x = x - 0.5
|
28 |
+
x = x * 2.0
|
29 |
+
return x
|
30 |
+
|
31 |
+
|
32 |
weights = torch.load("model0.ckpt", map_location=torch.device("cpu"))["state_dict"]
|
33 |
+
weights = {k.replace("model.", ""): v for k, v in weights.items()}
|
34 |
+
model = Net2D(weights).eval()
|
35 |
|
36 |
|
37 |
def predict(Image):
|
38 |
img = torch.from_numpy(Image)
|
|
|
39 |
img = img.permute(2, 0, 1)
|
40 |
img = img.unsqueeze(0)
|
41 |
+
img = rescale(img)
|
|
|
|
|
42 |
with torch.no_grad():
|
43 |
grade = torch.softmax(model(img.float()), dim=1)[0]
|
44 |
cats = ["None", "Mild", "Moderate", "Severe", "Proliferative"]
|
|
|
48 |
return output_dict
|
49 |
|
50 |
|
51 |
+
|
52 |
image = gr.Image(shape=(512, 512), image_mode="RGB")
|
53 |
label = gr.Label(label="Grade")
|
54 |
|
|
|
56 |
fn=predict,
|
57 |
inputs=image,
|
58 |
outputs=label,
|
59 |
+
examples=["examples/0.png", "examples/1.png", "examples/2.png", "examples/3.png", "examples/4.png"]
|
|
|
60 |
)
|
61 |
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
+
demo.launch(debug=True, share=True)
|
65 |
|
66 |
|
examples/{none.png β 0.png}
RENAMED
File without changes
|
examples/{mild.png β 1.png}
RENAMED
File without changes
|
examples/{moderate.png β 2.png}
RENAMED
File without changes
|
examples/{proliferative.png β 3.png}
RENAMED
File without changes
|
examples/4.png
ADDED
![]() |
Git LFS Details
|
examples/severe.png
DELETED
Git LFS Details
|