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__
  • /
  • voc.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:e63392a1bfbdd936395eeefbba0fb3a10a13d7e5

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

�L`�;�@s�dZddlmZddljZddlZddlZddlj	j
Z
ddlZddlZ
ddlZddlmZejddkrvddljjZnddljjZd$Zejed�ZGdd�de�ZGdd�de�ZGd d!�d!e
j�ZGd"d#�d#e
j�Z dS)%z�VOC Dataset Classes

Original author: Francisco Massa
https://github.com/fmassa/vision/blob/voc_dataset/torchvision/datasets/voc.py

Updated by: Ellis Brown, Max deGroot
�)�HOME�N)�logger��	aeroplane�bicycle�bird�boat�bottle�bus�car�cat�chair�cow�diningtable�dog�horse�	motorbike�person�pottedplant�sheep�sofa�train�	tvmonitorzWSL/Data/VOCdevkit/c@s"eZdZdZddd�Zdd�ZdS)	�VOCEvalAnnotationTransforma�Transforms a VOC annotation into a Tensor of bbox coords and label index
    Initilized with a dictionary lookup of classnames to indexes

    Arguments:
        class_to_ind (dict, optional): dictionary lookup of classnames -> indexes
            (default: alphabetic indexing of VOC's 20 classes)
        keep_difficult (bool, optional): keep difficult instances or not
            (default: False)
        height (int): height
        width (int): width
    NFcCs&|ptttttt����|_||_dS)N)�dict�zip�VOC_CLASSES�range�len�class_to_ind�keep_difficult)�selfr r!�r#�'/data/changjian/WSL/CSD-SSD/data/voc.py�__init__.sz#VOCEvalAnnotationTransform.__init__cCs�g}x�|jd�D]�}i}|jd�j|d<|jd�j|d<t|jd�j�|d<t|jd�j�|d<|jd�}t|jd�j�dt|jd	�j�dt|jd
�j�dt|jd�j�dg|d<|j|�qW|S)
z�
        Arguments:
            target (annotation) : the target annotation to be made usable
                will be an ET.Element
        Returns:
            a list containing lists of bounding boxes  [bbox coords, class name]
        �object�nameZposeZ	truncated�	difficult�bndbox�xminr�ymin�xmax�ymax�bbox)�findall�find�text�int�append)r"�target�width�height�objects�obj�
obj_structr.r#r#r$�__call__3s
z#VOCEvalAnnotationTransform.__call__)NF)�__name__�
__module__�__qualname__�__doc__r%r:r#r#r#r$r!s
rc@s"eZdZdZddd�Zdd�ZdS)	�VOCAnnotationTransforma�Transforms a VOC annotation into a Tensor of bbox coords and label index
    Initilized with a dictionary lookup of classnames to indexes

    Arguments:
        class_to_ind (dict, optional): dictionary lookup of classnames -> indexes
            (default: alphabetic indexing of VOC's 20 classes)
        keep_difficult (bool, optional): keep difficult instances or not
            (default: False)
        height (int): height
        width (int): width
    NFcCs&|ptttttt����|_||_dS)N)rrrrrr r!)r"r r!r#r#r$r%WszVOCAnnotationTransform.__init__cCs�g}x�|jd�D]�}t|jd�j�dk}|jr6|r6q|jd�jj�j�}|jd�}dddd	g}	g}
xNt|	�D]B\}}t|j|�j�d}
|d
dkr�|
|n|
|}
|
j|
�qnW|j	|}|
j|�||
g7}qW|S)z�
        Arguments:
            target (annotation) : the target annotation to be made usable
                will be an ET.Element
        Returns:
            a list containing lists of bounding boxes  [bbox coords, class name]
        r&r(rr'r)r*r+r,r-rr)
�iterr2r0r1r!�lower�strip�	enumerater3r )r"r4r5r6�resr8r(r'r.�ptsr)�i�ptZcur_pt�	label_idxr#r#r$r:\s"


zVOCAnnotationTransform.__call__)NF)r;r<r=r>r%r:r#r#r#r$r?Js
r?c@s�eZdZdZed gde�ddddfdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)!�VOCDetectionaRVOC Detection Dataset Object

    input is image, target is annotation

    Arguments:
        root (string): filepath to VOCdevkit folder.
        image_set (string): imageset to use (eg. 'train', 'val', 'test')
        transform (callable, optional): transformation to perform on the
            input image
        target_transform (callable, optional): transformation to perform on the
            target `annotation`
            (eg: take in caption string, return tensor of word indices)
        dataset_name (string, optional): which dataset to load
            (default: 'VOC2007')
    �2007�trainvalN�VOCg�?Fc	Cs�||_||_||_||_|r$t�|_t|_||_tj	ddd�|_
tj	ddd�|_|d\}	}
tj	|jd|	|
d�}|
d	kr�tj|�r�t
d
|�t�|_t|d��F}|j�jd�jd�}
x*|
D]"}|jd
�\}}|jj||f�q�WWdQRXntd��nnt
d�t�|_x\|D]T\}	}
tj	|jd|	�}x6ttj	|dd|
d��D]}|jj||j�f��qDW�qWtt|j�|�|_||_|j|�dS)Nz%s�Annotationsz%s.xml�
JPEGImagesz%s.jpgrrLz_random_list.txtrKzreading from random_list�r�
�	z#you should have randomlist.txt filezreading ids from origin data�	ImageSets�Mainz.txt)�root�	image_set�	transform�target_transformrr�classesr'�osp�join�	_annopath�_imgpath�exists�print�list�_ids�open�readrB�splitr3�
ValueErrorr2r�
supervise_num�supervise_percent�set_only_supervise)r"rT�
image_setsrVrW�dataset_namerf�only_supervise�eval�yearr'Zidlist_file�f�lists�l�a�b�rootpath�liner#r#r$r%�s>


 
 zVOCDetection.__init__cCsF||_|r,tjd�|jd|j�j�|_ntjd�|jj�|_dS)Nzusing supervised onlyz&using both supervised and unsupervised)rjr�infor`re�copy�ids)r"rjr#r#r$rg�s

zVOCDetection.set_only_supervisecCs|jS)N)rX)r"r#r#r$�
get_label_map�szVOCDetection.get_label_mapcCs|jddS)Nrr)rU)r"r#r#r$�get_set_type�szVOCDetection.get_set_typecCs|rt�|_dS)N)rrW)r"rkr#r#r$�set_eval�szVOCDetection.set_evalcCs&|j|�\}}}}}||||j|�fS)N)�	pull_item�pull_image_level_anno)r"�index�im�gt�h�w�semir#r#r$�__getitem__�szVOCDetection.__getitem__cCs
t|j�S)N)rrv)r"r#r#r$�__len__�szVOCDetection.__len__cCs|j|}tj|j|�j�}tj|j|�}|j\}}}|j	dk	rR|j	|||�}|j
dk	r�tj|�}|j
||dd�dd�f|dd�df�\}}}	|dd�dd�df}tj
|tj|	dd�f�}||jkr�tjdg�}
ntjdg�}
tj|�jddd�||||
fS)N�rrr)�axis)rrr)rv�ET�parser[�getroot�cv2�imreadr\�shaperWrV�np�array�hstack�expand_dimsre�torch�
from_numpy�permute)r"r|�img_idr4�imgr6r5�channels�boxes�labelsr�r#r#r$rz�s



0
zVOCDetection.pull_itemcCs|j|}tj|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:
            PIL img
        )rvr�r�r\�IMREAD_COLOR)r"r|r�r#r#r$�
pull_image�s
zVOCDetection.pull_imagecCs8|j|}tj|j|�j�}|j|dd�}|d|fS)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)rvr�r�r[r�rW)r"r|r��annor~r#r#r$�	pull_annos
zVOCDetection.pull_annocCs:|j|�\}}d}tj|�}x|D]}d||d<q"W|S)N�r�����)r�r��zeros)r"r|r�r~�cat_numr��gr#r#r$r{s

z"VOCDetection.pull_image_level_annocCstj|j|��jd�S)a7Returns the original image at an index in tensor 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:
            tensorized version of img, squeezed
        r)r��Tensorr��
unsqueeze_)r"r|r#r#r$�pull_tensor"szVOCDetection.pull_tensor)rJrK)r;r<r=r>�VOC_ROOTr?r%rgrwrxryr�r�rzr�r�r{r�r#r#r#r$rI{s"2		rIc@sVeZdZdZdgde�dfdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)�VOC0712DetectionaRVOC Detection Dataset Object

    input is image, target is annotation

    Arguments:
        root (string): filepath to VOCdevkit folder.
        image_set (string): imageset to use (eg. 'train', 'val', 'test')
        transform (callable, optional): transformation to perform on the
            input image
        target_transform (callable, optional): transformation to perform on the
            target `annotation`
            (eg: take in caption string, return tensor of word indices)
        dataset_name (string, optional): which dataset to load
            (default: 'VOC2007')
    rJrKNZVOC0712c
Cs�||_||_||_||_||_tjddd�|_tjddd�|_t	�|_
xX|D]P\}}tj|jd|�}x4ttj|dd|d	��D]}	|j
j||	j
�f�q�WqLWdS)
Nz%srMz%s.xmlrNz%s.jpgrLrRrSz.txt)rTrUrVrWr'rYrZr[r\r_rvrar3rB)
r"rTrhrVrWrirlr'rrrsr#r#r$r%CszVOC0712Detection.__init__cCs|j|�\}}}}||fS)N)rz)r"r|r}r~rr�r#r#r$r�TszVOC0712Detection.__getitem__cCs
t|j�S)N)rrv)r"r#r#r$r�YszVOC0712Detection.__len__c
Cs�|j|}tj|j|�j�}tj|j|�}|j\}}}|j	dk	rR|j	|||�}|j
dk	r�tj|�}|j
||dd�dd�f|dd�df�\}}}	|dd�dd�df}tj
|tj|	dd�f�}tj|�jddd�|||fS)Nr�rrr)r�)rrr)rvr�r�r[r�r�r�r\r�rWrVr�r�r�r�r�r�r�)
r"r|r�r4r�r6r5r�r�r�r#r#r$rz\s



0zVOC0712Detection.pull_itemcCs|j|}tj|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:
            PIL img
        )rvr�r�r\r�)r"r|r�r#r#r$r�ps
zVOC0712Detection.pull_imagecCs8|j|}tj|j|�j�}|j|dd�}|d|fS)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)rvr�r�r[r�rW)r"r|r�r�r~r#r#r$r�~s
zVOC0712Detection.pull_annocCstj|j|��jd�S)a7Returns the original image at an index in tensor 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:
            tensorized version of img, squeezed
        r)r�r�r�r�)r"r|r#r#r$r��szVOC0712Detection.pull_tensor)rJrK)r;r<r=r>r?r%r�r�rzr�r�r�r#r#r#r$r�0sr�)rrrr	r
rrr
rrrrrrrrrrrr)!r>�configr�os.path�pathrY�sysr��torch.utils.data�utils�datar��numpyr��random�utils.loggerr�version_infoZxml.etree.cElementTree�etreeZcElementTreer��xml.etree.ElementTree�ElementTreerrZr�r&rr?�DatasetrIr�r#r#r#r$�<module>s.
)16
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