
    QЦi                     z    S SK r S SKrS SKJr  S SKJrJrJrJrJ	r	J
r
  S SKJr  SSKJr  SSKJr   " S S	\5      rg)
    N)Path)AnyCallableListOptionalTupleUnion)Image   )download_and_extract_archive)VisionDatasetc                      ^  \ rS rSrSrSrSS/rSrSr     SS\	\
\4   S	\S
\\   S\\   S\\   S\4U 4S jjjrS\S\\\4   4S jrS\S\4S jrS\4S jr\S\
4S j5       rS\4S jrSS jrSrU =r$ )Kitti   u^  `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_2roottrain	transformtarget_transform
transformsdownloadc           	      z  > [         T
U ]  UUUUS9  / U l        / U l        X l        U R                  (       a  SOSU l        U(       a  U R                  5         U R                  5       (       d  [        S5      e[        R                  R                  U R                  U R
                  U R                  5      nU R                  (       a?  [        R                  R                  U R                  U R
                  U R                  5      n[        R                  " U5       H  n	U R                  R!                  [        R                  R                  Xy5      5        U R                  (       d  MN  U R                  R!                  [        R                  R                  WU	R#                  S5      S    S35      5        M     g )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             Y/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/kitti.pyr   Kitti.__init__5   s5    	-!	 	 	
 
'+zzyMMO!!##]^^GGLL!1!14>>4CVCVW	::d&6&6H\H\]J

9-HKKrww||I@Azzz##BGGLLs@STU@V?WW[=\$]^ .    indexreturnc                     [         R                  " U R                  U   5      nU R                  (       a  U R	                  U5      OSnU R
                  (       a  U R                  X#5      u  p#X#4$ )aT  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-   r5   imagetargets       r2   __getitem__Kitti.__getitem__V   sR    & 

4;;u-..2jj##E*d?? OOE:ME}r4   c                    / n[        U R                  U   5       n[        R                  " USS9nU H  nUR	                  US   [        US   5      [        US   5      [        US   5      USS  Vs/ s H  n[        U5      PM     snUSS	  Vs/ s H  n[        U5      PM     snUS	S
  Vs/ s H  n[        U5      PM     sn[        US
   5      S.5        M     S S S 5        U$ s  snf s  snf s  snf ! , (       d  f       U$ = f)N )	delimiterr   r                     )type	truncatedoccludedalphabbox
dimensionslocation
rotation_y)r8   r    csvreaderr+   floatint)r-   r5   r;   inpcontentlinexs          r2   r9   Kitti._parse_targeto   s    $,,u%&#jj4G $Q%*47^$'QL!&tAw37!9 =9aq9 =9=a&DAuQx&D7;Br{$C{!U1X{$C&+DHo	   '  !>&D$C '& s6   AC73C(	C7C-&	C7/C2C7(C77
Dc                 ,    [        U R                  5      $ N)lenr   r-   s    r2   __len__Kitti.__len__   s    4;;r4   c                     [         R                  R                  U R                  U R                  R
                  S5      $ )Nraw)r$   r%   r&   r   r1   __name__r[   s    r2   r'   Kitti._raw_folder   s'    ww||DIIt~~'>'>FFr4   c                    ^  T R                   /nT R                  (       a  UR                  T R                  5        [	        U 4S jU 5       5      $ )z#Check if the data directory exists.c              3      >#    U  HW  n[         R                  R                  [         R                  R                  TR                  TR
                  U5      5      v   MY     g 7frY   )r$   r%   isdirr&   r'   r!   ).0fnamer-   s     r2   	<genexpr>&Kitti._check_exists.<locals>.<genexpr>   s@     mel\a277==d.>.>PU!VWWels   AA")r(   r   r+   r)   all)r-   folderss   ` r2   r"   Kitti._check_exists   s<    &&'::NN4//0melmmmr4   c                     U R                  5       (       a  g[        R                  " U R                  SS9  U R                   H&  n[        U R                   U 3U R                  US9  M(     g)z4Download the KITTI data if it doesn't exist already.NT)exist_ok)urldownload_rootfilename)r"   r$   makedirsr'   	resourcesr   data_url)r-   rf   s     r2   r   Kitti.download   s^     
D$$t4 ^^E(}}oeW-".. $r4   )r!   r   r    r   )TNNNF)r6   N)r`   
__module____qualname____firstlineno____doc__rs   rr   r(   r)   r	   strr   boolr   r   r   rR   r   r   r<   r   r9   r\   propertyr'   r"   r   __static_attributes____classcell__)r1   s   @r2   r   r      s   @ BH!!I NO
 (,/3)-_CI_ _ H%	_
 #8,_ X&_ _ _B sCx 23 4 &    GS G Gnt n r4   r   )rO   r$   pathlibr   typingr   r   r   r   r   r	   PILr
   utilsr   visionr   r    r4   r2   <module>r      s+    
 	  > >  / !RM Rr4   