ariankhalfani commited on
Commit
a9db6c2
·
verified ·
1 Parent(s): cf041d1

Upload 6 files

Browse files
Files changed (7) hide show
  1. .gitattributes +1 -0
  2. app.py +47 -0
  3. best-glaucoma-seg.pt +3 -0
  4. font.ttf +0 -0
  5. image-logo.png +3 -0
  6. last.pt +3 -0
  7. requirements(1).txt +6 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ image-logo.png filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ import cv2
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ # Load YOLOv8 model
8
+ model = YOLO("best-glaucoma-od.pt")
9
+
10
+ # Function to perform prediction
11
+ def predict_image(input_image):
12
+ # Convert Gradio input image (PIL Image) to numpy array
13
+ image_np = np.array(input_image)
14
+
15
+ # Ensure the image is in the correct format
16
+ if len(image_np.shape) == 2: # grayscale to RGB
17
+ image_np = cv2.cvtColor(image_np, cv2.COLOR_GRAY2RGB)
18
+ elif image_np.shape[2] == 4: # RGBA to RGB
19
+ image_np = cv2.cvtColor(image_np, cv2.COLOR_RGBA2RGB)
20
+
21
+ # Perform prediction
22
+ results = model(image_np)
23
+
24
+ # Draw bounding boxes on the image
25
+ image_with_boxes = image_np.copy()
26
+ raw_predictions = []
27
+ for result in results[0].boxes:
28
+ label = "Positive" if result.cls.item() == 1 else "Negative" # Convert tensor to standard Python type
29
+ confidence = result.conf.item() # Convert tensor to standard Python type
30
+ xmin, ymin, xmax, ymax = map(int, result.xyxy[0])
31
+ cv2.rectangle(image_with_boxes, (xmin, ymin), (xmax, ymax), (255, 0, 0), 2)
32
+ cv2.putText(image_with_boxes, f'{label} {confidence:.2f}', (xmin, ymin - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)
33
+ raw_predictions.append(f"Label: {label}, Confidence: {confidence:.2f}, Box: [{xmin}, {ymin}, {xmax}, {ymax}]")
34
+
35
+ raw_predictions_str = "\n".join(raw_predictions)
36
+
37
+ return image_with_boxes, raw_predictions_str
38
+
39
+ # Create Gradio interface
40
+ inputs = gr.Image(type="pil")
41
+ outputs = [gr.Image(type="numpy", label="Predicted Image"), gr.Textbox(label="Raw Result")]
42
+ title = "YOLOv8 Glaucoma Detection"
43
+ description = "Insert an image and click submit to detect glaucoma."
44
+ iface = gr.Interface(fn=predict_image, inputs=inputs, outputs=outputs, title=title, description=description)
45
+
46
+ # Launch the interface
47
+ iface.launch()
best-glaucoma-seg.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:022416d3f286d1449c3a316c63be5434df1cf5aebee202b56ef80bd79206e994
3
+ size 6809443
font.ttf ADDED
Binary file (66.9 kB). View file
 
image-logo.png ADDED

Git LFS Details

  • SHA256: 4257bf30ac2b97a01288f25b3bfd7f55da46ff614076bcafdaea59683b1caf8f
  • Pointer size: 131 Bytes
  • Size of remote file: 270 kB
last.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:559b294684f9a5cef7c3e05296bd334e6b304a639cabf172451462215227bd75
3
+ size 6802157
requirements(1).txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ opencv-python-headless
3
+ ultralytics
4
+ numpy
5
+ Pillow
6
+ scikit-image