
    |hQ                         d dl m Z  d dlmZ d dlmZmZmZ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	)
    )copy)Path)AnyListOptionalUnion)yolo)OBBModel)DEFAULT_CFGRANKc            	            e Zd ZdZeddfdee   deee      f fdZ		 ddee
eef      dee
eef      ded	ef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()
    N	overrides
_callbacksc                 :    |i }d|d<   t         |   |||       y)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[Any], 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cfgr   r   	__class__s       `/var/www/html/test/engine/venv/lib/python3.12/site-packages/ultralytics/models/yolo/obb/train.pyr   zOBBTrainer.__init__"   s+    ( I!	&i4    r   weightsverbosereturnc                     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   chr   )r
   datar   load)r   r   r   r   models        r   	get_modelzOBBTrainer.get_model;   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_validatorT   sG    <xx$$t}}4		?W[WeWe % 
 	
r   )NNT)__name__
__module____qualname____doc__r   r   dictr   r   r   r   strr   boolr
   r&   r1   __classcell__)r   s   @r   r   r      s    * 'Dlp 58D> 5V^_cdg_hVi 54 swE#t),-?GcSWiHX?Yko	2
r   r   N)r   pathlibr   typingr   r   r   r   ultralytics.modelsr	   ultralytics.nn.tasksr
   ultralytics.utilsr   r   detectDetectionTrainerr    r   r   <module>rB      s4      - - # ) /M
-- M
r   