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 2b019233d6851facadec8e9215cc805eef47932c authored by Changjian Chen on 20 May 2024, 01:52:04 UTC, committed by Changjian Chen on 20 May 2024, 01:52:04 UTC
update readme
1 parent 08a8fb3
  • Files
  • Changes
  • 5c3066e
  • /
  • backend
  • /
  • data
  • /
  • __pycache__
  • /
  • coco.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:2b019233d6851facadec8e9215cc805eef47932c
directory badge
swh:1:dir:3d1e63d905c7651894c8c68d3b1b329c5b11741f
content badge
swh:1:cnt:ad20bf2731359fcca95e70e626254c8c4d7accc5

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 ...
coco.cpython-36.pyc
3

�L`�P@s�ddlmZddlZddljZddlZddlZddlj	j
Z
ddljZddl
Z
ddlZdZejed�ZdZdZdZd_ZdYdZ�ZGd[d\�d\e�ZGd]d^�d^e
j�ZdS)`�)�HOME�NZannotationszWSL/Data/coco17/annotations�imagesZ	PythonAPIzinstances_{}.json�person�bicycle�car�
motorcycle�airplane�bus�train�truck�boat�
traffic light�fire�hydrant�	stop sign�
parking meter�bench�bird�cat�dog�horse�sheep�cow�elephant�bear�zebra�giraffe�backpack�umbrella�handbag�tie�suitcase�frisbee�skis�	snowboard�sports ball�kite�baseball bat�baseball glove�
skateboard�	surfboard�
tennis racket�bottle�
wine glass�cup�fork�knife�spoon�bowl�banana�apple�sandwich�orange�broccoli�carrot�hot dog�pizza�donut�cake�chair�couch�potted plant�bed�dining table�toilet�tv�laptop�mouse�remote�keyboard�
cell phone�microwave oven�toaster�sink�refrigerator�book�clock�vase�scissors�
teddy bear�
hair drier�
toothbrushcCsBi}t|d�}x.|D]&}|jd�}t|d�|t|d�<qW|S)N�r�,rr)�open�split�int)Z
label_file�	label_map�labels�line�ids�r^�(/data/changjian/WSL/CSD-SSD/data/coco.py�
get_label_map!s


r`c@s eZdZdZdd�Zdd�ZdS)�COCOAnnotationTransformz�Transforms a COCO annotation into a Tensor of bbox coords and label index
    Initilized with a dictionary lookup of classnames to indexes
    cCsttjtd��|_dS)Nzcoco_labels.txt)r`�osp�join�	COCO_ROOTrZ)�selfr^r^r_�__init__.sz COCOAnnotationTransform.__init__c
Cs�tj||||g�}g}x�|D]~}d|kr�|d}|d|d7<|d|d7<|j|dd}ttj|�|�}	|	j|�||	g7}qtd�qW|S)a
        Args:
            target (dict): COCO target json annotation as a python dict
            height (int): height
            width (int): width
        Returns:
            a list containing lists of bounding boxes  [bbox coords, class idx]
        �bbox�r�rZcategory_idzno bbox problem!)�np�arrayrZ�list�append�print)
re�target�width�height�scale�res�objrgZ	label_idxZ	final_boxr^r^r_�__call__1s	

z COCOAnnotationTransform.__call__N)�__name__�
__module__�__qualname__�__doc__rfrur^r^r^r_ra*srac@sTeZdZdZdde�dfdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�
COCODetectiona�`MS Coco Detection <http://mscoco.org/dataset/#detections-challenge2016>`_ Dataset.
    Args:
        root (string): Root directory where images are downloaded to.
        set_name (string): Name of the specific set of COCO images.
        transform (callable, optional): A function/transform that augments the
                                        raw images`
        target_transform (callable, optional): A function/transform that takes
        in the target (bbox) and transforms it.
    Ztrainval35kNzMS COCOcCsrtjjtj|t��ddlm}tj|t|�|_	|tj|t
tj|���|_
t|j
jj��|_||_||_||_dS)Nr)�COCO)�sys�pathrmrbrc�COCO_APIZpycocotools.cocor{�IMAGES�root�ANNOTATIONS�
INSTANCES_SET�format�cocorl�	imgToAnns�keysr]�	transform�target_transform�name)rer�Z	image_setr�r�Zdataset_namer{r^r^r_rfVs
zCOCODetection.__init__cCs|j|�\}}}}||fS)z�
        Args:
            index (int): Index
        Returns:
            tuple: Tuple (image, target).
                   target is the object returned by ``coco.loadAnns``.
        )�	pull_item)re�indexZim�gt�h�wr^r^r_�__getitem__bszCOCODetection.__getitem__cCs
t|j�S)N)�lenr])rer^r^r_�__len__mszCOCODetection.__len__cCs.|j|}|jj|}|jj|d�}|jj|�}tj|j|jj|�dd�}tj	|�sft
dj|���tj
tj|j|��}|j\}}}	|jdk	r�|j|||�}|jdk	�rtj|�}|j||dd�dd�f|dd�df�\}}
}|dd�dd�d
f}tj|
tj|dd	�f�}tj|�jddd�|||fS)z�
        Args:
            index (int): Index
        Returns:
            tuple: Tuple (image, target, height, width).
                   target is the object returned by ``coco.loadAnns``.
        )�imgIdsr�	file_namezImage path does not exist: {}N�rhr)Zaxis)rhrr)r]r�r��	getAnnIds�loadAnnsrbrcr��loadImgs�exists�AssertionErrorr��cv2�imread�shaper�r�rjrkZhstackZexpand_dims�torchZ
from_numpyZpermute)rer��img_idro�ann_idsr}Zimgrqrp�_�boxesr[r^r^r_r�ps"


zCOCODetection.pull_itemcCs6|j|}|jj|�dd}tjtj|j|�tj�S)aReturns the original image object at index in PIL form

        Note: not using self.__getitem__(), as any transformations passed in
        could mess up this functionality.

        Argument:
            index (int): index of img to show
        Return:
            cv2 img
        rr�)	r]r�r�r�r�rbrcr�ZIMREAD_COLOR)rer�r�r}r^r^r_�
pull_image�s
zCOCODetection.pull_imagecCs$|j|}|jj|d�}|jj|�S)a�Returns the original annotation of image at index

        Note: not using self.__getitem__(), as any transformations passed in
        could mess up this functionality.

        Argument:
            index (int): index of img to get annotation of
        Return:
            list:  [img_id, [(label, bbox coords),...]]
                eg: ('001718', [('dog', (96, 13, 438, 332))])
        )r�)r]r�r�r�)rer�r�r�r^r^r_�	pull_anno�s
zCOCODetection.pull_annoc	Cs�d|jjd}|dj|j��7}|dj|j�7}d}|dj||jj�jdddt|���7}d}|d	j||j	j�jdddt|���7}|S)
NzDataset �
z    Number of datapoints: {}
z    Root Location: {}
z    Transforms (if any): z{0}{1}
� z     Target Transforms (if any): z{0}{1})
�	__class__rvr�r�r�r��__repr__�replacer�r�)reZfmt_strZtmpr^r^r_r��s**zCOCODetection.__repr__)rvrwrxryrarfr�r�r�r�r�r�r^r^r^r_rzKs	rz)Prrrrr	r
rrr
rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrT)�configr�osZos.pathr}rbr|r��torch.utils.data�utils�dataZtorchvision.transformsZ
transformsr��numpyrjr�rcrdrr~r��COCO_CLASSESr`�objectraZDatasetrzr^r^r^r_�<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–2025, 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