
    /jm                        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d	S )
    )annotations)copy)Path)yolo)OBBModel)DEFAULT_CFGRANKc                  >     e Zd ZdZeddfd fdZ	 dddZd Z xZS )
OBBTrainerat  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, dfl_loss,
            and angle_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="yolo26n-obb.pt", data="dota8.yaml", epochs=3)
        >>> trainer = OBBTrainer(overrides=args)
        >>> trainer.train()
    N	overridesdict | None
_callbacksc                `    |i }d|d<   t                                          |||           dS )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 (dict, optional): Dictionary of callback functions to be invoked during training.
        Nobbtask)super__init__)selfcfgr   r   	__class__s       f/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/ultralytics/models/yolo/obb/train.pyr   zOBBTrainer.__init__"   s<     I!	&i44444    Tr   str | dict | Noneweightsstr | Path | Noneverboseboolreturnr   c                    t          || j        d         | j        d         |o
t          dk              }|r|                    |           |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="yolo26n-obb.yaml", weights="yolo26n-obb.pt")
        ncchannels)r    chr   )r   datar	   load)r   r   r   r   models        r   	get_modelzOBBTrainer.get_model1   sS    $ 4TYz5JT[Tj`dhj`jkkk 	 JJwr   c                    d| _         t          j                            | j        | j        t          | j                  | j                  S )z@Return an instance of OBBValidator for validation of YOLO model.)box_losscls_lossdfl_loss
angle_loss)save_dirargsr   )	
loss_namesr   r   OBBValidatortest_loaderr-   r   r.   	callbacks)r   s    r   get_validatorzOBBTrainer.get_validatorI   sB    Jx$$t}4	??W[We % 
 
 	
r   )r   r   r   r   )NNT)r   r   r   r   r   r   r   r   )	__name__
__module____qualname____doc__r   r   r'   r3   __classcell__)r   s   @r   r   r      s         ( 'ae 5 5 5 5 5 5 5  ae    0
 
 
 
 
 
 
r   r   N)
__future__r   r   pathlibr   ultralytics.modelsr   ultralytics.nn.tasksr   ultralytics.utilsr   r	   detectDetectionTrainerr    r   r   <module>rA      s    # " " " " "             # # # # # # ) ) ) ) ) ) / / / / / / / /A
 A
 A
 A
 A
- A
 A
 A
 A
 A
r   