johnlockejrr commited on
Commit
8d8b58e
·
verified ·
1 Parent(s): 05cd0a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -8,11 +8,11 @@ from ultralytics import YOLO
8
 
9
  # Define models
10
  MODEL_OPTIONS = {
11
- #"YOLOv11-Nano": "medieval-yolo11n-seg.pt",
12
- "YOLOv11-Small": "medieval-yolo11s-seg.pt"
13
- #"YOLOv11-Medium": "medieval-yolo11m-seg.pt",
14
- #"YOLOv11-Large": "medieval-yolo11l-seg.pt",
15
- #"YOLOv11-XLarge": "medieval-yolo11x-seg.pt"
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
- masks = results.masks.data.cpu().numpy() if results.masks is not None else None
 
 
 
 
 
 
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
- annotated_image = MASK_ANNOTATOR.annotate(scene=annotated_image, detections=detections)
 
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