o
    Wh                     @   sL   d dl m Z  d dlmZ d dlmZ d dlmZmZ G dd dejj	Z
dS )    )copy)yolo)OBBModel)DEFAULT_CFGRANKc                       s:   e Zd ZdZeddf fdd	Zd
ddZdd	 Z  ZS )
OBBTraineraw  
    A class extending the DetectionTrainer class for training based on an Oriented Bounding Box (OBB) model.

    Attributes:
        loss_names (Tuple[str]): Names of the loss components used during training.

    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()
    Nc                    s(   |du ri }d|d< t  ||| dS )a  
        Initialize an OBBTrainer object for training Oriented Bounding Box (OBB) models.

        This trainer extends the DetectionTrainer class to specialize in training models that detect oriented
        bounding boxes. It automatically sets the task to 'obb' in the configuration.

        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, optional): List of callback functions to be invoked during training.

        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()
        Nobbtask)super__init__)selfcfg	overrides
_callbacks	__class__ U/var/www/vscode/kcb/lib/python3.10/site-packages/ultralytics/models/yolo/obb/train.pyr      s   zOBBTrainer.__init__Tc                 C   s6   t || jd | jd |otdkd}|r|| |S )a  
        Return OBBModel initialized with specified config and weights.

        Args:
            cfg (str | dict | None): 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 | None): 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="yolov8n-obb.yaml", weights="yolov8n-obb.pt")
        ncchannels)r   chverbose)r   datar   load)r   r   weightsr   modelr   r   r   	get_model5   s   $
zOBBTrainer.get_modelc                 C   s&   d| _ tjj| j| jt| j| jdS )z@Return an instance of OBBValidator for validation of YOLO model.)box_losscls_lossdfl_loss)save_dirargsr   )	
loss_namesr   r   OBBValidatortest_loaderr!   r   r"   	callbacks)r   r   r   r   get_validatorL   s   zOBBTrainer.get_validator)NNT)	__name__
__module____qualname____doc__r   r   r   r'   __classcell__r   r   r   r   r   
   s
    
r   N)r   ultralytics.modelsr   ultralytics.nn.tasksr   ultralytics.utilsr   r   detectDetectionTrainerr   r   r   r   r   <module>   s
   