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

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

์ฐธ๊ณ 

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



ultralytics.trackers.track.on_predict_start(predictor, persist=False)

์˜ˆ์ธก ์ค‘ ๊ฐ์ฒด ์ถ”์ ์„ ์œ„ํ•ด ํŠธ๋ž˜์ปค๋ฅผ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

๋งค๊ฐœ๋ณ€์ˆ˜:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช… ๊ธฐ๋ณธ๊ฐ’
predictor object

ํŠธ๋ž˜์ปค๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ์˜ˆ์ธก์ž ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.

ํ•„์ˆ˜
persist bool

ํŠธ๋ž˜์ปค๊ฐ€ ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ ํŠธ๋ž˜์ปค๋ฅผ ์œ ์ง€ํ• ์ง€ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ False์ž…๋‹ˆ๋‹ค.

False

์˜ฌ๋ฆฌ๋‹ค:

์œ ํ˜• ์„ค๋ช…
AssertionError

ํŠธ๋ž˜์ปค ์œ ํ˜•์ด '๋ฐ”์ดํŠธํŠธ๋ž™' ๋˜๋Š” '๋ด‡์†ŒํŠธ'๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ.

์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/track.py
def on_predict_start(predictor: object, persist: bool = False) -> None:
    """
    Initialize trackers for object tracking during prediction.

    Args:
        predictor (object): The predictor object to initialize trackers for.
        persist (bool, optional): Whether to persist the trackers if they already exist. Defaults to False.

    Raises:
        AssertionError: If the tracker_type is not 'bytetrack' or 'botsort'.
    """
    if hasattr(predictor, "trackers") and persist:
        return

    tracker = check_yaml(predictor.args.tracker)
    cfg = IterableSimpleNamespace(**yaml_load(tracker))

    if cfg.tracker_type not in {"bytetrack", "botsort"}:
        raise AssertionError(f"Only 'bytetrack' and 'botsort' are supported for now, but got '{cfg.tracker_type}'")

    trackers = []
    for _ in range(predictor.dataset.bs):
        tracker = TRACKER_MAP[cfg.tracker_type](args=cfg, frame_rate=30)
        trackers.append(tracker)
        if predictor.dataset.mode != "stream":  # only need one tracker for other modes.
            break
    predictor.trackers = trackers
    predictor.vid_path = [None] * predictor.dataset.bs  # for determining when to reset tracker on new video



ultralytics.trackers.track.on_predict_postprocess_end(predictor, persist=False)

๊ฐ์ง€๋œ ์ƒ์ž๋ฅผ ํ›„์ฒ˜๋ฆฌํ•˜๊ณ  ๊ฐœ์ฒด ์ถ”์ ์„ ํ†ตํ•ด ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.

๋งค๊ฐœ๋ณ€์ˆ˜:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช… ๊ธฐ๋ณธ๊ฐ’
predictor object

์˜ˆ์ธก์„ ํฌํ•จํ•˜๋Š” ์˜ˆ์ธก์ž ๊ฐœ์ฒด์ž…๋‹ˆ๋‹ค.

ํ•„์ˆ˜
persist bool

ํŠธ๋ž˜์ปค๊ฐ€ ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ ํŠธ๋ž˜์ปค๋ฅผ ์œ ์ง€ํ• ์ง€ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ False์ž…๋‹ˆ๋‹ค.

False
์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/track.py
def on_predict_postprocess_end(predictor: object, persist: bool = False) -> None:
    """
    Postprocess detected boxes and update with object tracking.

    Args:
        predictor (object): The predictor object containing the predictions.
        persist (bool, optional): Whether to persist the trackers if they already exist. Defaults to False.
    """
    path, im0s = predictor.batch[:2]

    is_obb = predictor.args.task == "obb"
    is_stream = predictor.dataset.mode == "stream"
    for i in range(len(im0s)):
        tracker = predictor.trackers[i if is_stream else 0]
        vid_path = predictor.save_dir / Path(path[i]).name
        if not persist and predictor.vid_path[i if is_stream else 0] != vid_path:
            tracker.reset()
            predictor.vid_path[i if is_stream else 0] = vid_path

        det = (predictor.results[i].obb if is_obb else predictor.results[i].boxes).cpu().numpy()
        if len(det) == 0:
            continue
        tracks = tracker.update(det, im0s[i])
        if len(tracks) == 0:
            continue
        idx = tracks[:, -1].astype(int)
        predictor.results[i] = predictor.results[i][idx]

        update_args = {"obb" if is_obb else "boxes": torch.as_tensor(tracks[:, :-1])}
        predictor.results[i].update(**update_args)



ultralytics.trackers.track.register_tracker(model, persist)

์˜ˆ์ธก ์ค‘ ๊ฐ์ฒด ์ถ”์ ์„ ์œ„ํ•ด ์ถ”์  ์ฝœ๋ฐฑ์„ ๋ชจ๋ธ์— ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.

๋งค๊ฐœ๋ณ€์ˆ˜:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช… ๊ธฐ๋ณธ๊ฐ’
model object

์ถ”์  ์ฝœ๋ฐฑ์„ ๋“ฑ๋กํ•  ๋ชจ๋ธ ๊ฐœ์ฒด์ž…๋‹ˆ๋‹ค.

ํ•„์ˆ˜
persist bool

ํŠธ๋ž˜์ปค๊ฐ€ ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ ํŠธ๋ž˜์ปค๋ฅผ ์œ ์ง€ํ• ์ง€ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค.

ํ•„์ˆ˜
์˜ ์†Œ์Šค ์ฝ”๋“œ ultralytics/trackers/track.py
def register_tracker(model: object, persist: bool) -> None:
    """
    Register tracking callbacks to the model for object tracking during prediction.

    Args:
        model (object): The model object to register tracking callbacks for.
        persist (bool): Whether to persist the trackers if they already exist.
    """
    model.add_callback("on_predict_start", partial(on_predict_start, persist=persist))
    model.add_callback("on_predict_postprocess_end", partial(on_predict_postprocess_end, persist=persist))





Created 2023-11-12, Updated 2024-06-02
Authors: glenn-jocher (5), Burhan-Q (1), Laughing-q (1)