Song commited on
Commit ·
7b3f280
1
Parent(s): 1e7b2ff
1225
Browse files- app.py +19 -8
- best0709.pt → best0715.pt +2 -2
app.py
CHANGED
|
@@ -1,12 +1,23 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from ultralytics import YOLO
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
iface
|
| 12 |
-
iface.launch(show_api=True)
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model = YOLO("best0715.pt")
|
| 6 |
|
| 7 |
+
def detect(image, conf_threshold=0.3):
|
| 8 |
+
results = model(image, conf=conf_threshold)
|
| 9 |
+
if len(results) == 0 or results[0].boxes is None or len(results[0].boxes) == 0:
|
| 10 |
+
return image, "No bear detected."
|
| 11 |
+
plotted = results[0].plot()
|
| 12 |
+
conf = results[0].boxes.conf[0].item()
|
| 13 |
+
return plotted, f"Detected bear with confidence {conf:.2f}"
|
| 14 |
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=detect,
|
| 17 |
+
inputs=[gr.Image(type="pil"), gr.Slider(0.1, 0.9, value=0.3, label="Confidence Threshold")],
|
| 18 |
+
outputs=[gr.Image(), gr.Textbox()],
|
| 19 |
+
title="Taiwanese Black Bear Detector",
|
| 20 |
+
description="Upload an image for detection."
|
| 21 |
+
)
|
| 22 |
|
| 23 |
+
iface.launch(share=True)
|
|
|
best0709.pt → best0715.pt
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:06e2747470091835b8bfd96a083be14c5f6d9edea180fddb68a65563f39d50ef
|
| 3 |
+
size 22513955
|