Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

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
update README
1 parent 90f314b
  • Files
  • Changes
  • 5b23d0f
  • /
  • backend
  • /
  • layers
  • /
  • __pycache__
  • /
  • box_utils.cpython-36.pyc
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:08a8fb349e580560cdc785d0860cc423c288eca8
directory badge
swh:1:dir:ecb49258e6d9eec5207770f6fa36e85c12570964
content badge
swh:1:cnt:f9aa22ea8d1943716983ff3ca380e893f19231ba

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
box_utils.cpython-36.pyc
3

�L`(%�@sVddlZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zddd�Z	dS)�NcCs`tj|dd�dd�f|dd�dd�fd|dd�dd�f|dd�dd�fdfd�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_forms.r	cCsZtj|dd�dd�f|dd�dd�fd|dd�dd�f|dd�dd�fd�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.
    Nrr)rr)rrrr�center_sizes.r
cCs�|jd�}|jd�}tj|dd�dd�fjd�j||d�|dd�dd�fjd�j||d��}tj|dd�dd�fjd�j||d�|dd�dd�fjd�j||d��}tj||dd�}|dd�dd�df|dd�dd�dfS)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].
    rNrr)�min)�sizerr�	unsqueeze�expand�max�clamp)�box_a�box_b�A�B�max_xy�min_xy�interrrr�	intersects

&&&&rcCs�t||�}|dd�df|dd�df|dd�df|dd�dfjd�j|�}|dd�df|dd�df|dd�df|dd�dfjd�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)]
    Nrr�r)rr
�	expand_as)rrr�area_a�area_b�unionrrr�jaccard2s
..rcCs�t|t|��}y|jddd�\}	}
Wn"ddl}|j�t�YnX|jddd�\}}
|
jd�|jd�|
jd�|	jd�|jd|
d�x"t|
j	d��D]}||
|
|<q�W||
}||
d}d|||k<t
|||�}|||<|||<dS)a�Match each prior box with the ground truth box of the highest jaccard
    overlap, encode the bounding boxes, then return the matched indices
    corresponding to both confidence and location preds.
    Args:
        threshold: (float) The overlap threshold used when mathing boxes.
        truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors].
        priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4].
        variances: (tensor) Variances corresponding to each prior coord,
            Shape: [num_priors, 4].
        labels: (tensor) All the class labels for the image, Shape: [num_obj].
        loc_t: (tensor) Tensor to be filled w/ endcoded location targets.
        conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds.
        idx: (int) current batch index
    Return:
        The matched indices corresponding to 1)location and 2)confidence preds.
    rT)�keepdimrNr)rr	r�IPythonZembed�exit�squeeze_�index_fill_�ranger�encode)�	thresholdZtruths�priors�	variances�labelsZloc_tZconf_t�idx�overlapsZbest_prior_overlapZbest_prior_idxr Zbest_truth_overlapZbest_truth_idx�j�matches�conf�locrrr�matchGs.




r0cCs�|dd�dd�f|dd�dd�fd|dd�dd�f}||d|dd�dd�f}|dd�dd�f|dd�dd�f|dd�dd�f}tj|�|d}tj||gd�S)a�Encode the variances from the priorbox layers into the ground truth boxes
    we have matched (based on jaccard overlap) with the prior boxes.
    Args:
        matched: (tensor) Coords of ground truth for each prior in point-form
            Shape: [num_priors, 4].
        priors: (tensor) Prior boxes in center-offset form
            Shape: [num_priors,4].
        variances: (list[float]) Variances of priorboxes
    Return:
        encoded boxes (tensor), Shape: [num_priors, 4]
    Nrrr)r�logr)�matchedr'r(Zg_cxcyZg_whrrrr%vs
@ <r%cCs�tj|dd�dd�f|dd�dd�f|d|dd�dd�f|dd�dd�ftj|dd�dd�f|d�fd�}|dd�dd�f|dd�dd�fd8<|dd�dd�f|dd�dd�f7<|S)a�Decode locations from predictions using priors to undo
    the encoding we did for offset regression at train time.
    Args:
        loc (tensor): location predictions for loc layers,
            Shape: [num_priors,4]
        priors (tensor): Prior boxes in center-offset form.
            Shape: [num_priors,4].
        variances: (list[float]) Variances of priorboxes
    Return:
        decoded bounding box predictions
    Nrrr)rr�exp)r/r'r(rrrr�decode�s
B<0,r4cCs.|jj�}tjtjtj||�ddd��|S)z�Utility function for computing log_sum_exp while determining
    This will be used to determine unaveraged confidence loss across
    all examples in a batch.
    Args:
        x (Variable(tensor)): conf_preds from conf layers
    rT)r)�datarrr1�sumr3)�xZx_maxrrr�log_sum_exp�s
r8��?��cCs,|j|jd��j�j�}|j�dkr(|S|dd�df}|dd�df}|dd�df}|dd�df}tj||||�}	|jd�\}
}||d�}|j�}|j�}
|j�}|j�}|j�}|j�}d}�xT|j�dk�r"|d
}|||<|d7}|jd�dk�rP|dd�}tj|d||d�tj|d||
d�tj|d||d�tj|d||d�tj	|||d�}tj	|
||d�}
tj	|||d�}tj	|||d�}|j
|�|j
|�||}||
}tj	|d	d�}tj	|d	d�}||}tj|	d|�}|||	|}||}||j|�}q�W||fS)aApply non-maximum suppression at test time to avoid detecting too many
    overlapping bounding boxes for a given object.
    Args:
        boxes: (tensor) The location preds for the img, Shape: [num_priors,4].
        scores: (tensor) The class predscores for the img, Shape:[num_priors].
        overlap: (float) The overlap thresh for suppressing unnecessary boxes.
        top_k: (int) The Maximum number of box preds to consider.
    Return:
        The indices of the kept boxes with respect to num_priors.
    rNrrr)�out)r)rg�����r<)�newr�zero_�long�numelr�mul�sort�index_selectr�
resize_as_�le)r�scores�overlap�top_k�keep�x1�y1�x2�y2�area�vr*Zxx1Zyy1Zxx2Zyy2�w�h�count�irZ	rem_areasrZIoUrrr�nms�sX

rT)r9r:)
rr	r
rrr0r%r4r8rTrrrr�<module>s/
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API