a
    PSic                     @   sh   d dl 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mZmZ ddlmZ G dd deZdS )	    N)AnyCallableOptionalTuple)Image   )download_urlcheck_integrityverify_str_arg)VisionDatasetc                       s   e Zd ZdZg dg dg ddZdeeee ee edd	 fd
dZ	e
eeef dddZe
dddZedddZddddZedddZ  ZS )SVHNay  `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 (string): 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 an 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 | _	|rf| 
  |  svt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__ U/var/www/html/django/DPS/env/lib/python3.9/site-packages/torchvision/datasets/svhn.pyr   5   s    
zSVHN.__init__)indexr   c                 C   s\   | j | t| j|  }}tt|d}| jdur@| |}| jdurT| |}||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        )r   r   r   N)	r*   intr/   r   	fromarrayr,   r1   r   r   )r2   r8   imgtargetr6   r6   r7   __getitem__]   s    



zSVHN.__getitem__)r   c                 C   s
   t | jS )N)lenr*   r2   r6   r6   r7   __len__s   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	   )r2   r   md5fpathr6   r6   r7   r"   v   s    zSVHN._check_integrityc                 C   s(   | j | j d }t| j| j| j| d S rA   )r   r   r   r    r   r!   )r2   rB   r6   r6   r7   r   |   s    zSVHN.downloadc                 C   s   dj f i | jS )NzSplit: {split})format__dict__r?   r6   r6   r7   
extra_repr   s    zSVHN.extra_repr)r   NNF)__name__
__module____qualname____doc__r   strr   r   boolr   r9   r   r   r=   r@   r"   r   rF   __classcell__r6   r6   r4   r7   r      s,       (r   )os.pathr'   typingr   r   r   r   numpyr,   PILr   utilsr   r	   r
   visionr   r   r6   r6   r6   r7   <module>   s   