
    ڧg                     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.

    .. 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 it using
            `these instructions <https://github.com/pytorch/vision/issues/7545#issuecomment-1631441616>`_.
    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_testzDataset 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     ^/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/stanford_cars.py
<listcomp>z)StanfordCars.__init__.<locals>.<listcomp>H   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>Q   s    JJJ3S!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$UG5FGG#L..@"X-;'!!)/2H)HD&%)%6%ED"")-):=])]D&%)%6%DD" 	MMOOO!!## 	Y  

 
 
 

 "kk$*DQUkVVWde
 
 
 {{3v'?#@#@T{RRS`ahhjjJJ)DL2I2IJJJs    %c                 *    t          | j                  S )N)lenr;   r"   s    r#   __len__zStanfordCars.__len__S   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__V   sp    !]3/
FJz**22599	>%y11I ,**622F&  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_existsa   sL    !H,4466 	5)0022Vt7M7T7T7V7V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.downloadg   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,        8 (,/3-K -KC%&-K -K H%	-K
 #8,-K -K 
-K -K -K -K -K -K^" " " " "	!s 	!uS#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       ! ! ! ! ! ! ! ! ! ! ! !c
 c
 c
 c
 c
= c
 c
 c
 c
 c
r%   