Update Tracker docstrings (#15469)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
Glenn Jocher 2024-08-14 00:32:15 +08:00 committed by GitHub
parent da2797a182
commit b7c5db94b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 501 additions and 196 deletions

View file

@ -15,6 +15,11 @@ class TrackState:
Tracked (int): State when the object is successfully tracked in subsequent frames.
Lost (int): State when the object is no longer tracked.
Removed (int): State when the object is removed from tracking.
Examples:
>>> state = TrackState.New
>>> if state == TrackState.New:
>>> print("Object is newly detected.")
"""
New = 0
@ -33,13 +38,13 @@ class BaseTrack:
is_activated (bool): Flag indicating whether the track is currently active.
state (TrackState): Current state of the track.
history (OrderedDict): Ordered history of the track's states.
features (list): List of features extracted from the object for tracking.
curr_feature (any): The current feature of the object being tracked.
features (List): List of features extracted from the object for tracking.
curr_feature (Any): The current feature of the object being tracked.
score (float): The confidence score of the tracking.
start_frame (int): The frame number where tracking started.
frame_id (int): The most recent frame ID processed by the track.
time_since_update (int): Frames passed since the last update.
location (tuple): The location of the object in the context of multi-camera tracking.
location (Tuple): The location of the object in the context of multi-camera tracking.
Methods:
end_frame: Returns the ID of the last frame where the object was tracked.
@ -50,12 +55,26 @@ class BaseTrack:
mark_lost: Marks the track as lost.
mark_removed: Marks the track as removed.
reset_id: Resets the global track ID counter.
Examples:
Initialize a new track and mark it as lost:
>>> track = BaseTrack()
>>> track.mark_lost()
>>> print(track.state) # Output: 2 (TrackState.Lost)
"""
_count = 0
def __init__(self):
"""Initializes a new track with unique ID and foundational tracking attributes."""
"""
Initializes a new track with a unique ID and foundational tracking attributes.
Examples:
Initialize a new track
>>> track = BaseTrack()
>>> print(track.track_id)
0
"""
self.track_id = 0
self.is_activated = False
self.state = TrackState.New
@ -70,36 +89,36 @@ class BaseTrack:
@property
def end_frame(self):
"""Return the last frame ID of the track."""
"""Returns the ID of the most recent frame where the object was tracked."""
return self.frame_id
@staticmethod
def next_id():
"""Increment and return the global track ID counter."""
"""Increment and return the next unique global track ID for object tracking."""
BaseTrack._count += 1
return BaseTrack._count
def activate(self, *args):
"""Abstract method to activate the track with provided arguments."""
"""Activates the track with provided arguments, initializing necessary attributes for tracking."""
raise NotImplementedError
def predict(self):
"""Abstract method to predict the next state of the track."""
"""Predicts the next state of the track based on the current state and tracking model."""
raise NotImplementedError
def update(self, *args, **kwargs):
"""Abstract method to update the track with new observations."""
"""Updates the track with new observations and data, modifying its state and attributes accordingly."""
raise NotImplementedError
def mark_lost(self):
"""Mark the track as lost."""
"""Marks the track as lost by updating its state to TrackState.Lost."""
self.state = TrackState.Lost
def mark_removed(self):
"""Mark the track as removed."""
"""Marks the track as removed by setting its state to TrackState.Removed."""
self.state = TrackState.Removed
@staticmethod
def reset_id():
"""Reset the global track ID counter."""
"""Reset the global track ID counter to its initial value."""
BaseTrack._count = 0