์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

์ฐธ์กฐ ultralytics/trackers/bot_sort.py

์ฐธ๊ณ 

์ด ํŒŒ์ผ์€ https://github.com/ultralytics/ ultralytics/blob/main/ ultralytics/trackers/bot_sort .py์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ œ๋ฅผ ๋ฐœ๊ฒฌํ•˜๋ฉด ํ’€ ๋ฆฌํ€˜์ŠคํŠธ (๐Ÿ› ๏ธ) ๋ฅผ ํ†ตํ•ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋„๋ก ๋„์™€์ฃผ์„ธ์š”. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ™!



ultralytics.trackers.bot_sort.BOTrack

๋ฒ ์ด์Šค: STrack

๊ฐ์ฒด ์ถ”์  ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•œ YOLOv8 ์šฉ STrack ํด๋ž˜์Šค์˜ ํ™•์žฅ ๋ฒ„์ „์ž…๋‹ˆ๋‹ค.

์†์„ฑ:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช…
shared_kalman KalmanFilterXYWH

BOTrack์˜ ๋ชจ๋“  ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•œ ๊ณต์œ  ์นผ๋งŒ ํ•„ํ„ฐ์ž…๋‹ˆ๋‹ค.

smooth_feat ndarray

ํ‰ํ™œํ™”๋œ ํ”ผ์ฒ˜ ๋ฒกํ„ฐ.

curr_feat ndarray

ํ˜„์žฌ ํ”ผ์ฒ˜ ๋ฒกํ„ฐ.

features deque

์ตœ๋Œ€ ๊ธธ์ด๊ฐ€ ์ •์˜๋œ ํ”ผ์ฒ˜ ๋ฒกํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐํฌ์ž…๋‹ˆ๋‹ค. feat_history.

alpha float

ํ”ผ์ฒ˜์˜ ์ง€์ˆ˜ ์ด๋™ ํ‰๊ท ์— ๋Œ€ํ•œ ํ‰ํ™œํ™” ๊ณ„์ˆ˜์ž…๋‹ˆ๋‹ค.

mean ndarray

์นผ๋งŒ ํ•„ํ„ฐ์˜ ํ‰๊ท  ์ƒํƒœ์ž…๋‹ˆ๋‹ค.

covariance ndarray

์นผ๋งŒ ํ•„ํ„ฐ์˜ ๊ณต๋ถ„์‚ฐ ํ–‰๋ ฌ์ž…๋‹ˆ๋‹ค.

๋ฐฉ๋ฒ•:

์ด๋ฆ„ ์„ค๋ช…
update_features

ํŠน์ง• ๋ฒกํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ณ  ์ง€์ˆ˜ ์ด๋™ ํ‰๊ท ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ‰ํ™œํ™”ํ•ฉ๋‹ˆ๋‹ค.

predict

์นผ๋งŒ ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ‰๊ท ๊ณผ ๊ณต๋ถ„์‚ฐ์„ ์˜ˆ์ธกํ•ฉ๋‹ˆ๋‹ค.

re_activate

์—…๋ฐ์ดํŠธ๋œ ๊ธฐ๋Šฅ ๋ฐ ์„ ํƒ์ ์œผ๋กœ ์ƒˆ ID๋กœ ํŠธ๋ž™์„ ์žฌํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค.

update

YOLOv8 ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒˆ ํŠธ๋ž™ ๋ฐ ํ”„๋ ˆ์ž„ ID๋กœ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.

tlwh

ํ˜„์žฌ ์œ„์น˜๋ฅผ tlwh ํ˜•์‹์œผ๋กœ ๊ฐ€์ ธ์˜ค๋Š” ์†์„ฑ (top left x, top left y, width, height).

multi_predict

๊ณต์œ  ์นผ๋งŒ ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ ์˜ค๋ธŒ์ ํŠธ ํŠธ๋ž™์˜ ํ‰๊ท ๊ณผ ๊ณต๋ถ„์‚ฐ์„ ์˜ˆ์ธกํ•ฉ๋‹ˆ๋‹ค.

convert_coords

tlwh ๊ฒฝ๊ณ„ ์ƒ์ž ์ขŒํ‘œ๋ฅผ xywh ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

tlwh_to_xywh

๋ฐ”์šด๋”ฉ ๋ฐ•์Šค๋ฅผ xywh ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ (center x, center y, width, height).

์‚ฌ์šฉ๋ฒ•

bo_track = BOTrack(tlwh, score, cls, feat) bo_track.predict() bo_track.update(new_track, frame_id)

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
class BOTrack(STrack):
    """
    An extended version of the STrack class for YOLOv8, adding object tracking features.

    Attributes:
        shared_kalman (KalmanFilterXYWH): A shared Kalman filter for all instances of BOTrack.
        smooth_feat (np.ndarray): Smoothed feature vector.
        curr_feat (np.ndarray): Current feature vector.
        features (deque): A deque to store feature vectors with a maximum length defined by `feat_history`.
        alpha (float): Smoothing factor for the exponential moving average of features.
        mean (np.ndarray): The mean state of the Kalman filter.
        covariance (np.ndarray): The covariance matrix of the Kalman filter.

    Methods:
        update_features(feat): Update features vector and smooth it using exponential moving average.
        predict(): Predicts the mean and covariance using Kalman filter.
        re_activate(new_track, frame_id, new_id): Reactivates a track with updated features and optionally new ID.
        update(new_track, frame_id): Update the YOLOv8 instance with new track and frame ID.
        tlwh: Property that gets the current position in tlwh format `(top left x, top left y, width, height)`.
        multi_predict(stracks): Predicts the mean and covariance of multiple object tracks using shared Kalman filter.
        convert_coords(tlwh): Converts tlwh bounding box coordinates to xywh format.
        tlwh_to_xywh(tlwh): Convert bounding box to xywh format `(center x, center y, width, height)`.

    Usage:
        bo_track = BOTrack(tlwh, score, cls, feat)
        bo_track.predict()
        bo_track.update(new_track, frame_id)
    """

    shared_kalman = KalmanFilterXYWH()

    def __init__(self, tlwh, score, cls, feat=None, feat_history=50):
        """Initialize YOLOv8 object with temporal parameters, such as feature history, alpha and current features."""
        super().__init__(tlwh, score, cls)

        self.smooth_feat = None
        self.curr_feat = None
        if feat is not None:
            self.update_features(feat)
        self.features = deque([], maxlen=feat_history)
        self.alpha = 0.9

    def update_features(self, feat):
        """Update features vector and smooth it using exponential moving average."""
        feat /= np.linalg.norm(feat)
        self.curr_feat = feat
        if self.smooth_feat is None:
            self.smooth_feat = feat
        else:
            self.smooth_feat = self.alpha * self.smooth_feat + (1 - self.alpha) * feat
        self.features.append(feat)
        self.smooth_feat /= np.linalg.norm(self.smooth_feat)

    def predict(self):
        """Predicts the mean and covariance using Kalman filter."""
        mean_state = self.mean.copy()
        if self.state != TrackState.Tracked:
            mean_state[6] = 0
            mean_state[7] = 0

        self.mean, self.covariance = self.kalman_filter.predict(mean_state, self.covariance)

    def re_activate(self, new_track, frame_id, new_id=False):
        """Reactivates a track with updated features and optionally assigns a new ID."""
        if new_track.curr_feat is not None:
            self.update_features(new_track.curr_feat)
        super().re_activate(new_track, frame_id, new_id)

    def update(self, new_track, frame_id):
        """Update the YOLOv8 instance with new track and frame ID."""
        if new_track.curr_feat is not None:
            self.update_features(new_track.curr_feat)
        super().update(new_track, frame_id)

    @property
    def tlwh(self):
        """Get current position in bounding box format `(top left x, top left y, width, height)`."""
        if self.mean is None:
            return self._tlwh.copy()
        ret = self.mean[:4].copy()
        ret[:2] -= ret[2:] / 2
        return ret

    @staticmethod
    def multi_predict(stracks):
        """Predicts the mean and covariance of multiple object tracks using shared Kalman filter."""
        if len(stracks) <= 0:
            return
        multi_mean = np.asarray([st.mean.copy() for st in stracks])
        multi_covariance = np.asarray([st.covariance for st in stracks])
        for i, st in enumerate(stracks):
            if st.state != TrackState.Tracked:
                multi_mean[i][6] = 0
                multi_mean[i][7] = 0
        multi_mean, multi_covariance = BOTrack.shared_kalman.multi_predict(multi_mean, multi_covariance)
        for i, (mean, cov) in enumerate(zip(multi_mean, multi_covariance)):
            stracks[i].mean = mean
            stracks[i].covariance = cov

    def convert_coords(self, tlwh):
        """Converts Top-Left-Width-Height bounding box coordinates to X-Y-Width-Height format."""
        return self.tlwh_to_xywh(tlwh)

    @staticmethod
    def tlwh_to_xywh(tlwh):
        """Convert bounding box to format `(center x, center y, width, height)`."""
        ret = np.asarray(tlwh).copy()
        ret[:2] += ret[2:] / 2
        return ret

tlwh property

ํ˜„์žฌ ์œ„์น˜๋ฅผ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ํ˜•์‹์œผ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ (top left x, top left y, width, height).

__init__(tlwh, score, cls, feat=None, feat_history=50)

๊ธฐ๋Šฅ ํžˆ์Šคํ† ๋ฆฌ, ์•ŒํŒŒ ๋ฐ ํ˜„์žฌ ๊ธฐ๋Šฅ๊ณผ ๊ฐ™์€ ์ž„์‹œ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ YOLOv8 ๊ฐœ์ฒด๋ฅผ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def __init__(self, tlwh, score, cls, feat=None, feat_history=50):
    """Initialize YOLOv8 object with temporal parameters, such as feature history, alpha and current features."""
    super().__init__(tlwh, score, cls)

    self.smooth_feat = None
    self.curr_feat = None
    if feat is not None:
        self.update_features(feat)
    self.features = deque([], maxlen=feat_history)
    self.alpha = 0.9

convert_coords(tlwh)

์œ„์ชฝ-์™ผ์ชฝ-๋„ˆ๋น„-๋†’์ด ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ์ขŒํ‘œ๋ฅผ X-Y-๋„ˆ๋น„-๋†’์ด ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def convert_coords(self, tlwh):
    """Converts Top-Left-Width-Height bounding box coordinates to X-Y-Width-Height format."""
    return self.tlwh_to_xywh(tlwh)

multi_predict(stracks) staticmethod

๊ณต์œ  ์นผ๋งŒ ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ ์˜ค๋ธŒ์ ํŠธ ํŠธ๋ž™์˜ ํ‰๊ท ๊ณผ ๊ณต๋ถ„์‚ฐ์„ ์˜ˆ์ธกํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
@staticmethod
def multi_predict(stracks):
    """Predicts the mean and covariance of multiple object tracks using shared Kalman filter."""
    if len(stracks) <= 0:
        return
    multi_mean = np.asarray([st.mean.copy() for st in stracks])
    multi_covariance = np.asarray([st.covariance for st in stracks])
    for i, st in enumerate(stracks):
        if st.state != TrackState.Tracked:
            multi_mean[i][6] = 0
            multi_mean[i][7] = 0
    multi_mean, multi_covariance = BOTrack.shared_kalman.multi_predict(multi_mean, multi_covariance)
    for i, (mean, cov) in enumerate(zip(multi_mean, multi_covariance)):
        stracks[i].mean = mean
        stracks[i].covariance = cov

predict()

์นผ๋งŒ ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ‰๊ท ๊ณผ ๊ณต๋ถ„์‚ฐ์„ ์˜ˆ์ธกํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def predict(self):
    """Predicts the mean and covariance using Kalman filter."""
    mean_state = self.mean.copy()
    if self.state != TrackState.Tracked:
        mean_state[6] = 0
        mean_state[7] = 0

    self.mean, self.covariance = self.kalman_filter.predict(mean_state, self.covariance)

re_activate(new_track, frame_id, new_id=False)

์—…๋ฐ์ดํŠธ๋œ ๊ธฐ๋Šฅ์œผ๋กœ ํŠธ๋ž™์„ ์žฌํ™œ์„ฑํ™”ํ•˜๊ณ  ์„ ํƒ์ ์œผ๋กœ ์ƒˆ ID๋ฅผ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def re_activate(self, new_track, frame_id, new_id=False):
    """Reactivates a track with updated features and optionally assigns a new ID."""
    if new_track.curr_feat is not None:
        self.update_features(new_track.curr_feat)
    super().re_activate(new_track, frame_id, new_id)

tlwh_to_xywh(tlwh) staticmethod

๋ฐ”์šด๋”ฉ ๋ฐ•์Šค๋ฅผ ํฌ๋งท์œผ๋กœ ๋ณ€ํ™˜ (center x, center y, width, height).

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
@staticmethod
def tlwh_to_xywh(tlwh):
    """Convert bounding box to format `(center x, center y, width, height)`."""
    ret = np.asarray(tlwh).copy()
    ret[:2] += ret[2:] / 2
    return ret

update(new_track, frame_id)

YOLOv8 ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒˆ ํŠธ๋ž™ ๋ฐ ํ”„๋ ˆ์ž„ ID๋กœ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def update(self, new_track, frame_id):
    """Update the YOLOv8 instance with new track and frame ID."""
    if new_track.curr_feat is not None:
        self.update_features(new_track.curr_feat)
    super().update(new_track, frame_id)

update_features(feat)

ํŠน์ง• ๋ฒกํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ณ  ์ง€์ˆ˜ ์ด๋™ ํ‰๊ท ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ‰ํ™œํ™”ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def update_features(self, feat):
    """Update features vector and smooth it using exponential moving average."""
    feat /= np.linalg.norm(feat)
    self.curr_feat = feat
    if self.smooth_feat is None:
        self.smooth_feat = feat
    else:
        self.smooth_feat = self.alpha * self.smooth_feat + (1 - self.alpha) * feat
    self.features.append(feat)
    self.smooth_feat /= np.linalg.norm(self.smooth_feat)



ultralytics.trackers.bot_sort.BOTSORT

๋ฒ ์ด์Šค: BYTETracker

ReID ๋ฐ GMC ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•œ ๊ฐ์ฒด ์ถ”์ ์„ ์œ„ํ•ด ์„ค๊ณ„๋œ YOLOv8 ์šฉ BYTETracker ํด๋ž˜์Šค์˜ ํ™•์žฅ ๋ฒ„์ „์ž…๋‹ˆ๋‹ค.

์†์„ฑ:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช…
proximity_thresh float

ํŠธ๋ž™๊ณผ ํƒ์ง€ ์‚ฌ์ด์˜ ๊ณต๊ฐ„์  ๊ทผ์ ‘์„ฑ(IoU)์— ๋Œ€ํ•œ ์ž„๊ณ„๊ฐ’์ž…๋‹ˆ๋‹ค.

appearance_thresh float

ํŠธ๋ž™๊ณผ ํƒ์ง€ ๊ฐ„์˜ ์™ธ๊ด€ ์œ ์‚ฌ์„ฑ(ReID ์ž„๋ฒ ๋”ฉ)์— ๋Œ€ํ•œ ์ž„๊ณ„๊ฐ’์ž…๋‹ˆ๋‹ค.

encoder object

ReID ์ž„๋ฒ ๋”ฉ์„ ์ฒ˜๋ฆฌํ•  ๊ฐ์ฒด๋กœ, ReID๊ฐ€ ํ™œ์„ฑํ™”๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ์—†์Œ์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

gmc GMC

๋ฐ์ดํ„ฐ ์—ฐ๊ฒฐ์„ ์œ„ํ•œ GMC ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค.

args object

์ถ”์  ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ํฌํ•จ๋œ ๋ช…๋ น์ค„ ์ธ์ˆ˜๋ฅผ ๊ตฌ๋ฌธ ๋ถ„์„ํ–ˆ์Šต๋‹ˆ๋‹ค.

๋ฐฉ๋ฒ•:

์ด๋ฆ„ ์„ค๋ช…
get_kalmanfilter

๊ฐ์ฒด ์ถ”์ ์„ ์œ„ํ•œ ์นผ๋งŒํ•„ํ„ฐXYWH ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

init_track

๊ฐ์ง€, ์ ์ˆ˜ ๋ฐ ํด๋ž˜์Šค๋กœ ํŠธ๋ž™์„ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

get_dists

IoU ๋ฐ (์„ ํƒ ์‚ฌํ•ญ) ReID๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠธ๋ž™๊ณผ ํƒ์ง€ ๊ฐ„์˜ ๊ฑฐ๋ฆฌ๋ฅผ ํŒŒ์•…ํ•ฉ๋‹ˆ๋‹ค.

multi_predict

YOLOv8 ๋ชจ๋ธ๋กœ ์—ฌ๋Ÿฌ ๊ฐœ์ฒด๋ฅผ ์˜ˆ์ธกํ•˜๊ณ  ์ถ”์ ํ•˜์„ธ์š”.

์‚ฌ์šฉ๋ฒ•

bot_sort = BOTSORT(args, frame_rate) bot_sort.init_track(dets, scores, cls, img) bot_sort.multi_predict(tracks)

์ฐธ๊ณ 

์ด ํด๋ž˜์Šค๋Š” YOLOv8 ๊ฐ์ฒด ๊ฐ์ง€ ๋ชจ๋ธ๊ณผ ํ•จ๊ป˜ ์ž‘๋™ํ•˜๋„๋ก ์„ค๊ณ„๋˜์—ˆ์œผ๋ฉฐ, args๋ฅผ ํ†ตํ•ด ํ™œ์„ฑํ™”๋œ ๊ฒฝ์šฐ์—๋งŒ ReID๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
class BOTSORT(BYTETracker):
    """
    An extended version of the BYTETracker class for YOLOv8, designed for object tracking with ReID and GMC algorithm.

    Attributes:
        proximity_thresh (float): Threshold for spatial proximity (IoU) between tracks and detections.
        appearance_thresh (float): Threshold for appearance similarity (ReID embeddings) between tracks and detections.
        encoder (object): Object to handle ReID embeddings, set to None if ReID is not enabled.
        gmc (GMC): An instance of the GMC algorithm for data association.
        args (object): Parsed command-line arguments containing tracking parameters.

    Methods:
        get_kalmanfilter(): Returns an instance of KalmanFilterXYWH for object tracking.
        init_track(dets, scores, cls, img): Initialize track with detections, scores, and classes.
        get_dists(tracks, detections): Get distances between tracks and detections using IoU and (optionally) ReID.
        multi_predict(tracks): Predict and track multiple objects with YOLOv8 model.

    Usage:
        bot_sort = BOTSORT(args, frame_rate)
        bot_sort.init_track(dets, scores, cls, img)
        bot_sort.multi_predict(tracks)

    Note:
        The class is designed to work with the YOLOv8 object detection model and supports ReID only if enabled via args.
    """

    def __init__(self, args, frame_rate=30):
        """Initialize YOLOv8 object with ReID module and GMC algorithm."""
        super().__init__(args, frame_rate)
        # ReID module
        self.proximity_thresh = args.proximity_thresh
        self.appearance_thresh = args.appearance_thresh

        if args.with_reid:
            # Haven't supported BoT-SORT(reid) yet
            self.encoder = None
        self.gmc = GMC(method=args.gmc_method)

    def get_kalmanfilter(self):
        """Returns an instance of KalmanFilterXYWH for object tracking."""
        return KalmanFilterXYWH()

    def init_track(self, dets, scores, cls, img=None):
        """Initialize track with detections, scores, and classes."""
        if len(dets) == 0:
            return []
        if self.args.with_reid and self.encoder is not None:
            features_keep = self.encoder.inference(img, dets)
            return [BOTrack(xyxy, s, c, f) for (xyxy, s, c, f) in zip(dets, scores, cls, features_keep)]  # detections
        else:
            return [BOTrack(xyxy, s, c) for (xyxy, s, c) in zip(dets, scores, cls)]  # detections

    def get_dists(self, tracks, detections):
        """Get distances between tracks and detections using IoU and (optionally) ReID embeddings."""
        dists = matching.iou_distance(tracks, detections)
        dists_mask = dists > self.proximity_thresh

        # TODO: mot20
        # if not self.args.mot20:
        dists = matching.fuse_score(dists, detections)

        if self.args.with_reid and self.encoder is not None:
            emb_dists = matching.embedding_distance(tracks, detections) / 2.0
            emb_dists[emb_dists > self.appearance_thresh] = 1.0
            emb_dists[dists_mask] = 1.0
            dists = np.minimum(dists, emb_dists)
        return dists

    def multi_predict(self, tracks):
        """Predict and track multiple objects with YOLOv8 model."""
        BOTrack.multi_predict(tracks)

    def reset(self):
        """Reset tracker."""
        super().reset()
        self.gmc.reset_params()

__init__(args, frame_rate=30)

ReID ๋ชจ๋“ˆ๊ณผ GMC ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ YOLOv8 ๊ฐœ์ฒด๋ฅผ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def __init__(self, args, frame_rate=30):
    """Initialize YOLOv8 object with ReID module and GMC algorithm."""
    super().__init__(args, frame_rate)
    # ReID module
    self.proximity_thresh = args.proximity_thresh
    self.appearance_thresh = args.appearance_thresh

    if args.with_reid:
        # Haven't supported BoT-SORT(reid) yet
        self.encoder = None
    self.gmc = GMC(method=args.gmc_method)

get_dists(tracks, detections)

IoU ๋ฐ (์„ ํƒ ์‚ฌํ•ญ) ReID ์ž„๋ฒ ๋”ฉ์„ ์‚ฌ์šฉํ•˜์—ฌ ํŠธ๋ž™๊ณผ ํƒ์ง€ ๊ฐ„์˜ ๊ฑฐ๋ฆฌ๋ฅผ ํŒŒ์•…ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def get_dists(self, tracks, detections):
    """Get distances between tracks and detections using IoU and (optionally) ReID embeddings."""
    dists = matching.iou_distance(tracks, detections)
    dists_mask = dists > self.proximity_thresh

    # TODO: mot20
    # if not self.args.mot20:
    dists = matching.fuse_score(dists, detections)

    if self.args.with_reid and self.encoder is not None:
        emb_dists = matching.embedding_distance(tracks, detections) / 2.0
        emb_dists[emb_dists > self.appearance_thresh] = 1.0
        emb_dists[dists_mask] = 1.0
        dists = np.minimum(dists, emb_dists)
    return dists

get_kalmanfilter()

๊ฐ์ฒด ์ถ”์ ์„ ์œ„ํ•œ ์นผ๋งŒํ•„ํ„ฐXYWH ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def get_kalmanfilter(self):
    """Returns an instance of KalmanFilterXYWH for object tracking."""
    return KalmanFilterXYWH()

init_track(dets, scores, cls, img=None)

๊ฐ์ง€, ์ ์ˆ˜ ๋ฐ ํด๋ž˜์Šค๋กœ ํŠธ๋ž™์„ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def init_track(self, dets, scores, cls, img=None):
    """Initialize track with detections, scores, and classes."""
    if len(dets) == 0:
        return []
    if self.args.with_reid and self.encoder is not None:
        features_keep = self.encoder.inference(img, dets)
        return [BOTrack(xyxy, s, c, f) for (xyxy, s, c, f) in zip(dets, scores, cls, features_keep)]  # detections
    else:
        return [BOTrack(xyxy, s, c) for (xyxy, s, c) in zip(dets, scores, cls)]  # detections

multi_predict(tracks)

YOLOv8 ๋ชจ๋ธ๋กœ ์—ฌ๋Ÿฌ ๊ฐœ์ฒด๋ฅผ ์˜ˆ์ธกํ•˜๊ณ  ์ถ”์ ํ•˜์„ธ์š”.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def multi_predict(self, tracks):
    """Predict and track multiple objects with YOLOv8 model."""
    BOTrack.multi_predict(tracks)

reset()

ํŠธ๋ž˜์ปค๋ฅผ ์žฌ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/bot_sort.py
def reset(self):
    """Reset tracker."""
    super().reset()
    self.gmc.reset_params()





์ƒ์„ฑ 2023-11-12, ์—…๋ฐ์ดํŠธ 2024-05-08
์ž‘์„ฑ์ž: Burhan-Q (1), glenn-jocher (3), Laughing-q (1)