Reference for ultralytics/models/yolo/obb/train.py
Improvements
This page is sourced from https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/yolo/obb/train.py. Have an improvement or example to add? Open a Pull Request — thank you! 🙏
class ultralytics.models.yolo.obb.train.OBBTrainer
OBBTrainer(self, cfg = DEFAULT_CFG, overrides: dict | None = None, _callbacks: list[Any] | None = None)
Bases: yolo.detect.DetectionTrainer
A class extending the DetectionTrainer class for training based on an Oriented Bounding Box (OBB) model.
This trainer specializes in training YOLO models that detect oriented bounding boxes, which are useful for detecting objects at arbitrary angles rather than just axis-aligned rectangles.
Args
| Name | Type | Description | Default |
|---|---|---|---|
cfg | dict, optional | Configuration dictionary for the trainer. Contains training parameters and model configuration. | DEFAULT_CFG |
overrides | dict, optional | Dictionary of parameter overrides for the configuration. Any values here will take precedence over those in cfg. | None |
_callbacks | list[Any], optional | List of callback functions to be invoked during training. | None |
Attributes
| Name | Type | Description |
|---|---|---|
loss_names | tuple | Names of the loss components used during training including box_loss, cls_loss, and dfl_loss. |
Methods
| Name | Description |
|---|---|
get_model | Return OBBModel initialized with specified config and weights. |
get_validator | Return an instance of OBBValidator for validation of YOLO model. |
Examples
>>> from ultralytics.models.yolo.obb import OBBTrainer
>>> args = dict(model="yolo11n-obb.pt", data="dota8.yaml", epochs=3)
>>> trainer = OBBTrainer(overrides=args)
>>> trainer.train()
Source code in ultralytics/models/yolo/obb/train.py
View on GitHubclass OBBTrainer(yolo.detect.DetectionTrainer):
"""A class extending the DetectionTrainer class for training based on an Oriented Bounding Box (OBB) model.
This trainer specializes in training YOLO models that detect oriented bounding boxes, which are useful for detecting
objects at arbitrary angles rather than just axis-aligned rectangles.
Attributes:
loss_names (tuple): Names of the loss components used during training including box_loss, cls_loss, and
dfl_loss.
Methods:
get_model: Return OBBModel initialized with specified config and weights.
get_validator: Return an instance of OBBValidator for validation of YOLO model.
Examples:
>>> from ultralytics.models.yolo.obb import OBBTrainer
>>> args = dict(model="yolo11n-obb.pt", data="dota8.yaml", epochs=3)
>>> trainer = OBBTrainer(overrides=args)
>>> trainer.train()
"""
def __init__(self, cfg=DEFAULT_CFG, overrides: dict | None = None, _callbacks: list[Any] | None = None):
"""Initialize an OBBTrainer object for training Oriented Bounding Box (OBB) models.
Args:
cfg (dict, optional): Configuration dictionary for the trainer. Contains training parameters and model
configuration.
overrides (dict, optional): Dictionary of parameter overrides for the configuration. Any values here will
take precedence over those in cfg.
_callbacks (list[Any], optional): List of callback functions to be invoked during training.
"""
if overrides is None:
overrides = {}
overrides["task"] = "obb"
super().__init__(cfg, overrides, _callbacks)
method ultralytics.models.yolo.obb.train.OBBTrainer.get_model
def get_model(self, cfg: str | dict | None = None, weights: str | Path | None = None, verbose: bool = True) -> OBBModel
Return OBBModel initialized with specified config and weights.
Args
| Name | Type | Description | Default |
|---|---|---|---|
cfg | str | dict, optional | Model configuration. Can be a path to a YAML config file, a dictionary containing configuration parameters, or None to use default configuration. | None |
weights | str | Path, optional | Path to pretrained weights file. If None, random initialization is used. | None |
verbose | bool | Whether to display model information during initialization. | True |
Returns
| Type | Description |
|---|---|
OBBModel | Initialized OBBModel with the specified configuration and weights. |
Examples
>>> trainer = OBBTrainer()
>>> model = trainer.get_model(cfg="yolo11n-obb.yaml", weights="yolo11n-obb.pt")
Source code in ultralytics/models/yolo/obb/train.py
View on GitHubdef get_model(
self, cfg: str | dict | None = None, weights: str | Path | None = None, verbose: bool = True
) -> OBBModel:
"""Return OBBModel initialized with specified config and weights.
Args:
cfg (str | dict, optional): Model configuration. Can be a path to a YAML config file, a dictionary
containing configuration parameters, or None to use default configuration.
weights (str | Path, optional): Path to pretrained weights file. If None, random initialization is used.
verbose (bool): Whether to display model information during initialization.
Returns:
(OBBModel): Initialized OBBModel with the specified configuration and weights.
Examples:
>>> trainer = OBBTrainer()
>>> model = trainer.get_model(cfg="yolo11n-obb.yaml", weights="yolo11n-obb.pt")
"""
model = OBBModel(cfg, nc=self.data["nc"], ch=self.data["channels"], verbose=verbose and RANK == -1)
if weights:
model.load(weights)
return model
method ultralytics.models.yolo.obb.train.OBBTrainer.get_validator
def get_validator(self)
Return an instance of OBBValidator for validation of YOLO model.
Source code in ultralytics/models/yolo/obb/train.py
View on GitHubdef get_validator(self):
"""Return an instance of OBBValidator for validation of YOLO model."""
self.loss_names = "box_loss", "cls_loss", "dfl_loss"
return yolo.obb.OBBValidator(
self.test_loader, save_dir=self.save_dir, args=copy(self.args), _callbacks=self.callbacks
)
📅 Created 1 year ago ✏️ Updated 10 days ago