
    ڧg                         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	e          ZdS )
    N)Path)AnyCallableListOptionalTupleUnion)Image   )download_and_extract_archive)VisionDatasetc                        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Zdedeeef         fdZdedefdZdefdZede	fd            ZdefdZddZ x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_2label_2TNFroottrain	transformtarget_transform
transformsdownloadc           	      0   t                                          ||||           g | _        g | _        || _        | j        rdnd| _        |r|                                  |                                 st          d          t          j
                            | j        | j        | j                  }| j        r0t          j
                            | j        | j        | j                  }t          j        |          D ]}	| j                            t          j
                            ||	                     | j        rT| j                            t          j
                            ||	                    d          d          d                     d 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_dir
labels_dirimg_file	__class__s             V/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/kitti.pyr   zKitti.__init__5   sw    	-!	 	 	
 	
 	
 
'+z@y 	MMOOO!!## 	_]^^^GLL!14>4CVWW	: 	^d&6H\]]J
9-- 	_ 	_HKrw||Ix@@AAAz _##BGLLs@S@STU@V=\=\=\$]$]^^^	_ 	_    indexreturnc                     t          j        | 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,   r3   imagetargets       r1   __getitem__zKitti.__getitem__V   sd    & 
4;u-...2jB##E***d? 	; OOE6::ME6f}r2   c                    g }t          | j        |                   5 }t          j        |d          }|D ]}|                    |d         t          |d                   t          |d                   t          |d                   d |dd	         D             d
 |d	d         D             d |dd         D             t          |d                   d           	 d d d            n# 1 swxY w Y   |S )N )	delimiterr   r         c                 ,    g | ]}t          |          S  float.0xs     r1   
<listcomp>z'Kitti._parse_target.<locals>.<listcomp>z   s     = = =aq = = =r2         c                 ,    g | ]}t          |          S rA   rB   rD   s     r1   rG   z'Kitti._parse_target.<locals>.<listcomp>{   s    &D&D&DAuQxx&D&D&Dr2      c                 ,    g | ]}t          |          S rA   rB   rD   s     r1   rG   z'Kitti._parse_target.<locals>.<listcomp>|   s    $C$C$C!U1XX$C$C$Cr2      )type	truncatedoccludedalphabbox
dimensionslocation
rotation_y)r6   r   csvreaderr*   rC   int)r,   r3   r9   inpcontentlines         r1   r7   zKitti._parse_targeto   sH   $,u%&& 	#j444G   $Q%*47^^$'QLL!&tAw = =4!9 = = =&D&Dad&D&D&D$C$CtBrE{$C$C$C&+DHoo	 	   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s   CC,,C03C0c                 *    t          | j                  S N)lenr   r,   s    r1   __len__zKitti.__len__   s    4;r2   c                 b    t           j                            | j        | j        j        d          S )Nraw)r#   r$   r%   r   r0   __name__r_   s    r1   r&   zKitti._raw_folder   s!    w||DIt~'>FFFr2   c                       j         g} j        r|                     j                   t	           fd|D                       S )z#Check if the data directory exists.c              3      K   | ]L}t           j                            t           j                            j        j        |                    V  Md S r]   )r#   r$   isdirr%   r&   r    )rE   fnamer,   s     r1   	<genexpr>z&Kitti._check_exists.<locals>.<genexpr>   sJ      mm\a27==d.>PU!V!VWWmmmmmmr2   )r'   r   r*   r(   all)r,   folderss   ` r1   r!   zKitti._check_exists   sQ    &': 	1NN4/000mmmmelmmmmmmr2   c                     |                                  rdS t          j        | j        d           | j        D ]"}t          | j         | | j        |           #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,   rg   s     r1   r   zKitti.download   s      	F
D$t4444 ^ 	 	E(}-e--".    	 	r2   )TNNNF)r4   N)rc   
__module____qualname____doc__rr   rq   r'   r(   r	   strr   boolr   r   r   rX   r   r   r:   r   r7   r`   propertyr&   r!   r   __classcell__)r0   s   @r1   r   r      s        @ BH!!I NO
 (,/3)-_ _CI_ _ H%	_
 #8,_ X&_ _ _ _ _ _ _B sCx    23 4    &          GS G G G XGnt n n n n       r2   r   )rV   r#   pathlibr   typingr   r   r   r   r   r	   PILr
   utilsr   visionr   r   rA   r2   r1   <module>r      s    



 				       > > > > > > > > > > > > > > > >       / / / / / / ! ! ! ! ! !R R R R RM R R R R Rr2   