§
    ·¯¸j¬  ã                   ó†   — d Z ddlZddlmZmZmZmZ ddlZddlm	Z	 ddl
mZ  ej        e¦  «        Z G d„ de¦  «        ZdS )zClassification training task.é    N)ÚCallableÚDictÚOptionalÚUnioné   )ÚTrainingTaskc                   ó"  ‡ — e Zd ZdZ	 	 	 ddej        deej        ef         dee	j
                 dee	j                 def
ˆ fd	„Z	 dd
ee         dd fd„Z	 	 ddedee         dej        fd„Zde	j        de	j        deee	j        f         fd„Zˆ xZS )ÚClassificationTaska?  Standard supervised classification task.

    Simple task that performs a forward pass through the model and computes
    the classification loss.

    Args:
        model: The model to train
        criterion: Loss function (e.g., CrossEntropyLoss)
        device: Device for task tensors/buffers
        dtype: Dtype for task tensors/buffers
        verbose: Enable info logging

    Example:
        >>> task = ClassificationTask(model, nn.CrossEntropyLoss(), device=torch.device('cuda'))
        >>> result = task(input, target)
        >>> result['loss'].backward()
    NTÚmodelÚ	criterionÚdeviceÚdtypeÚverbosec                 ó  •— t          ¦   «                              |||¬¦  «         || _        || _        | j        rDt          |dd ¦  «        pt          |¦  «        j        }t           	                    d|› �¦  «         d S d S )N)r   r   r   Ú__name__zClassificationTask: criterion=)
ÚsuperÚ__init__Útrainable_moduler   r   ÚgetattrÚtyper   Ú_loggerÚinfo)Úselfr   r   r   r   r   Ú	loss_nameÚ	__class__s          €úh/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/timm/task/classification.pyr   zClassificationTask.__init__    sŠ   ø€ õ 	‰Œ×Ò ¨e¸WÐÑEÔEÐEØ %ˆÔØ"ˆŒàŒ<ð 	GÝ 	¨:°tÑ<Ô<ÐXÅÀYÁÄÔ@XˆIÝ�LŠLÐE¸)ÐEÐEÑFÔFÐFÐFÐFð	Gð 	Gó    Ú
device_idsÚreturnc                 ó<   — ddl m}  || j        fd|i|¤Ž| _        | S )aK  Prepare task for distributed training.

        Wraps the model in DistributedDataParallel (DDP).

        Args:
            device_ids: List of device IDs for DDP (e.g., [local_rank])
            **ddp_kwargs: Additional arguments passed to DistributedDataParallel

        Returns:
            self (for method chaining)
        r   )ÚDistributedDataParallelr   )Útorch.nn.parallelr!   r   )r   r   Ú
ddp_kwargsÚDDPs       r   Úprepare_distributedz&ClassificationTask.prepare_distributed0   s?   € ð  	EÐDÐDÐDÐDÐDØ #  DÔ$9Ð _Ð _ÀjÐ _ÐT^Ð _Ð _ˆÔØˆr   ÚinductorÚbackendÚmodec                 óf   — t          j        | j        f||dœ|¤Ž| _        | j        | _        | j        S )z5Compile the classification model before DDP wrapping.)r'   r(   )ÚtorchÚcompiler   Ú
eval_model)r   r'   r(   Úcompile_kwargss       r   r+   zClassificationTask.compileD   s=   € õ !&¤¨dÔ.CÐ rÈWÐ[_Ð rÐ rÐcqÐ rÐ rˆÔàÔ/ˆŒØÔ$Ð$r   ÚinputÚtargetc                 ób   — |                       |¦  «        }|                      ||¦  «        }||dœS )a2  Forward pass through model and compute classification loss.

        Args:
            input: Input tensor [B, C, H, W]
            target: Target labels [B]

        Returns:
            Dictionary containing:
                - 'loss': Classification loss
                - 'output': Model logits
        )ÚlossÚoutput)r   r   )r   r.   r/   r2   r1   s        r   ÚforwardzClassificationTask.forwardP   sA   € ð  ×&Ò& uÑ-Ô-ˆØ�~Š~˜f fÑ-Ô-ˆð Øð
ð 
ð 	
r   )NNT)N)r&   N)r   Ú
__module__Ú__qualname__Ú__doc__ÚnnÚModuler   r   r   r*   r   r   Úboolr   Úlistr%   Ústrr+   ÚTensorr   r3   Ú__classcell__)r   s   @r   r
   r
      sf  ø€ € € € € ðð ð, .2Ø+/Ø ðGð Gà”9ðGð ˜RœY¨Ð0Ô1ðGð ˜Uœ\Ô*ð	Gð
 ˜EœKÔ(ðGð ðGð Gð Gð Gð Gð Gð$ *.ðð à  œðð 
ð	ð ð ð ð, &Ø"&ð
%ð 
%àð
%ð ˜3”-ð
%ð
 
Œð
%ð 
%ð 
%ð 
%ð
à”<ð
ð ”Lð
ð 
ˆc�5”<ÐÔ	 ð	
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r   r
   )r6   ÚloggingÚtypingr   r   r   r   r*   Útorch.nnr7   Útaskr   Ú	getLoggerr   r   r
   © r   r   ú<module>rD      sµ   ðØ #Ð #Ø €€€Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2à €€€Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð à
ˆ'Ô
˜HÑ
%Ô
%€ðY
ð Y
ð Y
ð Y
ð Y
˜ñ Y
ô Y
ð Y
ð Y
ð Y
r   