Revision 08a8fb349e580560cdc785d0860cc423c288eca8 authored by Changjian Chen on 20 May 2024, 01:45:34 UTC, committed by Changjian Chen on 20 May 2024, 01:45:34 UTC
1 parent 90f314b
box_utils.cpython-36.pyc
3
�L`(% � @ sV d dl Z dd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Zdd� Zdd� Zddd�Z dS )� Nc C s` t j| dd�dd�f | dd�dd�f d | dd�dd�f | dd�dd�f d fd�S )a Convert prior_boxes to (xmin, ymin, xmax, ymax)
representation for comparison to point form ground truth data.
Args:
boxes: (tensor) center-size default boxes from priorbox layers.
Return:
boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes.
N� � )�torch�cat)�boxes� r �//data/changjian/WSL/CSD-SSD/layers/box_utils.py�
point_form s .r c C sZ t j| dd�dd�f | dd�dd�f d | dd�dd�f | dd�dd�f d�S )z� Convert prior_boxes to (cx, cy, w, h)
representation for comparison to center-size form ground truth data.
Args:
boxes: (tensor) point_form boxes
Return:
boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes.
Nr r )r r )r r r r �center_size s .r
c C s� | j d�}|j d�}tj| dd�dd�f jd�j||d�|dd�dd�f jd�j||d��}tj| dd�dd�f jd�j||d�|dd�dd�f jd�j||d��}tj|| dd�}|dd�dd�df |dd�dd�df S )al We resize both tensors to [A,B,2] without new malloc:
[A,2] -> [A,1,2] -> [A,B,2]
[B,2] -> [1,B,2] -> [A,B,2]
Then we compute the area of intersect between box_a and box_b.
Args:
box_a: (tensor) bounding boxes, Shape: [A,4].
box_b: (tensor) bounding boxes, Shape: [B,4].
Return:
(tensor) intersection area, Shape: [A,B].
r Nr r )�min)�sizer r � unsqueeze�expand�max�clamp)�box_a�box_b�A�B�max_xy�min_xy�interr r r � intersect s
&&&&r c C s� t | |�}| dd�df | dd�df | dd�df | dd�df jd�j|�}|dd�df |dd�df |dd�df |dd�df jd�j|�}|| | }|| S )u Compute the jaccard overlap of two sets of boxes. The jaccard overlap
is simply the intersection over union of two boxes. Here we operate on
ground truth boxes and default boxes.
E.g.:
A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B)
Args:
box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4]
box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4]
Return:
jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)]
Nr r � r )r r
� expand_as)r r r �area_a�area_b�unionr r r �jaccard2 s
..r c C s� t |t|��}y|jddd�\} }
W n" ddl}|j� t� Y nX |jddd�\}}
|
jd� |jd� |
jd� | jd� |jd|
d� x"t|
j d��D ]}||
|
| <