Spaces:
Sleeping
Sleeping
Pranomvignesh
commited on
Commit
·
510f06a
1
Parent(s):
c532d5b
Added localization
Browse files- .gitignore +1 -0
- app.py +15 -7
- test.py +0 -14
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
test.py
|
app.py
CHANGED
@@ -10,15 +10,23 @@ model = yolov5.load('./gentle-meadow.pt', device="cpu")
|
|
10 |
|
11 |
|
12 |
def predict(image):
|
13 |
-
# results = model([image], size=224)
|
14 |
-
predictions = imageClassifier(image)
|
15 |
-
print(predictions)
|
16 |
|
|
|
|
|
|
|
|
|
17 |
output = {}
|
18 |
for item in predictions:
|
19 |
output[item['label']] = item['score']
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
title = "Detecting Tumors in MRI Images"
|
@@ -40,8 +48,8 @@ inputs = gr.Image(type="pil", shape=(224, 224),
|
|
40 |
label="Upload your image for detection")
|
41 |
|
42 |
outputs = [
|
43 |
-
|
44 |
-
gr.
|
45 |
]
|
46 |
|
47 |
interface = gr.Interface(
|
|
|
10 |
|
11 |
|
12 |
def predict(image):
|
|
|
|
|
|
|
13 |
|
14 |
+
predictions = imageClassifier(image)
|
15 |
+
maxScore = 0
|
16 |
+
predictedLabel = None
|
17 |
+
labelsForLocalization = ['meningioma', 'pituitary']
|
18 |
output = {}
|
19 |
for item in predictions:
|
20 |
output[item['label']] = item['score']
|
21 |
+
if (maxScore < item['score']):
|
22 |
+
maxScore = item['score']
|
23 |
+
predictedLabel = item['label']
|
24 |
+
if (predictedLabel in labelsForLocalization):
|
25 |
+
results = model([image], size=224)
|
26 |
+
imageWithLocalization = results.render()[0]
|
27 |
+
else:
|
28 |
+
imageWithLocalization = image
|
29 |
+
return output, imageWithLocalization
|
30 |
|
31 |
|
32 |
title = "Detecting Tumors in MRI Images"
|
|
|
48 |
label="Upload your image for detection")
|
49 |
|
50 |
outputs = [
|
51 |
+
gr.Label(label="Tumor Classification"),
|
52 |
+
gr.Image(type="pil", label="Tumor Detections")
|
53 |
]
|
54 |
|
55 |
interface = gr.Interface(
|
test.py
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
from PIL import Image
|
2 |
-
from gradio_client import Client
|
3 |
-
|
4 |
-
client = Client("PranomVignesh/timri")
|
5 |
-
|
6 |
-
with open('examples/sample_1.jpg', "rb") as f:
|
7 |
-
image = Image.open(f)
|
8 |
-
image_bytes = f.read()
|
9 |
-
|
10 |
-
output = client.predict(
|
11 |
-
image_bytes
|
12 |
-
)
|
13 |
-
|
14 |
-
print(output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|