
    Yh                     z    d dl Z d dlZd dlmZ d dl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Optional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             l/var/www/tools.fuzzalab.pt/emblema-extractor/venv/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*   r1   imagetargets       r/   __getitem__zKitti.__getitem__V   sd    & 
4;u-...2jB##E***d? 	; OOE6::ME6f}r0   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     r/   
<listcomp>z'Kitti._parse_target.<locals>.<listcomp>z   s     = = =aq = = =r0         c                 ,    g | ]}t          |          S r?   r@   rB   s     r/   rE   z'Kitti._parse_target.<locals>.<listcomp>{   s    &D&D&DAuQxx&D&D&Dr0      c                 ,    g | ]}t          |          S r?   r@   rB   s     r/   rE   z'Kitti._parse_target.<locals>.<listcomp>|   s    $C$C$C!U1XX$C$C$Cr0      )type	truncatedoccludedalphabbox
dimensionslocation
rotation_y)r4   r   csvreaderr(   rA   int)r*   r1   r7   inpcontentlines         r/   r5   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    r/   __len__zKitti.__len__   s    4;r0   c                 b    t           j                            | j        | j        j        d          S )Nraw)r!   r"   r#   r   r.   __name__r]   s    r/   r$   zKitti._raw_folder   s!    w||DIt~'>FFFr0   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   )rC   fnamer*   s     r/   	<genexpr>z&Kitti._check_exists.<locals>.<genexpr>   sJ      mm\a27==d.>PU!V!VWWmmmmmmr0   )r%   r   r(   r&   all)r*   folderss   ` r/   r   zKitti._check_exists   sQ    &': 	1NN4/000mmmmelmmmmmmr0   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*   re   s     r/   r   zKitti.download   s      	F
D$t4444 ^ 	 	E(}-e--".    	 	r0   )TNNNF)r2   N)ra   
__module____qualname____doc__rp   ro   r%   r&   r   strr   boolr   r   r   rV   tupler   r8   listr5   r^   propertyr$   r   r   __classcell__)r.   s   @r/   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       r0   r   )rT   r!   pathlibr   typingr   r   r   r   PILr   utilsr
   visionr   r   r?   r0   r/   <module>r      s    



 				       1 1 1 1 1 1 1 1 1 1 1 1       / / / / / / ! ! ! ! ! !R R R R RM R R R R Rr0   