Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,9 +17,19 @@ model = YOLO(model_path)
|
|
| 17 |
|
| 18 |
# ---- Detection function ----
|
| 19 |
def detect_objects(image):
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
annotated = results[0].plot()
|
| 24 |
return Image.fromarray(annotated)
|
| 25 |
|
|
|
|
| 17 |
|
| 18 |
# ---- Detection function ----
|
| 19 |
def detect_objects(image):
|
| 20 |
+
# Convert PIL to RGB NumPy array (YOLO expects RGB)
|
| 21 |
+
img = np.array(image.convert("RGB"))
|
| 22 |
+
|
| 23 |
+
# Run prediction with same settings used during training
|
| 24 |
+
results = model.predict(
|
| 25 |
+
source=img,
|
| 26 |
+
imgsz=640, # same resolution as training
|
| 27 |
+
conf=0.25, # lower confidence threshold to catch subtle detections
|
| 28 |
+
iou=0.45, # standard non-max suppression
|
| 29 |
+
verbose=False
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Visualize results
|
| 33 |
annotated = results[0].plot()
|
| 34 |
return Image.fromarray(annotated)
|
| 35 |
|