๊ณ ๊ธ ์ฌ์ฉ์ ์ง์
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
. ์ด์ ๋ํ ์์ธํ ๋ด์ฉ์ ์ฐธ์กฐ ์น์
์ ์ฐธ์กฐํ์ธ์.
์์ฃผ ๋ฌป๋ ์ง๋ฌธ
ํน์ ์์ ์ ๋ง๊ฒ Ultralytics YOLOv8 DetectionTrainer๋ฅผ ์ฌ์ฉ์ ์ง์ ํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํ๋์?
์ฌ์ฉ์ ์ง์ ํ๋ ค๋ฉด Ultralytics YOLOv8 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 YOLOv8 ์์ ๋ฒ ์ด์ค ํธ๋ ์ด๋์ ์ฃผ์ ๊ตฌ์ฑ ์์๋ ๋ฌด์์ธ๊ฐ์?
๊ทธ๋ฆฌ๊ณ BaseTrainer
์ Ultralytics YOLOv8 ์ ๊ต์ก ๋ฃจํด์ ๊ธฐ์ด๊ฐ ๋๋ฉฐ ์ผ๋ฐ์ ์ธ ๋ฐฉ๋ฒ์ ์ฌ์ ์ํ์ฌ ๋ค์ํ ์์
์ ๋ง๊ฒ ์ฌ์ฉ์ ์ง์ ํ ์ ์์ต๋๋ค. ์ฃผ์ ๊ตฌ์ฑ ์์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
get_model(cfg, weights)
๋ฅผ ์ฌ์ฉํ์ฌ ํ์ตํ ๋ชจ๋ธ์ ๊ตฌ์ถํฉ๋๋ค.get_dataloader()
๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ๋ก๋๋ฅผ ๋น๋ํฉ๋๋ค.
์ฌ์ฉ์ ์ง์ ๋ฐ ์์ค ์ฝ๋์ ๋ํ ์์ธํ ๋ด์ฉ์ ๋ค์์ ์ฐธ์กฐํ์ธ์. BaseTrainer
์ฐธ์กฐ.
Ultralytics YOLOv8 DetectionTrainer์ ์ฝ๋ฐฑ์ ์ถ๊ฐํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํ๋์?
๋ค์์์ ์ฝ๋ฐฑ์ ์ถ๊ฐํ์ฌ ๊ต์ก ํ๋ก์ธ์ค๋ฅผ ๋ชจ๋ํฐ๋งํ๊ณ ์์ ํ ์ ์์ต๋๋ค. Ultralytics YOLOv8 DetectionTrainer
. ์๋ฅผ ๋ค์ด, ๋ค์์ ๋ชจ๋ ํ์ต ์ํฌํฌ ํ์ ๋ชจ๋ธ ๊ฐ์ค์น๋ฅผ ๊ธฐ๋กํ๋ ์ฝ๋ฐฑ์ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์
๋๋ค:
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 YOLOv8 ์ ์ฌ์ฉํด์ผ ํ๋ ์ด์ ๋ ๋ฌด์์ธ๊ฐ์?
Ultralytics YOLOv8 ๋ ๊ฐ๋ ฅํ ์์ง ์คํ๊ธฐ์ ๋ํ ๋์ ์์ค์ ์ถ์ํ๋ฅผ ์ ๊ณตํ๋ฏ๋ก ์ ์ํ ๊ฐ๋ฐ๊ณผ ์ปค์คํฐ๋ง์ด์ง์ ์ด์์ ์ ๋๋ค. ์ฃผ์ ์ด์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
- ์ฌ์ฉ ํธ์์ฑ: ๋ช ๋ น์ค๊ณผ Python ์ธํฐํ์ด์ค๋ ๋ชจ๋ ๋ณต์กํ ์์ ์ ๊ฐ์ํํฉ๋๋ค.
- ์ฑ๋ฅ: ์ค์๊ฐ ๊ฐ์ฒด ๊ฐ์ง ๋ฐ ๋ค์ํ ๋น์ AI ์ ํ๋ฆฌ์ผ์ด์ ์ ์ต์ ํ๋์ด ์์ต๋๋ค.
- ์ฌ์ฉ์ ์ง์ : ์ฌ์ฉ์ ์ง์ ๋ชจ๋ธ, ์์ค ํจ์ ๋ฐ ๋ฐ์ดํฐ ๋ก๋์ ๋ง๊ฒ ์ฝ๊ฒ ํ์ฅํ ์ ์์ต๋๋ค.
YOLOv8 ์ ๊ธฐ๋ฅ์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ Ultralytics YOLO.
๋นํ์ค ๋ชจ๋ธ์ Ultralytics YOLOv8 DetectionTrainer๋ฅผ ์ฌ์ฉํ ์ ์๋์?
์, Ultralytics YOLOv8 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 ์ค๋ช ์๋ฅผ ์ฐธ์กฐํ์ธ์.
์์ฑ 2023-11-12, ์ ๋ฐ์ดํธ 2024-07-04
์์ฑ์: glenn-jocher (7), RizwanMunawar (1), AyushExel (1), Laughing-q (1)