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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ç      ð?)ÚinputÚboxesÚoutput_sizeÚspatial_scaleÚreturnc                 C   sT   t ƒ  t|ƒ |}t|ƒ}t|tjƒs.t|ƒ}tjj 	| |||d |d ¡\}}|S )a[  
    Performs Region of Interest (RoI) Pool operator described in Fast 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

    Returns:
        output (Tensor[K, C, output_size[0], output_size[1]])
    r   r   )
r   r
   r   Ú
isinstanceÚtorchr   r	   ÚopsZtorchvisionÚroi_pool)r   r   r   r   ÚroisÚoutputÚ_© r   úX/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torchvision/ops/roi_pool.pyr      s    ÿr   c                       sL   e Zd ZdZee edœ‡ fdd„Zeeedœdd„Z	e
dœd	d
„Z‡  ZS )ÚRoIPoolz
    See roi_pool
    )r   r   c                    s   t t| ƒ ¡  || _|| _d S ©N)Úsuperr   Ú__init__r   r   )Úselfr   r   ©Ú	__class__r   r   r   2   s    zRoIPool.__init__)r   r   r   c                 C   s   t ||| j| jƒS r   )r   r   r   )r   r   r   r   r   r   Úforward7   s    zRoIPool.forward)r   c                 C   s<   | j jd }|dt| jƒ 7 }|dt| jƒ 7 }|d7 }|S )Nú(zoutput_size=z, spatial_scale=ú))r    Ú__name__Ústrr   r   )r   Ztmpstrr   r   r   Ú__repr__:   s
    zRoIPool.__repr__)r$   Ú
__module__Ú__qualname__Ú__doc__r   ÚintÚfloatr   r   r!   r%   r&   Ú__classcell__r   r   r   r   r   .   s   r   )r   )r   r   r   Ztorch.nn.modules.utilsr   Ztorch.jit.annotationsr   r   Ztorchvision.extensionr   Ú_utilsr	   r
   r*   r+   r   ÚModuler   r   r   r   r   Ú<module>   s    üû#