diff --git a/docs/en/modes/track.md b/docs/en/modes/track.md index 9d93aed2..39314060 100644 --- a/docs/en/modes/track.md +++ b/docs/en/modes/track.md @@ -289,7 +289,7 @@ In the following example, we demonstrate how to utilize YOLO11's tracking capabi result = model.track(frame, persist=True)[0] # Get the boxes and track IDs - if result.boxes and result.boxes.id is not None: + if result.boxes and result.boxes.is_track: boxes = result.boxes.xywh.cpu() track_ids = result.boxes.id.int().cpu().tolist() diff --git a/docs/en/usage/simple-utilities.md b/docs/en/usage/simple-utilities.md index 75a8fc31..2124f67f 100644 --- a/docs/en/usage/simple-utilities.md +++ b/docs/en/usage/simple-utilities.md @@ -436,7 +436,7 @@ Ultralytics includes an `Annotator` class for annotating various data types. It' cv2.namedWindow(window_name) cv2.setMouseCallback(window_name, drag_line) - if results.boxes.id is not None: + if results.boxes.is_track: if results.masks is not None: masks = results.masks boxes = results.boxes diff --git a/examples/YOLOv8-Action-Recognition/action_recognition.py b/examples/YOLOv8-Action-Recognition/action_recognition.py index 93bdcf2e..5c643c12 100644 --- a/examples/YOLOv8-Action-Recognition/action_recognition.py +++ b/examples/YOLOv8-Action-Recognition/action_recognition.py @@ -409,7 +409,7 @@ def run( # Run YOLO tracking results = yolo_model.track(frame, persist=True, classes=[0]) # Track only person class - if results[0].boxes.id is not None: + if results[0].boxes.is_track: boxes = results[0].boxes.xyxy.cpu().numpy() track_ids = results[0].boxes.id.cpu().numpy() diff --git a/examples/YOLOv8-Region-Counter/yolov8_region_counter.py b/examples/YOLOv8-Region-Counter/yolov8_region_counter.py index f2f008c2..2f15f0b2 100644 --- a/examples/YOLOv8-Region-Counter/yolov8_region_counter.py +++ b/examples/YOLOv8-Region-Counter/yolov8_region_counter.py @@ -156,7 +156,7 @@ def run( # Extract the results results = model.track(frame, persist=True, classes=classes) - if results[0].boxes.id is not None: + if results[0].boxes.is_track: boxes = results[0].boxes.xyxy.cpu() track_ids = results[0].boxes.id.int().cpu().tolist() clss = results[0].boxes.cls.cpu().tolist() diff --git a/examples/object_tracking.ipynb b/examples/object_tracking.ipynb index 9b9c0749..646503eb 100644 --- a/examples/object_tracking.ipynb +++ b/examples/object_tracking.ipynb @@ -169,7 +169,7 @@ " results = model.track(im0, persist=True)\n", "\n", " # Check if tracking IDs and masks are present in the results\n", - " if results[0].boxes.id is not None and results[0].masks is not None:\n", + " if results[0].boxes.is_track and results[0].masks is not None:\n", " # Extract masks and tracking IDs\n", " masks = results[0].masks.xy\n", " track_ids = results[0].boxes.id.int().cpu().tolist()\n", diff --git a/ultralytics/engine/results.py b/ultralytics/engine/results.py index 41bdad2e..284f9a93 100644 --- a/ultralytics/engine/results.py +++ b/ultralytics/engine/results.py @@ -558,7 +558,7 @@ class Results(SimpleClass, DataExportMixin): ) idx = ( pred_boxes.id - if pred_boxes.id is not None and color_mode == "instance" + if pred_boxes.is_track and color_mode == "instance" else pred_boxes.cls if pred_boxes and color_mode == "class" else reversed(range(len(pred_masks))) @@ -568,7 +568,7 @@ class Results(SimpleClass, DataExportMixin): # Plot Detect results if pred_boxes is not None and show_boxes: for i, d in enumerate(reversed(pred_boxes)): - c, d_conf, id = int(d.cls), float(d.conf) if conf else None, None if d.id is None else int(d.id.item()) + c, d_conf, id = int(d.cls), float(d.conf) if conf else None, int(d.id.item()) if d.is_track else None name = ("" if id is None else f"id:{id} ") + names[c] label = (f"{name} {d_conf:.2f}" if conf else name) if labels else None box = d.xyxyxyxy.reshape(-1, 4, 2).squeeze() if is_obb else d.xyxy.squeeze() @@ -733,7 +733,7 @@ class Results(SimpleClass, DataExportMixin): elif boxes: # Detect/segment/pose for j, d in enumerate(boxes): - c, conf, id = int(d.cls), float(d.conf), None if d.id is None else int(d.id.item()) + c, conf, id = int(d.cls), float(d.conf), int(d.id.item()) if d.is_track else None line = (c, *(d.xyxyxyxyn.view(-1) if is_obb else d.xywhn.view(-1))) if masks: seg = masks[j].xyn[0].copy().reshape(-1) # reversed mask.xyn, (n,2) to (n*2) diff --git a/ultralytics/solutions/ai_gym.py b/ultralytics/solutions/ai_gym.py index 591ad9bd..644e5d98 100644 --- a/ultralytics/solutions/ai_gym.py +++ b/ultralytics/solutions/ai_gym.py @@ -76,7 +76,7 @@ class AIGym(BaseSolution): self.extract_tracks(im0) # Extract tracks (bounding boxes, classes, and masks) tracks = self.tracks[0] - if tracks.boxes.id is not None: + if tracks.boxes.is_track: track_ids = tracks.boxes.id.cpu().tolist() kpt_data = tracks.keypoints.data.cpu() # Avoid repeated .cpu() calls diff --git a/ultralytics/solutions/heatmap.py b/ultralytics/solutions/heatmap.py index 7f555ffc..ebe5a4de 100644 --- a/ultralytics/solutions/heatmap.py +++ b/ultralytics/solutions/heatmap.py @@ -110,7 +110,7 @@ class Heatmap(ObjectCounter): self.display_counts(plot_im) # Display the counts on the frame # Normalize, apply colormap to heatmap and combine with original image - if self.track_data.id is not None: + if self.track_data.is_track: normalized_heatmap = cv2.normalize(self.heatmap, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8) colored_heatmap = cv2.applyColorMap(normalized_heatmap, self.colormap) plot_im = cv2.addWeighted(plot_im, 0.5, colored_heatmap, 0.5, 0) diff --git a/ultralytics/solutions/object_counter.py b/ultralytics/solutions/object_counter.py index 6ae2719d..c6133241 100644 --- a/ultralytics/solutions/object_counter.py +++ b/ultralytics/solutions/object_counter.py @@ -168,7 +168,7 @@ class ObjectCounter(BaseSolution): self.annotator = SolutionAnnotator(im0, line_width=self.line_width) # Initialize annotator is_obb = getattr(self.tracks[0], "obb", None) is not None # True if OBB results exist - if is_obb and self.track_data and self.track_data.id is not None: + if is_obb and self.track_data and self.track_data.is_track: self.boxes = self.track_data.xyxyxyxy.reshape(-1, 4, 2).cpu() self.annotator.draw_region( diff --git a/ultralytics/solutions/solutions.py b/ultralytics/solutions/solutions.py index 78ebc9b2..a6292127 100644 --- a/ultralytics/solutions/solutions.py +++ b/ultralytics/solutions/solutions.py @@ -172,7 +172,7 @@ class BaseSolution: ) self.track_data = self.tracks[0].obb or self.tracks[0].boxes # Extract tracks for OBB or object detection - if self.track_data and self.track_data.id is not None: + if self.track_data and self.track_data.is_track: self.boxes = self.track_data.xyxy.cpu() self.clss = self.track_data.cls.cpu().tolist() self.track_ids = self.track_data.id.int().cpu().tolist() diff --git a/ultralytics/trackers/README.md b/ultralytics/trackers/README.md index 8a143dd8..63038598 100644 --- a/ultralytics/trackers/README.md +++ b/ultralytics/trackers/README.md @@ -194,7 +194,7 @@ while cap.isOpened(): result = model.track(frame, persist=True)[0] # Get the boxes and track IDs - if result.boxes and result.boxes.id is not None: + if result.boxes and result.boxes.is_track: boxes = result.boxes.xywh.cpu() track_ids = result.boxes.id.int().cpu().tolist() else: