Ë
    ëÓ^jJ  ã                   óJ   — d Z ddlmZ ddlmZ  G d„ dej
                  «      Zy)zEDetection head: bounding-box regression + classification projections.é    N)ÚMLPc                   ó6   ‡ — e Zd ZdZdededdfˆ fd„Zd„ Zˆ xZS )ÚDetectionHeadaU  Projection head for object detection outputs.

    Wraps the classification linear layer and bounding-box MLP used by the LWDETR decoder to produce final detection
    predictions.

    Args:
        hidden_dim: Feature dimension coming from the transformer decoder.
        num_classes: Number of object classes (excluding background).
    Ú
hidden_dimÚnum_classesÚreturnNc                 ó~   •— t         ‰| �  «        t        j                  ||«      | _        t        ||dd«      | _        y )Né   é   )ÚsuperÚ__init__ÚnnÚLinearÚclass_embedr   Ú
bbox_embed)Úselfr   r   Ú	__class__s      €úh/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/rfdetr/models/heads/detection.pyr   zDetectionHead.__init__   s3   ø€ Ü‰ÑÔÜŸ9™9 Z°Ó=ˆÔÜ˜j¨*°a¸Ó;ˆ�ó    c                 ój   — | j                  |«      }| j                  |«      j                  «       }||fS )a�  Project decoder hidden states to class logits and box coordinates.

        Args:
            hs: Decoder output tensor of shape ``(B, N, hidden_dim)``.

        Returns:
            Tuple of ``(outputs_class, outputs_coord)`` where ``outputs_class`` has shape ``(B, N, num_classes)`` and
            ``outputs_coord`` has shape ``(B, N, 4)`` in ``[cx, cy, w, h]`` normalised to ``[0, 1]``.
        )r   r   Úsigmoid)r   ÚhsÚoutputs_classÚoutputs_coords       r   ÚforwardzDetectionHead.forward   s6   € ð ×(Ñ(¨Ó,ˆØŸ™¨Ó+×3Ñ3Ó5ˆØ˜mÐ+Ð+r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úintr   r   Ú__classcell__)r   s   @r   r   r      s'   ø„ ñð< 3ð <°Sð <¸Tõ <ö
,r   r   )r   Útorch.nnr   Úrfdetr.models.mathr   ÚModuler   © r   r   ú<module>r&      s!   ðñ Lå å "ô,�B—I‘Iõ ,r   