
    ^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    99Z=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  ",BII ,r   