κ³ κΈ μ¬μ©μ μ§μ
Ultralytics YOLO λͺ λ Ήμ€κ³Ό Python μΈν°νμ΄μ€λ λͺ¨λ κΈ°λ³Έ μμ§ μ€νκΈ°μ λν λμ μμ€μ μΆμνμΌ λΏμ λλ€. νΈλ μ΄λ μμ§μ μ΄ν΄λ³΄κ² μ΅λλ€.
Watch: Mastering Ultralytics YOLO: Advanced Customization
λ² μ΄μ€ νΈλ μ΄λ
λ² μ΄μ€ νΈλ μ΄λμλ μΌλ°μ μΈ μμ©κ΅¬ νΈλ μ΄λ 루ν΄μ΄ ν¬ν¨λμ΄ μμ΅λλ€. μ¬λ°λ₯Έ νμμ λ°λ₯΄κΈ°λ§ νλ©΄ νμν ν¨μλ μ°μ°μ μ¬μ μνμ¬ λͺ¨λ μμ μ λ§κ² μ¬μ©μ μ§μ ν μ μμ΅λλ€. μλ₯Ό λ€μ΄, μ΄λ¬ν ν¨μλ₯Ό μ¬μ μνμ¬ μ¬μ©μ μ§μ λͺ¨λΈκ³Ό λ°μ΄ν° λ‘λλ₯Ό μ§μν μ μμ΅λλ€:
get_model(cfg, weights)
- νμ΅ν λͺ¨λΈμ ꡬμΆνλ ν¨μget_dataloader()
- λ°μ΄ν°λ‘λλ₯Ό λΉλνλ ν¨μ μμΈν λ΄μ©κ³Ό μμ€ μ½λλ λ€μμμ νμΈν μ μμ΅λλ€.BaseTrainer
μ°Έμ‘°
νμ§ νΈλ μ΄λ
Here's how you can use the 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
. μ΄μ λν μμΈν λ΄μ©μ μ°Έμ‘° μΉμ
μ μ°Έμ‘°νμΈμ.
μμ£Ό 묻λ μ§λ¬Έ
How do I customize the Ultralytics YOLO11 DetectionTrainer for specific tasks?
To customize the 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
λ₯Ό μ°Έμ‘°ν μ μμ΅λλ€. μ½λ°± κ°μ΄λ.
What are the key components of the BaseTrainer in Ultralytics YOLO11?
κ·Έλ¦¬κ³ BaseTrainer
in Ultralytics YOLO11 serves as the foundation for training routines and can be customized for various tasks by overriding its generic methods. Key components include:
get_model(cfg, weights)
λ₯Ό μ¬μ©νμ¬ νμ΅ν λͺ¨λΈμ ꡬμΆν©λλ€.get_dataloader()
λ₯Ό μ¬μ©νμ¬ λ°μ΄ν°λ‘λλ₯Ό λΉλν©λλ€.
μ¬μ©μ μ§μ λ° μμ€ μ½λμ λν μμΈν λ΄μ©μ λ€μμ μ°Έμ‘°νμΈμ. BaseTrainer
μ°Έμ‘°.
How can I add a callback to the Ultralytics YOLO11 DetectionTrainer?
You can add callbacks to monitor and modify the training process in Ultralytics YOLO11 DetectionTrainer
. For instance, here's how you can add a callback to log model weights after every training 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()
μ½λ°± μ΄λ²€νΈ λ° μ§μ μ§μ μ λν μμΈν λ΄μ©μ μ½λ°± κ°μ΄λλ₯Ό μ°Έμ‘°νμΈμ.
Why should I use Ultralytics YOLO11 for model training?
Ultralytics YOLO11 offers a high-level abstraction on powerful engine executors, making it ideal for rapid development and customization. Key benefits include:
- μ¬μ© νΈμμ±: λͺ λ Ήμ€κ³Ό Python μΈν°νμ΄μ€λ λͺ¨λ 볡μ‘ν μμ μ κ°μνν©λλ€.
- Performance: Optimized for real-time object detection and various vision AI applications.
- Customization: Easily extendable for custom models, loss functions, and dataloaders.
Learn more about YOLO11's capabilities by visiting Ultralytics YOLO.
Can I use the Ultralytics YOLO11 DetectionTrainer for non-standard models?
Yes, 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 μ€λͺ μλ₯Ό μ°Έμ‘°νμΈμ.