
    QЦi                     v    S SK r S SKJr  S SKJrJrJrJrJr  S SK	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OptionalTupleUnion)Image   )download_url)VisionDatasetc                      ^  \ rS rSrSr/ SQ/ SQS.r    SS\\\4   S\	S	\
\   S
\
\   S\	SS4U 4S jjjrS\S\\\4   4S jrS\4S jrSrU =r$ )USPS   a  `USPS <https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass.html#usps>`_ Dataset.
The data-format is : [label [index:value ]*256 \n] * num_lines, where ``label`` lies in ``[1, 10]``.
The value for each pixel lies in ``[-1, 1]``. Here we transform the ``label`` into ``[0, 9]``
and make pixel values in ``[0, 255]``.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset to store``USPS`` data files.
    train (bool, optional): If True, creates dataset from ``usps.bz2``,
        otherwise from ``usps.t.bz2``.
    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): If true, downloads the dataset from the internet and
        puts it in root directory. If dataset is already downloaded, it is not
        downloaded again.

)zKhttps://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass/usps.bz2zusps.bz2 ec16c51db3855ca6c91edd34d0e9b197)zMhttps://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass/usps.t.bz2z
usps.t.bz2 8ea070ee2aca1ac39742fdd1ef5ed118)traintestNrootr   	transformtarget_transformdownloadreturnc                   > [         TU ]  XUS9  U(       a  SOSnU R                  U   u  pxn	[        R                  R                  U R                  U5      n
U(       a8  [        R                  R                  U
5      (       d  [        XpR                  XS9  SS K	nUR                  U
5       nUR                  5        Vs/ s H   oR                  5       R                  5       PM"     nnU VVs/ s H*  oSS   Vs/ s H  nUR                  S5      S   PM     snPM,     nnn[        R                  " U[        R                   S	9R#                  S
5      nUS-   S-  S-  R%                  [        R&                  S	9nU Vs/ s H  n[)        US   5      S-
  PM     nnS S S 5        WU l        WU l        g s  snf s  snf s  snnf s  snf ! , (       d  f       N2= f)N)r   r   r   r   )md5r   r
   :)dtype)r      r         )super__init__
split_listospathjoinr   existsr   bz2open	readlinesdecodesplitnpasarrayfloat32reshapeastypeuint8intdatatargets)selfr   r   r   r   r   r,   urlfilenamechecksum	full_pathr(   fplineraw_datar4   xtmp_listimgsdr5   	__class__s                        X/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/usps.pyr"   USPS.__init__-   sm    	EUV f"&//%"8xGGLLH5	BGGNN955ii@XXi B:<,,.I.$++-.HIIQR8<8ab)8<HR::hbjj9AA,ODAXNS(00rxx0@D.67hs1Q4y1}hG7 ! 	 J<R 8 ! sO   +G>'F0%G,F:8F5F:AG<G G0G5F::G
Gindexc                     U R                   U   [        U R                  U   5      p2[        R                  " USS9nU R
                  b  U R                  U5      nU R                  b  U R                  U5      nX#4$ )zn
Args:
    index (int): Index

Returns:
    tuple: (image, target) where target is index of the target class.
L)mode)r4   r3   r5   r	   	fromarrayr   r   )r6   rE   imgtargets       rC   __getitem__USPS.__getitem__I   sp     ii&DLL,?(@V ooc,>>%..%C  ,**62F{    c                 ,    [        U R                  5      $ )N)lenr4   )r6   s    rC   __len__USPS.__len___   s    499~rN   )r4   r5   )TNNF)__name__
__module____qualname____firstlineno____doc__r#   r   strr   boolr   r   r"   r3   r   r   rL   rQ   __static_attributes____classcell__)rB   s   @rC   r   r      s    (


J  (,/3CI  H%	
 #8,  
 8 sCx ,  rN   r   )r$   pathlibr   typingr   r   r   r   r   numpyr-   PILr	   utilsr   visionr   r    rN   rC   <module>rc      s+    	  8 8    !T= TrN   