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

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

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



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

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

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

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

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

์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. YOLOv8 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. ์ด์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ฐธ์กฐ ์„น์…˜์„ ์ฐธ์กฐํ•˜์„ธ์š”.



Created 2023-11-12, Updated 2024-06-02
Authors: glenn-jocher (6), RizwanMunawar (1), AyushExel (1), Laughing-q (1)

๋Œ“๊ธ€