Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,10 +8,10 @@ repo_id = "truthdotphd/vessel-detection"
|
|
| 8 |
model_path = hf_hub_download(repo_id=repo_id, filename="model.pt")
|
| 9 |
model = YOLO(model_path)
|
| 10 |
|
| 11 |
-
def detect_vessels(image):
|
| 12 |
-
# Run inference
|
| 13 |
-
results = model(image)
|
| 14 |
-
|
| 15 |
# Plot results
|
| 16 |
annotated_image = results[0].plot()
|
| 17 |
return cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
|
@@ -19,13 +19,17 @@ def detect_vessels(image):
|
|
| 19 |
# Create Gradio interface
|
| 20 |
demo = gr.Interface(
|
| 21 |
fn=detect_vessels,
|
| 22 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
outputs=gr.Image(),
|
| 24 |
title="Maritime Vessel Detection",
|
| 25 |
-
description="Upload an image to detect vessels",
|
| 26 |
-
examples=[["vessels.jpg"]],
|
| 27 |
theme=gr.themes.Soft()
|
| 28 |
)
|
| 29 |
|
| 30 |
# Launch the app
|
| 31 |
-
demo.launch()
|
|
|
|
| 8 |
model_path = hf_hub_download(repo_id=repo_id, filename="model.pt")
|
| 9 |
model = YOLO(model_path)
|
| 10 |
|
| 11 |
+
def detect_vessels(image, conf_threshold, iou_threshold):
|
| 12 |
+
# Run inference with custom thresholds
|
| 13 |
+
results = model(image, conf=conf_threshold, iou=iou_threshold)
|
| 14 |
+
|
| 15 |
# Plot results
|
| 16 |
annotated_image = results[0].plot()
|
| 17 |
return cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
|
|
|
| 19 |
# Create Gradio interface
|
| 20 |
demo = gr.Interface(
|
| 21 |
fn=detect_vessels,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.Image(type="numpy"),
|
| 24 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.25, step=0.05, label="Confidence Threshold"),
|
| 25 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.05, label="IoU Threshold")
|
| 26 |
+
],
|
| 27 |
outputs=gr.Image(),
|
| 28 |
title="Maritime Vessel Detection",
|
| 29 |
+
description="Upload an image to detect vessels. Adjust confidence and IoU thresholds to filter detections.",
|
| 30 |
+
examples=[["vessels.jpg", 0.25, 0.7]],
|
| 31 |
theme=gr.themes.Soft()
|
| 32 |
)
|
| 33 |
|
| 34 |
# Launch the app
|
| 35 |
+
demo.launch()
|