Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +30 -0
- railway_track_segment (1).pt +3 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
from ultralytics import YOLO
|
| 5 |
+
|
| 6 |
+
# Load model
|
| 7 |
+
model = YOLO("railway_track_segment.pt")
|
| 8 |
+
|
| 9 |
+
def segment_track(image):
|
| 10 |
+
"""Segment railway track from image"""
|
| 11 |
+
# Predict on CPU (no GPU available)
|
| 12 |
+
results = model.predict(image, conf=0.25, imgsz=640, device="cpu")
|
| 13 |
+
|
| 14 |
+
# Get segmented image
|
| 15 |
+
segmented = results[0].plot(boxes=False, conf=True, line_width=2)
|
| 16 |
+
segmented = cv2.cvtColor(segmented, cv2.COLOR_BGR2RGB)
|
| 17 |
+
|
| 18 |
+
return segmented
|
| 19 |
+
|
| 20 |
+
# Create interface
|
| 21 |
+
demo = gr.Interface(
|
| 22 |
+
fn=segment_track,
|
| 23 |
+
inputs=gr.Image(type="pil"),
|
| 24 |
+
outputs=gr.Image(type="numpy"),
|
| 25 |
+
title="Railway Track Segmentation",
|
| 26 |
+
description="Upload a railway track image to segment it"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Launch
|
| 30 |
+
demo.launch(share=True)
|
railway_track_segment (1).pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:82d3af89be96e8193c564ba39e69634160de99ae642c4f928ff9f4332d667db5
|
| 3 |
+
size 6012701
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
ultralytics
|