
    .h                        d dl mZ d dlmZ d dlmZ 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	ej                  j                        Zy
)    )annotations)copy)Path)Any)yolo)OBBModel)DEFAULT_CFGRANKc                  L     e Zd ZdZeddfd fdZ	 d	 	 	 	 	 	 	 ddZd Z xZS )	
OBBTraineram  
    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()
    Nc                :    |i }d|d<   t         |   |||       y)a  
        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.
        Nobbtask)super__init__)selfcfg	overrides
_callbacks	__class__s       _/var/www/html/ai-service/venv/lib/python3.12/site-packages/ultralytics/models/yolo/obb/train.pyr   zOBBTrainer.__init__$   s+     I!	&i4    c                    t        || j                  d   | j                  d   |xr	 t        dk(        }|r|j                  |       |S )a  
        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")
        ncchannels)r   chverbose)r   datar
   load)r   r   weightsr   models        r   	get_modelzOBBTrainer.get_model4   sF    & 4TYYz5JT[Tj`dhj`jkJJwr   c                    d| _         t        j                  j                  | j                  | j
                  t        | j                        | j                        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   s    r   get_validatorzOBBTrainer.get_validatorM   sG    <xx$$t}}4		?W[WeWe % 
 	
r   )r   zdict | Noner   zlist[Any] | None)NNT)r   zstr | dict | Noner!   zstr | Path | Noner   boolreturnr   )	__name__
__module____qualname____doc__r	   r   r#   r.   __classcell__)r   s   @r   r   r      sH    * 'fj 5" ae$6GY]	2
r   r   N)
__future__r   r   pathlibr   typingr   ultralytics.modelsr   ultralytics.nn.tasksr   ultralytics.utilsr	   r
   detectDetectionTrainerr    r   r   <module>r?      s4    #    # ) /D
-- D
r   