
    kh                     b    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y)	    N)AnyCallableOptionalTupleUnion   )default_loader)verify_str_arg)VisionDatasetc                        e Zd ZdZddddefdeeej                  f   dede	e
   de	e
   d	ed
e
egef   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,
    the dataset isn't available online anymore.

    .. 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 or torch.Tensor, depends on the given loader,
            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.
        loader (callable, optional): A function to load an image given its path.
            By default, it uses PIL as its image loader, but users could also pass in
            ``torchvision.io.decode_image`` for decoding image data into tensors directly.
    trainNFrootsplit	transformtarget_transformdownloadloaderreturnc                 |   	 dd l m} 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| j                          | j                         st        d      |j                  | j                  d      d   D 	cg c]%  }	t!        | j                  |	d   z        |	d   dz
  f' c}	| _        |j                  t!        |dz        d      d   j%                         | _        t)        | j&                        D 
ci c]  \  }
}||

 c}}
| _        || _        y # t        $ r t        d      w xY wc c}	w c c}}
w )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.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_idxr   )selfr   r   r   r   r   r   sior   
annotationicls	__class__s               ^/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/datasets/stanford_cars.pyr&   zStanfordCars.__init__&   s   	t" 	EUV$UG5FG#LL.@""X-;;'!)/2H)HD&%)%6%6%ED")-):):=])]D&%)%6%6%DD"MMO!!#344 "kk$*D*DQUkVWde

  D**Z-@@A7#a'
 {{3v'?#@T{RS`ahhj2;DLL2IJ3S!VJA  	trss	t,
 Ks   F >*F3=F8F0c                 ,    t        | j                        S )N)lenr0   r5   s    r;   __len__zStanfordCars.__len__T   s    4==!!    idxc                     | j                   |   \  }}| j                  |      }| j                  | j                  |      }| j                  | j                  |      }||fS )z.Returns pil_image and class_id for given index)r0   r   r   r   )r5   rA   
image_pathtargetimages        r;   __getitem__zStanfordCars.__getitem__W   sa    !]]3/
FJ'>>%NN5)E  ,**62Ff}r@   c                     | j                   dz  j                         sy| j                  j                         xr | j                  j                         S )Nr   F)r*   is_dirr+   existsr,   r>   s    r;   r-   zStanfordCars._check_existsb   sE    !!H,446))002Vt7M7M7T7T7VVr@   c                     t        d      )NzTThe original URL is broken so the StanfordCars dataset cannot be downloaded anymore.)
ValueErrorr>   s    r;   r   zStanfordCars.downloadh   s    oppr@   )__name__
__module____qualname____doc__r	   r   r/   r(   r)   r   r   boolr   r&   intr?   r   rF   r-   r   __classcell__)r:   s   @r;   r   r   
   s    < (,/3'5,C%&, , H%	,
 #8,, , #$, 
,\" "	s 	uS#X 	Wt Wqr@   r   )r(   typingr   r   r   r   r   folderr	   utilsr
   visionr   r    r@   r;   <module>rX      s'     8 8 " ! !_q= _qr@   