Ë
    Dêñiµ  ã                   ór   — d dl Z d dlmZ d dlmZmZmZmZ d dlZ	ddl
mZ ddl
mZ ddlmZ  G d	„ d
e«      Zy)é    N)ÚPath)ÚAnyÚCallableÚOptionalÚUnioné   )Ú_Image_fromarrayé   )Údownload_url)ÚVisionDatasetc                   ó”   ‡ — e Zd ZdZg d¢g d¢dœZ	 	 	 	 ddeeef   dede	e
   d	e	e
   d
eddfˆ fd„Zdedeeef   fd„Zdefd„Zˆ xZS )ÚUSPSa&  `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         ‰| �  |||¬«       |rdnd}| j                  |   \  }}}	t        j                  j                  | j                  |«      }
|r8t        j                  j                  |
«      st        || j                  ||	¬«       dd l	}|j                  |
«      5 }|j                  «       D �cg c]   }|j                  «       j                  «       ‘Œ" }}|D ��cg c]'  }|dd  D �cg c]  }|j                  d«      d   ‘Œ c}‘Œ) }}}t        j                  |t        j                   ¬	«      j#                  d
«      }|dz   dz  dz  j%                  t        j&                  ¬	«      }|D �cg c]  }t)        |d   «      dz
  ‘Œ }}d d d «       | _        | _        y c c}w c c}w c c}}w c c}w # 1 sw Y   Œ-xY w)N)r   r   r   r   )Úmd5r   r
   ú:éÿÿÿÿ)Údtype)r   é   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_datar2   ÚxÚtmp_listÚimgsÚdr3   Ú	__class__s                        €ú[/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/torchvision/datasets/usps.pyr    zUSPS.__init__-   sv  ø€ ô 	‰Ñ˜¨ÐEUÐÔVÙ ‘ fˆØ"&§/¡/°%Ñ"8ÑˆˆX�xÜ—G‘G—L‘L §¡¨HÓ5ˆ	áœBŸG™GŸN™N¨9Ô5Ü˜˜dŸi™i¨°xÕ@ãà�X‰X�iÓ ð 	8 BØ:<¿,¹,».ÖI°$˜Ÿ™›×+Ñ+Õ-ÐIˆHÐIØIQ×RÀ°4¸¸°8Ö<¨a˜Ÿ™ › bÓ)Ô<ÐRˆHÑRÜ—:‘:˜h¬b¯j©jÔ9×AÑAÀ,ÓOˆDØ˜A‘X ‘N SÑ(×0Ñ0´r·x±xÐ0Ó@ˆDØ.6Ö7¨”s˜1˜Q™4“y 1“}Ð7ˆGÐ7÷	8ð ˆŒ	Øˆ�ùò JùÚ<ùÓRùò 8÷	8ð 	8úsO   Â&F;Â9%F&ÃF;Ã%F0Ã1F+ÄF0ÄA$F;Å5F6ÆF;Æ&F;Æ+F0Æ0F;Æ;GÚindexc                 óæ   — | j                   |   t        | j                  |   «      }}t        |d¬«      }| j                  �| j	                  |«      }| j
                  �| j                  |«      }||fS )z–
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        ÚL)Úmode)r2   r1   r3   r	   r   r   )r4   rB   ÚimgÚtargets       rA   Ú__getitem__zUSPS.__getitem__I   sp   € ð —i‘i Ñ&¬¨D¯L©L¸Ñ,?Ó(@ˆVˆô ˜s¨Ô-ˆà�>‰>Ð%Ø—.‘. Ó%ˆCà× Ñ Ð,Ø×*Ñ*¨6Ó2ˆFà�Fˆ{Ðó    c                 ó,   — t        | j                  «      S )N)Úlenr2   )r4   s    rA   Ú__len__zUSPS.__len___   s   € Ü�4—9‘9‹~ÐrI   )TNNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r   Ústrr   Úboolr   r   r    r1   Útupler   rH   rL   Ú__classcell__)r@   s   @rA   r   r      s    ø„ ñò(
ò

ñ€Jð  Ø(,Ø/3Øñà�C˜�IÑðð ðð ˜HÑ%ð	ð
 # 8Ñ,ðð ðð 
õð8 ð ¨¨s°C¨x©ó ð,˜÷ rI   r   )r"   Úpathlibr   Útypingr   r   r   r   Únumpyr+   Úutilsr	   r   Úvisionr   r   © rI   rA   ú<module>r[      s+   ðÛ 	Ý ß 1Ó 1ã å $Ý Ý !ôTˆ=õ TrI   