Jose M Delgado
commited on
Commit
·
e2f6cfc
1
Parent(s):
375c0e8
test images, metadata
Browse files- app.py +20 -4
- test/mild.png +3 -0
- test/moderate.png +3 -0
- test/no_retinopathy.png +3 -0
- test/severe.png +3 -0
app.py
CHANGED
@@ -2,17 +2,27 @@ import gradio as gr
|
|
2 |
from fastai.vision.all import *
|
3 |
import skimage
|
4 |
|
5 |
-
def get_x(r): return "
|
6 |
|
7 |
def get_y(r): return r['diagnosis']
|
8 |
|
9 |
learn = load_learner('model.pkl')
|
10 |
labels = learn.dls.vocab
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def predict(img):
|
13 |
img = PILImage.create(img)
|
14 |
pred,pred_idx,probs = learn.predict(img)
|
15 |
-
|
|
|
16 |
|
17 |
title = "Proliferative Retinopathy Detection"
|
18 |
description = """Detects severity of diabetic retinopathy -
|
@@ -28,11 +38,17 @@ description = """Detects severity of diabetic retinopathy -
|
|
28 |
4 - Proliferative DR
|
29 |
"""
|
30 |
article="<p style='text-align: center'><a href='https://www.kaggle.com/code/josemauriciodelgado/proliferative-retinopathy' target='_blank'>Notebook</a></p>"
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
|
34 |
gr.Interface(
|
35 |
fn=predict,
|
36 |
inputs=gr.Image(),
|
37 |
outputs=gr.Label(num_top_classes=5),
|
|
|
|
|
|
|
|
|
38 |
).launch()
|
|
|
2 |
from fastai.vision.all import *
|
3 |
import skimage
|
4 |
|
5 |
+
def get_x(r): return ""
|
6 |
|
7 |
def get_y(r): return r['diagnosis']
|
8 |
|
9 |
learn = load_learner('model.pkl')
|
10 |
labels = learn.dls.vocab
|
11 |
|
12 |
+
# Define the mapping from label numbers to descriptions
|
13 |
+
label_descriptions = {
|
14 |
+
0: "No DR",
|
15 |
+
1: "Mild",
|
16 |
+
2: "Moderate",
|
17 |
+
3: "Severe",
|
18 |
+
4: "Proliferative DR"
|
19 |
+
}
|
20 |
+
|
21 |
def predict(img):
|
22 |
img = PILImage.create(img)
|
23 |
pred,pred_idx,probs = learn.predict(img)
|
24 |
+
# Use the label_descriptions dictionary to return descriptions instead of numbers
|
25 |
+
return {label_descriptions[labels[i]]: float(probs[i]) for i in range(len(labels))}
|
26 |
|
27 |
title = "Proliferative Retinopathy Detection"
|
28 |
description = """Detects severity of diabetic retinopathy -
|
|
|
38 |
4 - Proliferative DR
|
39 |
"""
|
40 |
article="<p style='text-align: center'><a href='https://www.kaggle.com/code/josemauriciodelgado/proliferative-retinopathy' target='_blank'>Notebook</a></p>"
|
41 |
+
|
42 |
+
# Get a list of all image paths in the test folder
|
43 |
+
test_folder = "test" # replace with the actual path to your test folder
|
44 |
+
image_paths = [os.path.join(test_folder, img) for img in os.listdir(test_folder) if img.endswith(('.png', '.jpg', '.jpeg'))]
|
45 |
|
46 |
gr.Interface(
|
47 |
fn=predict,
|
48 |
inputs=gr.Image(),
|
49 |
outputs=gr.Label(num_top_classes=5),
|
50 |
+
examples=image_paths, # set the examples parameter to the list of image paths
|
51 |
+
article=article,
|
52 |
+
title=title,
|
53 |
+
description=description,
|
54 |
).launch()
|
test/mild.png
ADDED
![]() |
Git LFS Details
|
test/moderate.png
ADDED
![]() |
Git LFS Details
|
test/no_retinopathy.png
ADDED
![]() |
Git LFS Details
|
test/severe.png
ADDED
![]() |
Git LFS Details
|