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

๊ณ ๊ธ‰ ์‚ฌ์šฉ์ž ์ง€์ •

Ultralytics YOLO ๋ช…๋ น์ค„๊ณผ Python ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋ชจ๋‘ ๊ธฐ๋ณธ ์—”์ง„ ์‹คํ–‰๊ธฐ์— ๋Œ€ํ•œ ๋†’์€ ์ˆ˜์ค€์˜ ์ถ”์ƒํ™”์ผ ๋ฟ์ž…๋‹ˆ๋‹ค. ํŠธ๋ ˆ์ด๋„ˆ ์—”์ง„์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.



Watch: ๋งˆ์Šคํ„ฐ๋ง Ultralytics YOLO : ๊ณ ๊ธ‰ ์‚ฌ์šฉ์ž ์ง€์ •

๋ฒ ์ด์Šค ํŠธ๋ ˆ์ด๋„ˆ

๋ฒ ์ด์Šค ํŠธ๋ ˆ์ด๋„ˆ์—๋Š” ์ผ๋ฐ˜์ ์ธ ์ƒ์šฉ๊ตฌ ํŠธ๋ ˆ์ด๋‹ ๋ฃจํ‹ด์ด ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ฌ๋ฐ”๋ฅธ ํ˜•์‹์„ ๋”ฐ๋ฅด๊ธฐ๋งŒ ํ•˜๋ฉด ํ•„์š”ํ•œ ํ•จ์ˆ˜๋‚˜ ์—ฐ์‚ฐ์„ ์žฌ์ •์˜ํ•˜์—ฌ ๋ชจ๋“  ์ž‘์—…์— ๋งž๊ฒŒ ์‚ฌ์šฉ์ž ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ด๋Ÿฌํ•œ ํ•จ์ˆ˜๋ฅผ ์žฌ์ •์˜ํ•˜์—ฌ ์ž์ฒด ์‚ฌ์šฉ์ž ์ง€์ • ๋ชจ๋ธ๊ณผ ๋ฐ์ดํ„ฐ ๋กœ๋”๋ฅผ ์ง€์›ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

  • get_model(cfg, weights) - ํ•™์Šตํ•  ๋ชจ๋ธ์„ ๊ตฌ์ถ•ํ•˜๋Š” ํ•จ์ˆ˜
  • get_dataloader() - ๋ฐ์ดํ„ฐ๋กœ๋”๋ฅผ ๋นŒ๋“œํ•˜๋Š” ํ•จ์ˆ˜ ์ž์„ธํ•œ ๋‚ด์šฉ๊ณผ ์†Œ์Šค ์ฝ”๋“œ๋Š” ๋‹ค์Œ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. BaseTrainer ์ฐธ์กฐ

ํƒ์ง€ ํŠธ๋ ˆ์ด๋„ˆ

์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. YOLO11 DetectionTrainer ๋ฅผ ํด๋ฆญํ•˜๊ณ  ์‚ฌ์šฉ์ž ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

from ultralytics.models.yolo.detect import DetectionTrainer

trainer = DetectionTrainer(overrides={...})
trainer.train()
trained_model = trainer.best  # get best model

ํƒ์ง€ ํŠธ๋ ˆ์ด๋„ˆ ์‚ฌ์šฉ์ž ์ง€์ •

ํŠธ๋ ˆ์ด๋„ˆ๋ฅผ ๋งž์ถค ์„ค์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ง€์ • ํƒ์ง€ ๋ชจ๋ธ์„ ํ•™์Šตํ•ฉ๋‹ˆ๋‹ค. ๋ฅผ ์ง์ ‘ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋ ค๋ฉด ๊ธฐ์กด the get_model ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค:

from ultralytics.models.yolo.detect import DetectionTrainer


class CustomTrainer(DetectionTrainer):
    def get_model(self, cfg, weights):
        """Loads a custom detection model given configuration and weight files."""
        ...


trainer = CustomTrainer(overrides={...})
trainer.train()

์ด์ œ ํŠธ๋ ˆ์ด๋„ˆ๋ฅผ ๋” ์‚ฌ์šฉ์ž ์ง€์ •ํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค:

  • ์‚ฌ์šฉ์ž ์ง€์ • loss function.
  • ์ถ”๊ฐ€ callback ๋งค 10์ดˆ๋งˆ๋‹ค Google ๋“œ๋ผ์ด๋ธŒ์— ๋ชจ๋ธ์„ ์—…๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค. epochs ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:
from ultralytics.models.yolo.detect import DetectionTrainer
from ultralytics.nn.tasks import DetectionModel


class MyCustomModel(DetectionModel):
    def init_criterion(self):
        """Initializes the loss function and adds a callback for uploading the model to Google Drive every 10 epochs."""
        ...


class CustomTrainer(DetectionTrainer):
    def get_model(self, cfg, weights):
        """Returns a customized detection model instance configured with specified config and weights."""
        return MyCustomModel(...)


# callback to upload model weights
def log_model(trainer):
    """Logs the path of the last model weight used by the trainer."""
    last_weight_path = trainer.last
    print(last_weight_path)


trainer = CustomTrainer(overrides={...})
trainer.add_callback("on_train_epoch_end", log_model)  # Adds to existing callback
trainer.train()

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

๊ธฐํƒ€ ์—”์ง„ ๊ตฌ์„ฑ ์š”์†Œ

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์œ ์‚ฌํ•˜๊ฒŒ ์‚ฌ์šฉ์ž ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๋‹ค๋ฅธ ๊ตฌ์„ฑ ์š”์†Œ๋„ ์žˆ์Šต๋‹ˆ๋‹ค. Validators ๊ทธ๋ฆฌ๊ณ  Predictors. ์ด์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ฐธ์กฐ ์„น์…˜์„ ์ฐธ์กฐํ•˜์„ธ์š”.

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

ํŠน์ • ์ž‘์—…์— ๋งž๊ฒŒ Ultralytics YOLO11 DetectionTrainer๋ฅผ ์‚ฌ์šฉ์ž ์ง€์ •ํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ•˜๋‚˜์š”?

์‚ฌ์šฉ์ž ์ง€์ •ํ•˜๋ ค๋ฉด Ultralytics YOLO11 DetectionTrainer ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ์žฌ์ •์˜ํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ •์˜ ๋ชจ๋ธ ๋ฐ ๋ฐ์ดํ„ฐ ๋กœ๋”์— ๋งž๊ฒŒ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋จผ์ € ๋‹ค์Œ์—์„œ ์ƒ์†์„ ์‹œ์ž‘ํ•˜์„ธ์š”. DetectionTrainer ์™€ ๊ฐ™์€ ๋ฉ”์„œ๋“œ๋ฅผ ์žฌ์ •์˜ํ•œ ๋‹ค์Œ get_model ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ง€์ • ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค:

from ultralytics.models.yolo.detect import DetectionTrainer


class CustomTrainer(DetectionTrainer):
    def get_model(self, cfg, weights):
        """Loads a custom detection model given configuration and weight files."""
        ...


trainer = CustomTrainer(overrides={...})
trainer.train()
trained_model = trainer.best  # get best model

๋ณ€๊ฒฝ๊ณผ ๊ฐ™์€ ์ถ”๊ฐ€ ์‚ฌ์šฉ์ž ์ง€์ •์˜ ๊ฒฝ์šฐ loss function ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ callback๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฝœ๋ฐฑ ๊ฐ€์ด๋“œ.

Ultralytics YOLO11 ์—์„œ ๋ฒ ์ด์Šค ํŠธ๋ ˆ์ด๋„ˆ์˜ ์ฃผ์š” ๊ตฌ์„ฑ ์š”์†Œ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?

๊ทธ๋ฆฌ๊ณ  BaseTrainer ์˜ Ultralytics YOLO11 ์€ ๊ต์œก ๋ฃจํ‹ด์˜ ๊ธฐ์ดˆ๊ฐ€ ๋˜๋ฉฐ ์ผ๋ฐ˜์ ์ธ ๋ฐฉ๋ฒ•์„ ์žฌ์ •์˜ํ•˜์—ฌ ๋‹ค์–‘ํ•œ ์ž‘์—…์— ๋งž๊ฒŒ ์‚ฌ์šฉ์ž ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฃผ์š” ๊ตฌ์„ฑ ์š”์†Œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

  • get_model(cfg, weights) ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•™์Šตํ•  ๋ชจ๋ธ์„ ๊ตฌ์ถ•ํ•ฉ๋‹ˆ๋‹ค.
  • get_dataloader() ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋กœ๋”๋ฅผ ๋นŒ๋“œํ•ฉ๋‹ˆ๋‹ค.

์‚ฌ์šฉ์ž ์ง€์ • ๋ฐ ์†Œ์Šค ์ฝ”๋“œ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋‹ค์Œ์„ ์ฐธ์กฐํ•˜์„ธ์š”. BaseTrainer ์ฐธ์กฐ.

Ultralytics YOLO11 DetectionTrainer์— ์ฝœ๋ฐฑ์„ ์ถ”๊ฐ€ํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ•˜๋‚˜์š”?

๋‹ค์Œ์—์„œ ์ฝœ๋ฐฑ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๊ต์œก ํ”„๋กœ์„ธ์Šค๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ณ  ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Ultralytics YOLO11 DetectionTrainer. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋‹ค์Œ์€ ๋ชจ๋“  ํ•™์Šต ํ›„ ๋ชจ๋ธ ๊ฐ€์ค‘์น˜๋ฅผ ๊ธฐ๋กํ•˜๋Š” ์ฝœ๋ฐฑ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. epoch:

from ultralytics.models.yolo.detect import DetectionTrainer


# callback to upload model weights
def log_model(trainer):
    """Logs the path of the last model weight used by the trainer."""
    last_weight_path = trainer.last
    print(last_weight_path)


trainer = DetectionTrainer(overrides={...})
trainer.add_callback("on_train_epoch_end", log_model)  # Adds to existing callbacks
trainer.train()

์ฝœ๋ฐฑ ์ด๋ฒคํŠธ ๋ฐ ์ง„์ž… ์ง€์ ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ฝœ๋ฐฑ ๊ฐ€์ด๋“œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

๋ชจ๋ธ ๊ต์œก์— Ultralytics YOLO11 ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?

Ultralytics YOLO11 ๋Š” ๊ฐ•๋ ฅํ•œ ์—”์ง„ ์‹คํ–‰๊ธฐ์— ๋Œ€ํ•œ ๋†’์€ ์ˆ˜์ค€์˜ ์ถ”์ƒํ™”๋ฅผ ์ œ๊ณตํ•˜๋ฏ€๋กœ ์‹ ์†ํ•œ ๊ฐœ๋ฐœ๊ณผ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•์— ์ด์ƒ์ ์ž…๋‹ˆ๋‹ค. ์ฃผ์š” ์ด์ ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

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

YOLO11 ์˜ ๊ธฐ๋Šฅ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ Ultralytics YOLO.

๋น„ํ‘œ์ค€ ๋ชจ๋ธ์— Ultralytics YOLO11 DetectionTrainer๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‚˜์š”?

์˜ˆ, Ultralytics YOLO11 DetectionTrainer ๋Š” ๋งค์šฐ ์œ ์—ฐํ•˜๋ฉฐ ๋น„ํ‘œ์ค€ ๋ชจ๋ธ์— ๋งž๊ฒŒ ์‚ฌ์šฉ์ž ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์—์„œ ์ƒ์†ํ•˜์—ฌ DetectionTrainer๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ • ๋ชจ๋ธ์˜ ์š”๊ตฌ ์‚ฌํ•ญ์„ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์„ ์˜ค๋ฒ„๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ๊ฐ„๋‹จํ•œ ์˜ˆ์ž…๋‹ˆ๋‹ค:

from ultralytics.models.yolo.detect import DetectionTrainer


class CustomDetectionTrainer(DetectionTrainer):
    def get_model(self, cfg, weights):
        """Loads a custom detection model."""
        ...


trainer = CustomDetectionTrainer(overrides={...})
trainer.train()

๋ณด๋‹ค ์ž์„ธํ•œ ์ง€์นจ๊ณผ ์˜ˆ์‹œ๋Š” DetectionTrainer ์„ค๋ช…์„œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

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

๋Œ“๊ธ€