SHAH-MEER commited on
Commit
fc04005
·
verified ·
1 Parent(s): 7f5ed2f

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +39 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ model = YOLO("runs/segment/train/weights/best.pt")
7
+
8
+ # Prediction function for image
9
+ def segment_image(image):
10
+ results = model(image)[0]
11
+ return np.array(results.plot())
12
+
13
+ # Prediction function for video
14
+ def segment_video(video_path):
15
+ results = model(video_path)
16
+ return results[0].save(save_dir="segmented_video/") or "segmented_video/predict.mp4"
17
+
18
+
19
+ with gr.Blocks(theme=gr.themes.Soft(),title='YOLOv11 Image Segmentation') as demo:
20
+ gr.Markdown("# YOLOv11 Image Segmentation")
21
+ with gr.Row():
22
+ img_input = gr.Image(type="pil", label="Upload an Image")
23
+ img_output = gr.Image(label="Segmented Image")
24
+ img_button = gr.Button("Segment Image")
25
+ img_button.click(segment_image, inputs=img_input, outputs=img_output)
26
+
27
+ gr.Examples(
28
+ examples=[
29
+ "datasets/coco8-seg/images/train/000000000025.jpg",
30
+ "datasets/coco8-seg/images/train/000000000009.jpg"
31
+ ],
32
+ inputs=img_input,
33
+ outputs=img_output,
34
+ fn=segment_image,
35
+ label="Example Images"
36
+ )
37
+
38
+ demo.launch(inbrowser=True)
39
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ ultralytics
3
+ Pillow
4
+ numpy