a
    áñh   ã                	   @   s†   d dl Z d dl mZmZ d dlmZ d dlmZmZ d dlm	Z	 ddl
mZmZ deeee eeeedœdd„ZG dd„ dejƒZdS )é    N)ÚnnÚTensor)Ú_pair)ÚListÚBroadcastingList2)Ú_assert_has_opsé   )Úconvert_boxes_to_roi_formatÚcheck_roi_boxes_shapeç      ð?éÿÿÿÿF)ÚinputÚboxesÚoutput_sizeÚspatial_scaleÚsampling_ratioÚalignedÚreturnc              	   C   sP   t ƒ  t|ƒ |}t|ƒ}t|tjƒs.t|ƒ}tjj 	| |||d |d ||¡S )a¿  
    Performs Region of Interest (RoI) Align operator described in Mask R-CNN

    Arguments:
        input (Tensor[N, C, H, W]): input tensor
        boxes (Tensor[K, 5] or List[Tensor[L, 4]]): the box coordinates in (x1, y1, x2, y2)
            format where the regions will be taken from. If a single Tensor is passed,
            then the first column should contain the batch index. If a list of Tensors
            is passed, then each Tensor will correspond to the boxes for an element i
            in a batch
        output_size (int or Tuple[int, int]): the size of the output after the cropping
            is performed, as (height, width)
        spatial_scale (float): a scaling factor that maps the input coordinates to
            the box coordinates. Default: 1.0
        sampling_ratio (int): number of sampling points in the interpolation grid
            used to compute the output value of each pooled output bin. If > 0,
            then exactly sampling_ratio x sampling_ratio grid points are used. If
            <= 0, then an adaptive number of grid points are used (computed as
            ceil(roi_width / pooled_w), and likewise for height). Default: -1
        aligned (bool): If False, use the legacy implementation.
            If True, pixel shift it by -0.5 for align more perfectly about two neighboring pixel indices.
            This version in Detectron2

    Returns:
        output (Tensor[K, C, output_size[0], output_size[1]])
    r   r   )
r   r
   r   Ú
isinstanceÚtorchr   r	   ÚopsZtorchvisionÚ	roi_align)r   r   r   r   r   r   Úrois© r   úY/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torchvision/ops/roi_align.pyr      s    "þr   c                       sR   e Zd ZdZdee eeedœ‡ fdd„Ze	e	e	dœdd„Z
ed	œd
d„Z‡  ZS )ÚRoIAlignz
    See roi_align
    F)r   r   r   r   c                    s*   t t| ƒ ¡  || _|| _|| _|| _d S ©N)Úsuperr   Ú__init__r   r   r   r   )Úselfr   r   r   r   ©Ú	__class__r   r   r   <   s
    zRoIAlign.__init__)r   r   r   c                 C   s   t ||| j| j| j| jƒS r   )r   r   r   r   r   )r   r   r   r   r   r   ÚforwardI   s    zRoIAlign.forward)r   c                 C   s`   | j jd }|dt| jƒ 7 }|dt| jƒ 7 }|dt| jƒ 7 }|dt| jƒ 7 }|d7 }|S )Nú(zoutput_size=z, spatial_scale=z, sampling_ratio=z
, aligned=ú))r!   Ú__name__Ústrr   r   r   r   )r   Ztmpstrr   r   r   Ú__repr__L   s    zRoIAlign.__repr__)F)r%   Ú
__module__Ú__qualname__Ú__doc__r   ÚintÚfloatÚboolr   r   r"   r&   r'   Ú__classcell__r   r   r    r   r   8   s    ûûr   )r   r   F)r   r   r   Ztorch.nn.modules.utilsr   Ztorch.jit.annotationsr   r   Ztorchvision.extensionr   Ú_utilsr	   r
   r+   r,   r-   r   ÚModuler   r   r   r   r   Ú<module>   s$      úù-