o
    ôjÜ  ã                   @   sx   d dl Zd dlmZ d dlmZmZmZmZm	Z	 d dl
Zd dlmZ ddlmZmZmZ ddlmZ G dd	„ d	eƒZdS )
é    N)ÚPath)ÚAnyÚCallableÚOptionalÚTupleÚUnion)ÚImageé   )Úcheck_integrityÚdownload_urlÚverify_str_arg)ÚVisionDatasetc                       sº   e Zd ZdZg d¢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d„Zdedeeef fdd„Zdefdd„Zde
fdd„Zddd„Zdefdd„Z‡  ZS )ÚSVHNaˆ  `SVHN <http://ufldl.stanford.edu/housenumbers/>`_ Dataset.
    Note: The SVHN dataset assigns the label `10` to the digit `0`. However, in this Dataset,
    we assign the label `0` to the digit `0` to be compatible with PyTorch loss functions which
    expect the class labels to be in the range `[0, C-1]`

    .. warning::

        This class needs `scipy <https://docs.scipy.org/doc/>`_ to load data from `.mat` format.

    Args:
        root (str or ``pathlib.Path``): Root directory of the dataset where the data is stored.
        split (string): One of {'train', 'test', 'extra'}.
            Accordingly dataset is selected. 'extra' is Extra training set.
        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.

    )z6http://ufldl.stanford.edu/housenumbers/train_32x32.matztrain_32x32.matZ e26dedcc434d2e4c54c9b2d4a06d8373)z5http://ufldl.stanford.edu/housenumbers/test_32x32.matztest_32x32.matZ eb5a983be6a315427106f1b164d9cef3)z6http://ufldl.stanford.edu/housenumbers/extra_32x32.matzextra_32x32.matZ a93ce644f1a588dc4d68dda5feec44a7)ÚtrainÚtestÚextrar   NFÚrootÚsplitÚ	transformÚtarget_transformÚdownloadÚreturnc                    sä   t ƒ j|||d� t|dt| j ¡ ƒƒ| _| j| d | _| j| d | _| j| d | _	|r3|  
¡  |  ¡ s;tdƒ‚dd lm} | tj | j| j¡¡}|d | _|d  tj¡ ¡ | _t | j| jd	kd¡ t | jd
¡| _d S )N)r   r   r   r   r	   é   zHDataset not found or corrupted. You can use download=True to download itÚXÚyé
   )é   r   r   r	   )ÚsuperÚ__init__r   ÚtupleÚ
split_listÚkeysr   ÚurlÚfilenameZfile_md5r   Ú_check_integrityÚRuntimeErrorÚscipy.ioÚioÚloadmatÚosÚpathÚjoinr   ÚdataÚastypeÚnpÚint64ÚsqueezeÚlabelsÚplaceÚ	transpose)Úselfr   r   r   r   r   ÚsioZ
loaded_mat©Ú	__class__© új/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchvision/datasets/svhn.pyr   6   s   
zSVHN.__init__Úindexc                 C   s\   | j | t| j| ƒ}}t t |d¡¡}| jdur |  |¡}| jdur*|  |¡}||fS )z–
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        )r	   r   r   N)	r,   Úintr1   r   Ú	fromarrayr.   r3   r   r   )r4   r:   ÚimgÚtargetr8   r8   r9   Ú__getitem__^   s   



zSVHN.__getitem__c                 C   s
   t | jƒS )N)Úlenr,   ©r4   r8   r8   r9   Ú__len__t   s   
zSVHN.__len__c                 C   s0   | j }| j| j d }tj || j¡}t||ƒS ©Nr   )r   r    r   r)   r*   r+   r#   r
   )r4   r   Úmd5Úfpathr8   r8   r9   r$   w   s   
zSVHN._check_integrityc                 C   s(   | j | j d }t| j| j| j|ƒ d S rC   )r    r   r   r"   r   r#   )r4   rD   r8   r8   r9   r   }   s   zSVHN.downloadc                 C   s   dj di | j¤ŽS )NzSplit: {split}r8   )ÚformatÚ__dict__rA   r8   r8   r9   Ú
extra_repr�   s   zSVHN.extra_repr)r   NNF)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    r   Ústrr   r   r   Úboolr   r;   r   r   r?   rB   r$   r   rH   Ú__classcell__r8   r8   r6   r9   r      s8    õú
þýüûúù(
r   )Úos.pathr)   Úpathlibr   Útypingr   r   r   r   r   Únumpyr.   ÚPILr   Úutilsr
   r   r   Úvisionr   r   r8   r8   r8   r9   Ú<module>   s    