Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,11 +8,11 @@ from ultralytics import YOLO
|
|
8 |
|
9 |
# Define models
|
10 |
MODEL_OPTIONS = {
|
11 |
-
#"YOLOv11-Nano": "medieval-
|
12 |
-
"YOLOv11-Small": "medieval-
|
13 |
-
#"YOLOv11-Medium": "medieval-
|
14 |
-
#"YOLOv11-Large": "medieval-
|
15 |
-
#"YOLOv11-XLarge": "medieval-
|
16 |
}
|
17 |
|
18 |
# Dictionary to store loaded models
|
@@ -50,7 +50,13 @@ def detect_and_annotate(
|
|
50 |
boxes = results.boxes.xyxy.cpu().numpy()
|
51 |
confidence = results.boxes.conf.cpu().numpy()
|
52 |
class_ids = results.boxes.cls.cpu().numpy().astype(int)
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
# Create Detections object
|
56 |
detections = sv.Detections(
|
@@ -69,7 +75,8 @@ def detect_and_annotate(
|
|
69 |
|
70 |
# Annotate image with masks and labels
|
71 |
annotated_image = image.copy()
|
72 |
-
|
|
|
73 |
annotated_image = LABEL_ANNOTATOR.annotate(scene=annotated_image, detections=detections, labels=labels)
|
74 |
|
75 |
return annotated_image
|
|
|
8 |
|
9 |
# Define models
|
10 |
MODEL_OPTIONS = {
|
11 |
+
#"YOLOv11-Nano": "medieval-yolov11n.pt",
|
12 |
+
"YOLOv11-Small": "medieval-yolov11s.pt"
|
13 |
+
#"YOLOv11-Medium": "medieval-yolov11m.pt",
|
14 |
+
#"YOLOv11-Large": "medieval-yolov11l.pt",
|
15 |
+
#"YOLOv11-XLarge": "medieval-yolov11x.pt"
|
16 |
}
|
17 |
|
18 |
# Dictionary to store loaded models
|
|
|
50 |
boxes = results.boxes.xyxy.cpu().numpy()
|
51 |
confidence = results.boxes.conf.cpu().numpy()
|
52 |
class_ids = results.boxes.cls.cpu().numpy().astype(int)
|
53 |
+
|
54 |
+
# Handle masks if they exist
|
55 |
+
masks = None
|
56 |
+
if results.masks is not None:
|
57 |
+
masks = results.masks.data.cpu().numpy()
|
58 |
+
# Convert masks to boolean type
|
59 |
+
masks = masks.astype(bool)
|
60 |
|
61 |
# Create Detections object
|
62 |
detections = sv.Detections(
|
|
|
75 |
|
76 |
# Annotate image with masks and labels
|
77 |
annotated_image = image.copy()
|
78 |
+
if masks is not None:
|
79 |
+
annotated_image = MASK_ANNOTATOR.annotate(scene=annotated_image, detections=detections)
|
80 |
annotated_image = LABEL_ANNOTATOR.annotate(scene=annotated_image, detections=detections, labels=labels)
|
81 |
|
82 |
return annotated_image
|