Spaces:
Running
Running
Initial commit
Browse files- .gitattributes +1 -0
- README.md +3 -3
- app.py +62 -0
- examples/mild.png +3 -0
- examples/moderate.png +3 -0
- examples/none.png +3 -0
- examples/proliferative.png +3 -0
- examples/severe.png +3 -0
- model0.ckpt +3 -0
- requirements.txt +4 -0
.gitattributes
CHANGED
|
@@ -19,6 +19,7 @@
|
|
| 19 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
*.pkl filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 22 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 19 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 23 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 24 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 25 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
title: Diabetic Retinopathy
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.9.1
|
| 8 |
app_file: app.py
|
|
|
|
| 1 |
---
|
| 2 |
title: Diabetic Retinopathy
|
| 3 |
+
emoji: 🐠
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.9.1
|
| 8 |
app_file: app.py
|
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import timm
|
| 3 |
+
import torch
|
| 4 |
+
import torch.nn as nn
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Net2D(nn.Module):
|
| 8 |
+
|
| 9 |
+
def __init__(self, weights):
|
| 10 |
+
super().__init__()
|
| 11 |
+
self.backbone = timm.create_model("tf_efficientnet_b6_ns", pretrained=False, global_pool="", num_classes=0)
|
| 12 |
+
self.pool_layer = nn.AdaptiveAvgPool2d(1)
|
| 13 |
+
self.dropout = nn.Dropout(0.5)
|
| 14 |
+
self.linear = nn.Linear(2304, 5)
|
| 15 |
+
self.load_state_dict(weights)
|
| 16 |
+
|
| 17 |
+
def forward(self, x):
|
| 18 |
+
x = self.backbone(x)
|
| 19 |
+
x = self.pool_layer(x).view(x.size(0), -1)
|
| 20 |
+
x = self.dropout(x)
|
| 21 |
+
x = self.linear(x)
|
| 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.", "") : v for k, v in weights.items()}
|
| 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 / img.max()
|
| 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"]
|
| 41 |
+
output_dict = {}
|
| 42 |
+
for cat, value in zip(cats, grade):
|
| 43 |
+
output_dict[cat] = value.item()
|
| 44 |
+
return output_dict
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
image = gr.Image(shape=(512, 512), image_mode="RGB")
|
| 48 |
+
label = gr.Label(label="Grade")
|
| 49 |
+
|
| 50 |
+
demo = gr.Interface(
|
| 51 |
+
fn=predict,
|
| 52 |
+
inputs=image,
|
| 53 |
+
outputs=label,
|
| 54 |
+
examples=["examples/none.png", "examples/mild.png", "examples/moderate.png", "examples/severe.png",
|
| 55 |
+
"examples/proliferative.png"]
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
demo.launch(debug=True)
|
| 61 |
+
|
| 62 |
+
|
examples/mild.png
ADDED
|
Git LFS Details
|
examples/moderate.png
ADDED
|
Git LFS Details
|
examples/none.png
ADDED
|
Git LFS Details
|
examples/proliferative.png
ADDED
|
Git LFS Details
|
examples/severe.png
ADDED
|
Git LFS Details
|
model0.ckpt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b44c74a6c75f747e48799bb9c20510bd27a6e900f33d5fd795955f59ce78eac4
|
| 3 |
+
size 164258381
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
omegaconf
|
| 2 |
+
timm
|
| 3 |
+
torch
|
| 4 |
+
|