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

์ฝœ๋ฐฑ

์ฝœ๋ฐฑ

Ultralytics ํ”„๋ ˆ์ž„์›Œํฌ๋Š” ํŠธ๋ ˆ์ธ, ๋ฐธ, ๋‚ด๋ณด๋‚ด๊ธฐ, ์˜ˆ์ธก ๋ชจ๋“œ์˜ ์ „๋žต์  ๋‹จ๊ณ„์—์„œ ์ฝœ๋ฐฑ์„ ์ง„์ž…์ ์œผ๋กœ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ์ฝœ๋ฐฑ์€ Trainer, Validator๋˜๋Š” Predictor ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๊ฐ์ฒด์˜ ๋ชจ๋“  ์†์„ฑ์€ ๋ฌธ์„œ์˜ ์ฐธ์กฐ ์„น์…˜์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



Watch: ๋งˆ์Šคํ„ฐ๋ง Ultralytics YOLO : ์ฝœ๋ฐฑ

์˜ˆ์ œ

์˜ˆ์ธก์œผ๋กœ ์ถ”๊ฐ€ ์ •๋ณด ๋ฐ˜ํ™˜

์ด ์˜ˆ์ œ์—์„œ๋Š” ๊ฐ ๊ฒฐ๊ณผ ๊ฐ์ฒด์™€ ํ•จ๊ป˜ ์›๋ณธ ํ”„๋ ˆ์ž„์„ ๋ฐ˜ํ™˜ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

from ultralytics import YOLO


def on_predict_batch_end(predictor):
    """Handle prediction batch end by combining results with corresponding frames; modifies predictor results."""
    _, image, _, _ = predictor.batch

    # Ensure that image is a list
    image = image if isinstance(image, list) else [image]

    # Combine the prediction results with the corresponding frames
    predictor.results = zip(predictor.results, image)


# Create a YOLO model instance
model = YOLO("yolo11n.pt")

# Add the custom callback to the model
model.add_callback("on_predict_batch_end", on_predict_batch_end)

# Iterate through the results and frames
for result, frame in model.predict():  # or model.track()
    pass

๋ชจ๋“  ์ฝœ๋ฐฑ

์ง€์›๋˜๋Š” ๋ชจ๋“  ์ฝœ๋ฐฑ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ฝœ๋ฐฑ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

ํŠธ๋ ˆ์ด๋„ˆ ์ฝœ๋ฐฑ

์ฝœ๋ฐฑ ์„ค๋ช…
on_pretrain_routine_start ์‚ฌ์ „ ํ›ˆ๋ จ ๋ฃจํ‹ด์ด ์‹œ์ž‘๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_pretrain_routine_end ์‚ฌ์ „ ํ›ˆ๋ จ ๋ฃจํ‹ด์ด ๋๋‚˜๋ฉด ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_train_start ํŠธ๋ ˆ์ด๋‹ ์‹œ์ž‘ ์‹œ ํŠธ๋ฆฌ๊ฑฐ๋จ
on_train_epoch_start ๊ฐ ํ›ˆ๋ จ ์—ํฌํฌ๊ฐ€ ์‹œ์ž‘๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_train_batch_start ๊ฐ ๊ต์œก ๋ฐฐ์น˜๊ฐ€ ์‹œ์ž‘๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
optimizer_step ์˜ตํ‹ฐ๋งˆ์ด์ € ๋‹จ๊ณ„์—์„œ ํŠธ๋ฆฌ๊ฑฐ๋จ
on_before_zero_grad ๊ทธ๋ผ๋ฐ์ด์…˜์ด 0์ด ๋˜๊ธฐ ์ „์— ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_train_batch_end ๊ฐ ๊ต์œก ๋ฐฐ์น˜๊ฐ€ ๋๋‚  ๋•Œ๋งˆ๋‹ค ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_train_epoch_end ๊ฐ ํ›ˆ๋ จ ์—ํฌํฌ๊ฐ€ ๋๋‚  ๋•Œ๋งˆ๋‹ค ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_fit_epoch_end ๊ฐ ํ• ์—ํฌํฌ๊ฐ€ ๋๋‚  ๋•Œ๋งˆ๋‹ค ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_model_save ๋ชจ๋ธ์ด ์ €์žฅ๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_train_end ๊ต์œก ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ข…๋ฃŒ๋˜๋ฉด ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_params_update ๋ชจ๋ธ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์—…๋ฐ์ดํŠธ๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
teardown ๊ต์œก ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ •๋ฆฌ ์ค‘์ผ ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.

์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๊ธฐ ์ฝœ๋ฐฑ

์ฝœ๋ฐฑ ์„ค๋ช…
on_val_start ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๊ฐ€ ์‹œ์ž‘๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_val_batch_start ๊ฐ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋ฐฐ์น˜๊ฐ€ ์‹œ์ž‘๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_val_batch_end ๊ฐ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋ฐฐ์น˜๊ฐ€ ๋๋‚  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_val_end ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๊ฐ€ ์ข…๋ฃŒ๋˜๋ฉด ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.

์˜ˆ์ธก์ž ์ฝœ๋ฐฑ

์ฝœ๋ฐฑ ์„ค๋ช…
on_predict_start ์˜ˆ์ธก ํ”„๋กœ์„ธ์Šค๊ฐ€ ์‹œ์ž‘๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_predict_batch_start ๊ฐ ์˜ˆ์ธก ๋ฐฐ์น˜๊ฐ€ ์‹œ์ž‘๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_predict_postprocess_end ์˜ˆ์ธก ํ›„์ฒ˜๋ฆฌ ์ข…๋ฃŒ ์‹œ ํŠธ๋ฆฌ๊ฑฐ๋จ
on_predict_batch_end ๊ฐ ์˜ˆ์ธก ๋ฐฐ์น˜๊ฐ€ ๋๋‚  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_predict_end ์˜ˆ์ธก ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ข…๋ฃŒ๋˜๋ฉด ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.

๋‚ด๋ณด๋‚ด๊ธฐ ์ฝœ๋ฐฑ

์ฝœ๋ฐฑ ์„ค๋ช…
on_export_start ๋‚ด๋ณด๋‚ด๊ธฐ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์‹œ์ž‘๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
on_export_end ๋‚ด๋ณด๋‚ด๊ธฐ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ข…๋ฃŒ๋˜๋ฉด ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.

์ž์ฃผ ๋ฌป๋Š” ์งˆ๋ฌธ

Ultralytics ์ฝœ๋ฐฑ์ด๋ž€ ๋ฌด์—‡์ด๋ฉฐ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋‚˜์š”?

Ultralytics ์ฝœ๋ฐฑ ์€ ํ›ˆ๋ จ, ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ, ๋‚ด๋ณด๋‚ด๊ธฐ, ์˜ˆ์ธก๊ณผ ๊ฐ™์€ ๋ชจ๋ธ ์ž‘์—…์˜ ์ฃผ์š” ๋‹จ๊ณ„์—์„œ ํŠธ๋ฆฌ๊ฑฐ๋˜๋Š” ํŠน์ˆ˜ํ•œ ์ง„์ž…์ ์ž…๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ฝœ๋ฐฑ์„ ํ†ตํ•ด ํ”„๋กœ์„ธ์Šค์˜ ํŠน์ • ์ง€์ ์—์„œ ์‚ฌ์šฉ์ž ์ง€์ • ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ๊ฐœ์„ ํ•˜๊ณ  ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ ์ฝœ๋ฐฑ์€ Trainer, Validator๋˜๋Š” Predictor ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๊ฐœ์ฒด์˜ ์ž์„ธํ•œ ์†์„ฑ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ฐธ์กฐ ์„น์…˜.

์ฝœ๋ฐฑ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•œ ๋‹ค์Œ ๋ชจ๋ธ์— add_callback ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”. ๋‹ค์Œ์€ ์˜ˆ์ธก ์ค‘์— ์ถ”๊ฐ€ ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์˜ ์˜ˆ์ž…๋‹ˆ๋‹ค:

from ultralytics import YOLO


def on_predict_batch_end(predictor):
    """Handle prediction batch end by combining results with corresponding frames; modifies predictor results."""
    _, image, _, _ = predictor.batch
    image = image if isinstance(image, list) else [image]
    predictor.results = zip(predictor.results, image)


model = YOLO("yolo11n.pt")
model.add_callback("on_predict_batch_end", on_predict_batch_end)
for result, frame in model.predict():
    pass

์ฝœ๋ฐฑ์„ ์‚ฌ์šฉํ•˜์—ฌ Ultralytics ๊ต์œก ๋ฃจํ‹ด์„ ์‚ฌ์šฉ์ž ์ง€์ •ํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ•˜๋‚˜์š”?

์ฝœ๋ฐฑ์„ ์‚ฌ์šฉํ•˜์—ฌ Ultralytics ๊ต์œก ๋ฃจํ‹ด์„ ์‚ฌ์šฉ์ž ์ง€์ •ํ•˜๋ ค๋ฉด ๊ต์œก ํ”„๋กœ์„ธ์Šค์˜ ํŠน์ • ๋‹จ๊ณ„์— ๋กœ์ง์„ ์‚ฝ์ž…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Ultralytics YOLO ์—์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๊ต์œก ์ฝœ๋ฐฑ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. on_train_start, on_train_end๋ฐ on_train_batch_end. ์ด๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž ์ง€์ • ๋ฉ”ํŠธ๋ฆญ, ์ฒ˜๋ฆฌ ๋˜๋Š” ๋กœ๊น…์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Here's an example of how to freeze BatchNorm statistics when freezing layers with callbacks:

from ultralytics import YOLO


# Add a callback to put the frozen layers in eval mode to prevent BN values from changing
def put_in_eval_mode(trainer):
    n_layers = trainer.args.freeze
    if not isinstance(n_layers, int):
        return

    for i, (name, module) in enumerate(trainer.model.named_modules()):
        if name.endswith("bn") and int(name.split(".")[1]) < n_layers:
            module.eval()
            module.track_running_stats = False


model = YOLO("yolo11n.pt")
model.add_callback("on_train_epoch_start", put_in_eval_mode)
model.train(data="coco.yaml", epochs=10)

๊ต์œก ์ฝœ๋ฐฑ์„ ํšจ๊ณผ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๊ต์œก ๊ฐ€์ด๋“œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

Ultralytics YOLO ์—์„œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์ค‘์— ์ฝœ๋ฐฑ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?

์‚ฌ์šฉ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์ค‘ ์ฝœ๋ฐฑ ์˜ Ultralytics YOLO ์—์„œ ์‚ฌ์šฉ์ž ์ง€์ • ์ฒ˜๋ฆฌ, ๋กœ๊น… ๋˜๋Š” ๋ฉ”ํŠธ๋ฆญ ๊ณ„์‚ฐ์„ ํ—ˆ์šฉํ•˜์—ฌ ๋ชจ๋ธ ํ‰๊ฐ€๋ฅผ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝœ๋ฐฑ on_val_start, on_val_batch_end๋ฐ on_val_end ์‚ฌ์šฉ์ž ์ง€์ • ๋กœ์ง์„ ์‚ฝ์ž…ํ•  ์ˆ˜ ์žˆ๋Š” ์ง„์ž…์ ์„ ์ œ๊ณตํ•˜์—ฌ ์ƒ์„ธํ•˜๊ณ  ํฌ๊ด„์ ์ธ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ํ”„๋กœ์„ธ์Šค๋ฅผ ๋ณด์žฅํ•ฉ๋‹ˆ๋‹ค.

For instance, you might want to plot all the validation batches, instead of just the first 3. Here's how you can do that:

import inspect

from ultralytics import YOLO


def plot_samples(validator):
    frame = inspect.currentframe().f_back.f_back
    v = frame.f_locals
    validator.plot_val_samples(v["batch"], v["batch_i"])
    validator.plot_predictions(v["batch"], v["preds"], v["batch_i"])


model = YOLO("yolo11n.pt")
model.add_callback("on_val_batch_end", plot_samples)
model.val(data="coco.yaml")

์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ํ”„๋กœ์„ธ์Šค์— ์ฝœ๋ฐฑ์„ ํ†ตํ•ฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๊ฐ€์ด๋“œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

์˜ˆ์ธก ๋ชจ๋“œ์— ๋Œ€ํ•œ ์‚ฌ์šฉ์ž ์ง€์ • ์ฝœ๋ฐฑ์„ Ultralytics YOLO ์— ์–ด๋–ป๊ฒŒ ์ฒจ๋ถ€ํ•˜๋‚˜์š”?

์‚ฌ์šฉ์ž ์ง€์ • ์ฝœ๋ฐฑ์„ ์ฒจ๋ถ€ํ•˜๋ ค๋ฉด ์˜ˆ์ธก ๋ชจ๋“œ Ultralytics YOLO ์—์„œ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•˜๊ณ  ์˜ˆ์ธก ํ”„๋กœ์„ธ์Šค์— ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์ธ ์˜ˆ์ธก ์ฝœ๋ฐฑ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. on_predict_start, on_predict_batch_end๋ฐ on_predict_end. ์ด๋ฅผ ํ†ตํ•ด ์˜ˆ์ธก ์ถœ๋ ฅ์„ ์ˆ˜์ •ํ•˜๊ณ  ๋ฐ์ดํ„ฐ ๋กœ๊น… ๋˜๋Š” ๊ฒฐ๊ณผ ๋ณ€ํ™˜๊ณผ ๊ฐ™์€ ์ถ”๊ฐ€ ๊ธฐ๋Šฅ์„ ํ†ตํ•ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Here is an example where a custom callback is used to save predictions based on whether an object of a particular class is present:

from ultralytics import YOLO

model = YOLO("yolo11n.pt")

class_id = 2


def save_on_object(predictor):
    r = predictor.results[0]
    if class_id in r.boxes.cls:
        predictor.args.save = True
    else:
        predictor.args.save = False


model.add_callback("on_predict_postprocess_end", save_on_object)
results = model("pedestrians.mp4", stream=True, save=True)

for results in results:
    pass

๋ณด๋‹ค ์ž์„ธํ•œ ์‚ฌ์šฉ๋ฒ•์€ ์ž์„ธํ•œ ์ง€์นจ๊ณผ ์ถ”๊ฐ€ ์‚ฌ์šฉ์ž ์ง€์ • ์˜ต์…˜์ด ํฌํ•จ๋œ ์˜ˆ์ธก ๊ฐ€์ด๋“œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

Ultralytics YOLO ์—์„œ ์ฝœ๋ฐฑ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ช‡ ๊ฐ€์ง€ ์‹ค์ œ ์˜ˆ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?

Ultralytics YOLO ๋Š” ๊ต์œก, ๊ฒ€์ฆ ๋ฐ ์˜ˆ์ธก๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๋‹จ๊ณ„๋ฅผ ๊ฐœ์„ ํ•˜๊ณ  ์‚ฌ์šฉ์ž ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด ์ฝœ๋ฐฑ์˜ ๋‹ค์–‘ํ•œ ์‹ค์ œ ๊ตฌํ˜„์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ๋ช‡ ๊ฐ€์ง€ ์‹ค์šฉ์ ์ธ ์˜ˆ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

  1. ์‚ฌ์šฉ์ž ์ง€์ • ์ง€ํ‘œ ๋กœ๊น…: ๊ต์œก ์ข…๋ฃŒ ๋˜๋Š” ๊ฒ€์ฆ ๊ธฐ๊ฐ„๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๋‹จ๊ณ„์—์„œ ์ถ”๊ฐ€ ์ง€ํ‘œ๋ฅผ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค.
  2. ๋ฐ์ดํ„ฐ ์ฆ๊ฐ•: ์˜ˆ์ธก ๋˜๋Š” ํ•™์Šต ๋ฐฐ์น˜ ์ค‘์— ์‚ฌ์šฉ์ž ์ง€์ • ๋ฐ์ดํ„ฐ ๋ณ€ํ™˜ ๋˜๋Š” ์ฆ๊ฐ•์„ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.
  3. ์ค‘๊ฐ„ ๊ฒฐ๊ณผ: ์ถ”๊ฐ€ ๋ถ„์„ ๋˜๋Š” ์‹œ๊ฐํ™”๋ฅผ ์œ„ํ•ด ์˜ˆ์ธก ๋˜๋Š” ํ”„๋ ˆ์ž„๊ณผ ๊ฐ™์€ ์ค‘๊ฐ„ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ: ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ์˜ˆ์ธก ์ค‘์— ํ”„๋ ˆ์ž„์„ ์˜ˆ์ธก ๊ฒฐ๊ณผ์™€ ๊ฒฐํ•ฉํ•˜๊ธฐ on_predict_batch_end:

from ultralytics import YOLO


def on_predict_batch_end(predictor):
    """Combine prediction results with frames."""
    _, image, _, _ = predictor.batch
    image = image if isinstance(image, list) else [image]
    predictor.results = zip(predictor.results, image)


model = YOLO("yolo11n.pt")
model.add_callback("on_predict_batch_end", on_predict_batch_end)
for result, frame in model.predict():
    pass

์ „์ฒด ์ฝœ๋ฐฑ ์ฐธ์กฐ๋ฅผ ์‚ดํŽด๋ณด๊ณ  ๋” ๋งŽ์€ ์˜ต์…˜๊ณผ ์˜ˆ์‹œ๋ฅผ ์ฐพ์•„๋ณด์„ธ์š”.

๐Ÿ“…1 ๋…„ ์ „ ์ƒ์„ฑ๋จ โœ๏ธ ์—…๋ฐ์ดํŠธ๋จ 19 ์ผ ์ „

๋Œ“๊ธ€