
    3j                        S SK Jr  S SKJr  S SKJr  S SKrS SKJr  S SK	J
r
  \ " S S5      5       r\ " S	 S
5      5       rg)    )annotations)	dataclass)OptionalN)KORNIA_CHECK)resizec                      \ rS rSr% SrS\S'   S\S'   SrS\S'   S	rS
\S'   \SS j5       r	        SS jr
SSS jjrSrg	)SegmentationResults   aL  Encapsulate the results obtained by a Segmentation model.

Args:
    logits: Results logits with shape :math:`(B, C, H, W)`, where :math:`C` refers to the number of predicted masks
    scores: The scores from the logits. Shape :math:`(B, C)`
    mask_threshold: The threshold value to generate the `binary_masks` from the `logits`

torch.Tensorlogitsscoresg        floatmask_thresholdNOptional[torch.Tensor]_original_res_logitsc                j    U R                   b  U R                   nOU R                  nXR                  :  $ )ac  Binary mask generated from logits considering the mask_threshold.

Shape will be the same of logits :math:`(B, C, H, W)` where :math:`C` is the number masks predicted.

.. note:: If you run `original_res_logits`, this will generate the masks
   based on the original resolution logits.
   Otherwise, this will use the low resolution logits (self.logits).
)r   r   r   )selfxs     R/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/models/structures.pybinary_masks SegmentationResults.binary_masks-   s3     $$0))AA&&&&    c                    U R                   n[        U[        5      (       a  [        XCSSSS9nUSSUS   2SUS   24   n[        XBSSSS9nX@l        U R                  $ )a  Remove padding and upscale the logits to the original image size.

Resize to image encoder input -> remove padding (bottom and right) -> Resize to original size

.. note:: This method set a internal `original_res_logits` which will be used if available for the binary masks.

Args:
    input_size: The size of the image input to the model, in (H, W) format. Used to remove padding.
    original_size: The original size of the image before resizing for input to the model, in (H, W) format.
    image_size_encoder: The size of the input image for image encoder, in (H, W) format. Used to resize the
                        logits back to encoder resolution before remove the padding.

Returns:
    Batched logits in :math:`(K, C, H, W)` format, where (H, W) is given by original_size.

bilinearF)sizeinterpolationalign_corners	antialias.Nr      )r   
isinstancetupler   r   )r   
input_sizeoriginal_sizeimage_size_encoderr   s        r   original_res_logits'SegmentationResults.original_res_logits>   sr    & KK(%00q[`lqrAc?Z]?OjmO341
RWchi$%!(((r   c                   U R                   R                  U5      U l         U R                  R                  U5      U l        [        U R                  [
        R                  5      (       a   U R                  R                  U5      U l        U $ )z7Realize a squeeze for the dim given for all properties.)r   squeezer   r    r   torchTensor)r   dims     r   r(   SegmentationResults.squeeze\   sc    kk))#.kk))#.d//>>(,(A(A(I(I#(ND%r   )r   r   r   )returnr   )r"   tuple[int, int]r#   r.   r$   zOptional[tuple[int, int]]r-   r   )r   )r+   intr-   r	   )__name__
__module____qualname____firstlineno____doc____annotations__r   r   propertyr   r%   r(   __static_attributes__ r   r   r	   r	      sl     NE3707' ' ))):I)_x)	)< r   r	   c                  v    \ rS rSr% SrSrS\S'   SrS\S'   SrS\S'   SS	 jr	\
SS
 j5       r\
SS j5       rSrg)Promptsf   a}  Encapsulate the prompts inputs for a Model.

Args:
    points: A tuple with the keypoints (coordinates x, y) and their respective labels. Shape :math:`(K, N, 2)` for
            the keypoints, and :math:`(K, N)`
    boxes: Batched box inputs, with shape :math:`(K, 4)`. Expected to be into xyxy format.
    masks: Batched mask prompts to the model with shape :math:`(K, 1, H, W)`

Nz+Optional[tuple[torch.Tensor, torch.Tensor]]pointsr   boxesmasksc                &   [        U R                  [        R                  5      (       ah  [        U R                  [        R                  5      (       a>  [        U R                  R                  S   U R                  R                  S   :H  S5        g g g )Nr   z,The prompts should have the same batch size!)r    	keypointsr)   r*   r=   r   shaper   s    r   __post_init__Prompts.__post_init__v   sb    dnnell33
4::u||8\8\--a0DJJ4D4DQ4GGIwx 9]3r   c                b    [        U R                  [        5      (       a  U R                  S   $ S$ )z The keypoints from the `points`.r   Nr    r<   r!   rB   s    r   r@   Prompts.keypointsz   '     ",DKK!?!?t{{1~ITIr   c                b    [        U R                  [        5      (       a  U R                  S   $ S$ )z'The keypoints labels from the `points`.r   NrF   rB   s    r   keypoints_labelsPrompts.keypoints_labels   rH   r   r8   )r-   None)r-   r   )r0   r1   r2   r3   r4   r<   r5   r=   r>   rC   r6   r@   rJ   r7   r8   r   r   r:   r:   f   s\     ;?F7>$(E!($(E!(y J J J Jr   r:   )
__future__r   dataclassesr   typingr   r)   kornia.core.checkr   kornia.geometry.transformr   r	   r:   r8   r   r   <module>rR      sR   $ # !   * , E E EP J J Jr   