o
    )i                     @   sd   d dl Z d dlZd dl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)AnyCallableListOptionalTuple)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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 (string): 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.zipZ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rEt
j| j| j| j}t
|D ]#}	| jt
j||	 | jrm| jt
j||	dd  d qJd S )N)r   r   r   Ztrainingtestingz<Dataset not found. You may use download=True to download it..r   z.txt)super__init__imagestargetsr   r   	_locationr   _check_existsRuntimeErrorospathjoin_raw_folderimage_dir_namelabels_dir_namelistdirappendsplit)
selfr   r   r   r   r   r   Z	image_dirZ
labels_dirZimg_file	__class__ i/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/torchvision/datasets/kitti.pyr   4   s0   	&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   r4   r'   r5   r7   r'   r'   r(   r:   {   r;      c                 S   r4   r'   r5   r7   r'   r'   r(   r:   |   r;      )type	truncatedZoccludedalphaZbbox
dimensionslocationZ
rotation_y)r+   r   csvreaderr"   r6   int)r$   r)   r.   inpcontentliner'   r'   r(   r,   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__rM   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 rK   )r   r   isdirr   r   r   )r8   fnamerM   r'   r(   	<genexpr>   s   * z&Kitti._check_exists.<locals>.<genexpr>)r   r   r"   r    all)r$   foldersr'   rM   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)urlZdownload_rootfilename)r   r   makedirsr   	resourcesr	   data_url)r$   rR   r'   r'   r(   r      s   
zKitti.download)TNNNF)r*   N)rP   
__module____qualname____doc__r[   rZ   r   r    strboolr   r   r   rG   r   r   r/   r   r,   rN   propertyr   r   r   __classcell__r'   r'   r%   r(   r      sB     "r   )rE   r   typingr   r   r   r   r   ZPILr   utilsr	   Zvisionr
   r   r'   r'   r'   r(   <module>   s    