ianpan commited on
Commit
7ce2ffd
·
1 Parent(s): fff900f

Initial commit

Browse files
.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: purple
5
- colorTo: pink
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

  • SHA256: 3e872ec4b1a0d8424fe62edec850e9c830260c61a563b23ff20ba6ed36e99e5c
  • Pointer size: 132 Bytes
  • Size of remote file: 2.9 MB
examples/moderate.png ADDED

Git LFS Details

  • SHA256: bf40c7cc13cf862c92efd1e977b094e7fa6f0ed7c3c271dbf82c847d338f919d
  • Pointer size: 132 Bytes
  • Size of remote file: 4.94 MB
examples/none.png ADDED

Git LFS Details

  • SHA256: 22ebc29d463307d5d51c1cdc994ab9ef0c4f72265f777ecd72599a338de7d70d
  • Pointer size: 131 Bytes
  • Size of remote file: 416 kB
examples/proliferative.png ADDED

Git LFS Details

  • SHA256: 442d6bec9025756180759b062d87f63328ce8d3cb6111dacc59225ecfe532154
  • Pointer size: 132 Bytes
  • Size of remote file: 5.73 MB
examples/severe.png ADDED

Git LFS Details

  • SHA256: 96dfa76f3ba7e3a61855d21a42a9c4dc2228fd1c8e0e1622c6be1ef12e6b6d7e
  • Pointer size: 132 Bytes
  • Size of remote file: 8.67 MB
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
+