
    QЦi"                     b    S SK r S SK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)AnyCallableOptionalTupleUnion)Image   )verify_str_arg)VisionDatasetc                      ^  \ rS rSrSr    SS\\\R                  4   S\S\	\
   S\	\
   S\S	S4U 4S
 jjjrS	\4S jrS\S	\\\4   4S jrS	\4S jrS rSrU =r$ )StanfordCars
   a=  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"``.
Nrootsplit	transformtarget_transformdownloadreturnc                 |  >  SS K Jn  [        TU ]  XUS9  [        USS5      U l        [        R                  " U5      S-  U l
        U R                  S-  nU R                  S:X  a  US	-  U l        U R                  S
-  U l        O(U R                  S-  U l        U R                  S-  U l        U(       a  U R                  5         U R                  5       (       d  [        S5      eUR                  U R                  SS9S    Vs/ s H&  n[!        U R                  US   -  5      US   S-
  4PM(     snU l        UR                  [!        US-  5      SS9S   R%                  5       U l        [)        U R&                  5       V	V
s0 s H  u  pX_M	     sn
n	U l        g ! [         a    [        S5      ef = fs  snf s  sn
n	f )Nr   zQScipy is not found. This dataset needs to have scipy installed: pip install scipy)r   r   r   )train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.T)
squeeze_meannotationsfnameclassr	   zcars_meta.matclass_names)scipy.ioioImportErrorRuntimeErrorsuper__init__r
   _splitpathlibPath_base_folder_annotations_mat_path_images_base_pathr   _check_existsloadmatstr_samplestolistclasses	enumerateclass_to_idx)selfr   r   r   r   r   sior   
annotationicls	__class__s              a/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/stanford_cars.pyr&   StanfordCars.__init__)   s   	t" 	EUV$UG5FG#LL.@""X-;;'!)/2H)HD&%)%6%6%ED")-):):=])]D&%)%6%6%DD"MMO!!##Y  "kk$*D*DQUkVWde

 f
 D**Z-@@A7#a' f
 {{3v'?#@T{RS`ahhj2;DLL2IJ2ISV2IJE  	trss	t2
 Ks   F -F3F8F0c                 ,    [        U R                  5      $ )N)lenr0   r5   s    r;   __len__StanfordCars.__len__X   s    4==!!    idxc                     U R                   U   u  p#[        R                  " U5      R                  S5      nU R                  b  U R	                  U5      nU R
                  b  U R                  U5      nXC4$ )z.Returns pil_image and class_id for given indexRGB)r0   r   openconvertr   r   )r5   rC   
image_pathtarget	pil_images        r;   __getitem__StanfordCars.__getitem__[   si    !]]3/
JJz*2259	>>%y1I  ,**62F  rB   c                     U R                   S-  R                  5       (       d  gU R                  R                  5       =(       a    U R                  R                  5       $ )Nr   F)r*   is_dirr+   existsr,   r?   s    r;   r-   StanfordCars._check_existsf   sH    !!H,4466))002Vt7M7M7T7T7VVrB   c                     [        S5      e)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.)
ValueErrorr?   s    r;   r   StanfordCars.downloadl   s    :
 	
rB   )r+   r*   r,   r0   r'   r4   r2   )r   NNF)__name__
__module____qualname____firstlineno____doc__r   r/   r(   r)   r   r   boolr&   intr@   r   r   rK   r-   r   __static_attributes____classcell__)r:   s   @r;   r   r   
   s    B (,/3-KC%&-K -K H%	-K
 #8,-K -K 
-K -K^" "	!s 	!uS#X 	!Wt W
 
rB   r   )r(   typingr   r   r   r   r   PILr   utilsr
   visionr   r    rB   r;   <module>rb      s%     8 8  ! !h
= h
rB   