
    Ph!                     n    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e      Zy)	    N)AnyCallableOptionalTuple)Image   )check_integritydownload_urlverify_str_arg)VisionDatasetc                        e Zd ZdZg dg dg ddZ	 	 	 	 dde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defdZddZdefdZ x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.mat e26dedcc434d2e4c54c9b2d4a06d8373)z5http://ufldl.stanford.edu/housenumbers/test_32x32.matztest_32x32.mat eb5a983be6a315427106f1b164d9cef3)z6http://ufldl.stanford.edu/housenumbers/extra_32x32.matzextra_32x32.mat a93ce644f1a588dc4d68dda5feec44a7)traintestextraNrootsplit	transformtarget_transformdownloadreturnc                 *   t         |   |||       t        |dt        | j                  j                                     | _        | j                  |   d   | _        | j                  |   d   | _        | j                  |   d   | _	        |r| j                          | j                         st        d      dd lm} |j                  t         j"                  j%                  | j&                  | j                              }|d   | _        |d   j+                  t,        j.                        j1                         | _        t-        j4                  | j2                  | j2                  d	k(  d       t-        j6                  | j(                  d
      | _        y )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filename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   sio
loaded_mat	__class__s	           dC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torchvision/datasets/svhn.pyr"   zSVHN.__init__5   s0    	EUV#E7E$//:N:N:P4QR
??5)!,.q1.q1MMO$$&ijj 	 [[dii!GH
sO	
 !o,,RXX6>>@
 	dkkR/3LLL9	    indexc                    | j                   |   t        | j                  |         }}t        j                  t        j                  |d            }| j                  | j                  |      }| j                  | j                  |      }||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        )r   r   r   )	r1   intr6   r   	fromarrayr3   r8   r   r   )r9   r?   imgtargets       r=   __getitem__zSVHN.__getitem__]   s}     ii&DKK,>(?V oobll3	:;>>%..%C  ,**62FF{r>   c                 ,    t        | j                        S )N)lenr1   r9   s    r=   __len__zSVHN.__len__s   s    499~r>   c                     | j                   }| j                  | j                     d   }t        j                  j                  || j                        }t        ||      S Nr   )r   r$   r   r.   r/   r0   r'   r	   )r9   r   md5fpaths       r=   r)   zSVHN._check_integrityv   sG    yyoodjj)!,T4==1uc**r>   c                     | j                   | j                     d   }t        | j                  | j                  | j
                  |       y rK   )r$   r   r
   r&   r   r'   )r9   rL   s     r=   r   zSVHN.download|   s3    oodjj)!,TXXtyy$--=r>   c                 :     dj                   di | j                  S )NzSplit: {split} )format__dict__rH   s    r=   
extra_reprzSVHN.extra_repr   s    &&&777r>   )r   NNF)r   N)__name__
__module____qualname____doc__r$   strr   r   boolr"   rA   r   r   rE   rI   r)   r   rS   __classcell__)r<   s   @r=   r   r      s    0




J* (,/3&:&: &: H%	&:
 #8,&: &: 
&:P sCx , +$ +>8C 8r>   r   )os.pathr.   typingr   r   r   r   numpyr3   PILr   utilsr	   r
   r   visionr   r   rP   r>   r=   <module>ra      s+     1 1   @ @ !v8= v8r>   