o
    ôj  ã                   @   st   d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZ ddlmZ ddlmZ G dd	„ d	eƒZdS )
é    N)ÚPath)ÚAnyÚCallableÚListÚOptionalÚTupleÚUnion)ÚImageé   )Údownload_and_extract_archive)ÚVisionDatasetc                       sÒ   e Zd ZdZdZddgZdZdZ						d d
ee	e
f dedee dee dee def‡ fdd„Zdedeeef fdd„Zdedefdd„Zdefdd„Zede	fdd„ƒZdefdd„Zd!dd„Z‡  ZS )"ÚKittiuÂ  `KITTI <http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark>`_ Dataset.

    It corresponds to the "left color images of object" dataset, for object detection.

    Args:
        root (str or ``pathlib.Path``): Root directory where images are downloaded to.
            Expects the following folder structure if download=False:

            .. code::

                <root>
                    â””â”€â”€ Kitti
                        â””â”€ raw
                            â”œâ”€â”€ training
                            |   â”œâ”€â”€ image_2
                            |   â””â”€â”€ label_2
                            â””â”€â”€ testing
                                â””â”€â”€ image_2
        train (bool, optional): Use ``train`` split if true, else ``test`` split.
            Defaults to ``train``.
        transform (callable, optional): A function/transform that takes in a PIL image
            and returns a transformed version. E.g, ``transforms.PILToTensor``
        target_transform (callable, optional): A function/transform that takes in the
            target and transforms it.
        transforms (callable, optional): A function/transform that takes input sample
            and its target as entry and returns a transformed version.
        download (bool, optional): If true, downloads the dataset from the internet and
            puts it in root directory. If dataset is already downloaded, it is not
            downloaded again.

    z0https://s3.eu-central-1.amazonaws.com/avg-kitti/zdata_object_image_2.zipzdata_object_label_2.zipÚimage_2Zlabel_2TNFÚrootÚtrainÚ	transformÚtarget_transformÚ
transformsÚdownloadc           
   	      sÚ   t ƒ j||||d� g | _g | _|| _| jrdnd| _|r!|  ¡  |  ¡ s)tdƒ‚t	j
 | j| j| j¡}| jrBt	j
 | j| j| j¡}t	 |¡D ]#}	| j t	j
 ||	¡¡ | jrj| j t	j
 ||	 d¡d › d�¡¡ qGd S )N)r   r   r   ÚtrainingÚtestingz<Dataset not found. You may use download=True to download it.Ú.r   z.txt)ÚsuperÚ__init__ÚimagesÚtargetsr   Ú	_locationr   Ú_check_existsÚRuntimeErrorÚosÚpathÚjoinÚ_raw_folderÚimage_dir_nameÚlabels_dir_nameÚlistdirÚappendÚsplit)
Úselfr   r   r   r   r   r   Ú	image_dirZ
labels_dirÚimg_file©Ú	__class__© úk/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchvision/datasets/kitti.pyr   5   s.   	ü&€ýzKitti.__init__ÚindexÚreturnc                 C   sB   t  | j| ¡}| jr|  |¡nd}| jr|  ||¡\}}||fS )aÄ  Get item at a given index.

        Args:
            index (int): Index
        Returns:
            tuple: (image, target), where
            target is a list of dictionaries with the following keys:

            - type: str
            - truncated: float
            - occluded: int
            - alpha: float
            - bbox: float[4]
            - dimensions: float[3]
            - locations: float[3]
            - rotation_y: float

        N)r	   Úopenr   r   Ú_parse_targetr   )r(   r/   ÚimageÚtargetr-   r-   r.   Ú__getitem__V   s
   zKitti.__getitem__c                 C   sÆ   g }t | j| ƒ�P}tj|dd�}|D ]=}| |d t|d ƒt|d ƒt|d ƒdd„ |d	d
… D ƒdd„ |d
d… D ƒdd„ |dd… D ƒt|d ƒdœ¡ qW d   ƒ |S 1 s\w   Y  |S )Nú )Ú	delimiterr   r
   é   é   c                 S   ó   g | ]}t |ƒ‘qS r-   ©Úfloat©Ú.0Úxr-   r-   r.   Ú
<listcomp>z   ó    z'Kitti._parse_target.<locals>.<listcomp>é   é   c                 S   r:   r-   r;   r=   r-   r-   r.   r@   {   rA   é   c                 S   r:   r-   r;   r=   r-   r-   r.   r@   |   rA   é   )ÚtypeÚ	truncatedZoccludedÚalphaÚbboxÚ
dimensionsÚlocationZ
rotation_y)r1   r   ÚcsvÚreaderr&   r<   Úint)r(   r/   r4   ÚinpÚcontentÚliner-   r-   r.   r2   o   s(   



øÿÿ
þñzKitti._parse_targetc                 C   s
   t | jƒS ©N)Úlenr   ©r(   r-   r-   r.   Ú__len__‚   s   
zKitti.__len__c                 C   s   t j | j| jjd¡S )NÚraw)r   r    r!   r   r,   Ú__name__rT   r-   r-   r.   r"   …   s   zKitti._raw_folderc                    s0   ˆ j g}ˆ jr| ˆ j¡ t‡ fdd„|D ƒƒS )z#Check if the data directory exists.c                 3   s,   � | ]}t j t j ˆ jˆ j|¡¡V  qd S rR   )r   r    Úisdirr!   r"   r   )r>   ÚfnamerT   r-   r.   Ú	<genexpr>Ž   s   €* z&Kitti._check_exists.<locals>.<genexpr>)r#   r   r&   r$   Úall)r(   Úfoldersr-   rT   r.   r   ‰   s   zKitti._check_existsc                 C   sF   |   ¡ rdS tj| jdd� | jD ]}t| j› |› �| j|d� qdS )z4Download the KITTI data if it doesn't exist already.NT)Úexist_ok)ÚurlÚdownload_rootÚfilename)r   r   Úmakedirsr"   Ú	resourcesr   Údata_url)r(   rY   r-   r-   r.   r   �   s   
ýÿzKitti.download)TNNNF)r0   N)rW   Ú
__module__Ú__qualname__Ú__doc__rc   rb   r#   r$   r   Ústrr   Úboolr   r   r   rN   r   r   r5   r   r2   rU   Úpropertyr"   r   r   Ú__classcell__r-   r-   r+   r.   r      sB     þù
þýüûúù!r   )rL   r   Úpathlibr   Útypingr   r   r   r   r   r   ÚPILr	   Úutilsr   Úvisionr   r   r-   r-   r-   r.   Ú<module>   s     