§
    ù²Åj”  ã                   ój   — 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e¦  «        ZdS )	é    N)ÚAnyÚCallableÚOptionalÚTupleÚUnion)ÚImageé   )Úverify_str_arg)ÚVisionDatasetc                   ó¶   ‡ — e Zd ZdZ	 	 	 	 ddeeej        f         dedee	         dee	         d	e
d
dfˆ fd„Zd
efd„Zded
eeef         fd„Zd
e
fd„Zd„ Zˆ xZS )ÚStanfordCarsa™  Stanford Cars  Dataset

    The Cars dataset contains 16,185 images of 196 classes of cars. The data is
    split into 8,144 training images and 8,041 testing images, where each class
    has been split roughly in a 50-50 split

    The original URL is https://ai.stanford.edu/~jkrause/cars/car_dataset.html, but it is broken.
    Follow the instructions in ``download`` argument to obtain and use the dataset offline.

    .. note::

        This class needs `scipy <https://docs.scipy.org/doc/>`_ to load target files from `.mat` format.

    Args:
        root (str or ``pathlib.Path``): Root directory of dataset
        split (string, optional): The dataset split, supports ``"train"`` (default) or ``"test"``.
        transform (callable, optional): A function/transform that takes in a PIL image
            and returns a transformed version. E.g, ``transforms.RandomCrop``
        target_transform (callable, optional): A function/transform that takes in the
            target and transforms it.
        download (bool, optional): This parameter exists for backward compatibility but it does not
            download the dataset, since the original URL is not available anymore. The dataset
            seems to be available on Kaggle so you can try to manually download and configure it using
            `these instructions <https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616>`_,
            or use an integrated
            `dataset on Kaggle <https://github.com/pytorch/vision/issues/7545#issuecomment-2282674373>`_.
            In both cases, first download and configure the dataset locally, and use the dataset with
            ``"download=False"``.
    ÚtrainNFÚrootÚsplitÚ	transformÚtarget_transformÚdownloadÚreturnc                 ó@  •‡ — 	 dd l m} n# t          $ r t          d¦  «        ‚w xY wt	          ¦   «                              |||¬¦  «         t          |dd¦  «        ‰ _        t          j	        |¦  «        dz  ‰ _
        ‰ j
        dz  }‰ j        dk    r|d	z  ‰ _        ‰ j
        d
z  ‰ _        n‰ j
        dz  ‰ _        ‰ j
        dz  ‰ _        |r‰                      ¦   «          ‰                      ¦   «         st          d¦  «        ‚ˆ fd„|                     ‰ j        d¬¦  «        d         D ¦   «         ‰ _        |                     t#          |dz  ¦  «        d¬¦  «        d                              ¦   «         ‰ _        d„ t)          ‰ j        ¦  «        D ¦   «         ‰ _        d S )Nr   zQScipy is not found. This dataset needs to have scipy installed: pip install scipy)r   r   r   )r   ÚtestÚstanford_carsÚdevkitr   zcars_train_annos.matÚ
cars_trainzcars_test_annos_withlabels.matÚ	cars_testz�Dataset not found. Try to manually download following the instructions in https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616.c                 ó`   •— g | ]*}t          ‰j        |d          z  ¦  «        |d         dz
  f‘Œ+S )ÚfnameÚclassr	   )ÚstrÚ_images_base_path)Ú.0Ú
annotationÚselfs     €úSC:\Projects\Historical\venv\Lib\site-packages\torchvision/datasets/stanford_cars.pyú
<listcomp>z)StanfordCars.__init__.<locals>.<listcomp>M   sR   ø€ ð 
ð 
ð 
ð
 õ �DÔ*¨Z¸Ô-@Ñ@ÑAÔAØ˜7Ô# aÑ'ðð
ð 
ð 
ó    T)Ú
squeeze_meÚannotationszcars_meta.matÚclass_namesc                 ó   — i | ]\  }}||“Œ	S © r*   )r    ÚiÚclss      r#   ú
<dictcomp>z)StanfordCars.__init__.<locals>.<dictcomp>V   s   € ÐJÐJÐJ©¨¨3˜S !ÐJÐJÐJr%   )Úscipy.ioÚioÚImportErrorÚRuntimeErrorÚsuperÚ__init__r
   Ú_splitÚpathlibÚPathÚ_base_folderÚ_annotations_mat_pathr   r   Ú_check_existsÚloadmatÚ_samplesr   ÚtolistÚclassesÚ	enumerateÚclass_to_idx)	r"   r   r   r   r   r   Úsior   Ú	__class__s	   `       €r#   r3   zStanfordCars.__init__)   sÛ  øø€ ð	tØ"Ð"Ð"Ð"Ð"Ð"Ð"øÝð 	tð 	tð 	tÝÐrÑsÔsÐsð	tøøøõ 	‰Œ×Ò˜¨ÐEUÐÑVÔVÐVå$ U¨GÐ5FÑGÔGˆŒÝ#œL¨Ñ.Ô.°Ñ@ˆÔØÔ" XÑ-ˆàŒ;˜'Ò!Ð!Ø)/Ð2HÑ)HˆDÔ&Ø%)Ô%6¸Ñ%EˆDÔ"Ð"à)-Ô):Ð=]Ñ)]ˆDÔ&Ø%)Ô%6¸Ñ%DˆDÔ"àð 	Ø�MŠM‰OŒOˆOà×!Ò!Ñ#Ô#ð 	ÝðYñô ð ð

ð 
ð 
ð 
ð
 "Ÿkšk¨$Ô*DÐQU˜kÑVÔVÐWdÔeð
ñ 
ô 
ˆŒð —{’{¥3 v°Ñ'?Ñ#@Ô#@ÈT�{ÑRÔRÐS`Ôa×hÒhÑjÔjˆŒØJÐJµ)¸D¼LÑ2IÔ2IÐJÑJÔJˆÔÐÐs   „ ‹%c                 ó*   — t          | j        ¦  «        S )N)Úlenr;   ©r"   s    r#   Ú__len__zStanfordCars.__len__X   s   € Ý�4”=Ñ!Ô!Ð!r%   Úidxc                 óè   — | j         |         \  }}t          j        |¦  «                             d¦  «        }| j        �|                      |¦  «        }| j        �|                      |¦  «        }||fS )z.Returns pil_image and class_id for given indexÚRGB)r;   r   ÚopenÚconvertr   r   )r"   rF   Ú
image_pathÚtargetÚ	pil_images        r#   Ú__getitem__zStanfordCars.__getitem__[   sp   € à!œ]¨3Ô/Ñˆ
�FÝ”J˜zÑ*Ô*×2Ò2°5Ñ9Ô9ˆ	àŒ>Ð%ØŸš yÑ1Ô1ˆIØÔ Ð,Ø×*Ò*¨6Ñ2Ô2ˆFØ˜&Ð Ð r%   c                 ó¢   — | j         dz                       ¦   «         sdS | j                             ¦   «         o| j                             ¦   «         S )Nr   F)r7   Úis_dirr8   Úexistsr   rD   s    r#   r9   zStanfordCars._check_existsf   sL   € ØÔ! HÑ,×4Ò4Ñ6Ô6ð 	Ø�5àÔ)×0Ò0Ñ2Ô2ÐV°tÔ7M×7TÒ7TÑ7VÔ7VÐVr%   c                 ó    — t          d¦  «        ‚)Na  The original URL is broken so the StanfordCars dataset is not available for automatic download anymore. You can try to download it manually following https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616, and set download=False to avoid this error.)Ú
ValueErrorrD   s    r#   r   zStanfordCars.downloadl   s   € Ýð:ñ
ô 
ð 	
r%   )r   NNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r5   r6   r   r   Úboolr3   ÚintrE   r   r   rN   r9   r   Ú__classcell__)rA   s   @r#   r   r   
   s-  ø€ € € € € ðð ðB Ø(,Ø/3Øð-Kð -Kà�C˜œÐ%Ô&ð-Kð ð-Kð ˜HÔ%ð	-Kð
 # 8Ô,ð-Kð ð-Kð 
ð-Kð -Kð -Kð -Kð -Kð -Kð^"˜ð "ð "ð "ð "ð	!˜sð 	! u¨S°#¨X¤ð 	!ð 	!ð 	!ð 	!ðW˜tð Wð Wð Wð Wð
ð 
ð 
ð 
ð 
ð 
ð 
r%   r   )r5   Útypingr   r   r   r   r   ÚPILr   Úutilsr
   Úvisionr   r   r*   r%   r#   ú<module>r_      s¬   ðØ €€€Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8à Ð Ð Ð Ð Ð à !Ð !Ð !Ð !Ð !Ð !Ø !Ð !Ð !Ð !Ð !Ð !ðh
ð h
ð h
ð h
ð h
�=ñ h
ô h
ð h
ð h
ð h
r%   