
    h                     z    S SK rS SKJr  S SKJrJrJrJr  S SK	r
S SKJr  SSKJrJrJr  SSKJr   " S S	\5      rg)
    N)Path)AnyCallableOptionalUnion)Image   )check_integritydownload_urlverify_str_arg)VisionDatasetc                      ^  \ rS rSrSr/ SQ/ 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\4S jrSS jrS\4S jrSrU =r$ )SVHN   aD  `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.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U ]  XUS9  [        US[        U R                  R                  5       5      5      U l        U R                  U   S   U l        U R                  U   S   U l        U R                  U   S   U l	        U(       a  U R                  5         U R                  5       (       d  [        S5      eSS KJn  UR                  [         R"                  R%                  U R&                  U R                  5      5      nUS   U l        US   R+                  [,        R.                  5      R1                  5       U l        [,        R4                  " U R2                  U R2                  S	:H  S5        [,        R6                  " U R(                  S
5      U l        g )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	           Q/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/datasets/svhn.pyr$   SVHN.__init__6   s1    	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                 "   U R                   U   [        U R                  U   5      p2[        R                  " [
        R                  " US5      5      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.
)r	   r   r   )	r3   intr8   r   	fromarrayr5   r:   r   r   )r;   rB   imgtargets       r?   __getitem__SVHN.__getitem__^   sy     ii&DKK,>(?V oobll3	:;>>%..%C  ,**62F{rA   c                 ,    [        U R                  5      $ )N)lenr3   r;   s    r?   __len__SVHN.__len__t   s    499~rA   c                     U R                   nU R                  U R                     S   n[        R                  R                  XR                  5      n[        X25      $ Nr   )r   r&   r   r0   r1   r2   r)   r
   )r;   r   md5fpaths       r?   r+   SVHN._check_integrityw   sC    yyoodjj)!,T==1u**rA   c                     U R                   U R                     S   n[        U R                  U R                  U R
                  U5        g rP   )r&   r   r   r(   r   r)   )r;   rQ   s     r?   r   SVHN.download}   s3    oodjj)!,TXXtyy$--=rA   c                 :    SR                   " S0 U R                  D6$ )NzSplit: {split} )format__dict__rL   s    r?   
extra_reprSVHN.extra_repr   s    &&777rA   )r3   r*   r)   r8   r   r(   )r   NNF)r   N)__name__
__module____qualname____firstlineno____doc__r&   r   strr   r   r   boolr$   rD   r%   r   rH   rM   r+   r   rZ   __static_attributes____classcell__)r>   s   @r?   r   r      s    0




J* (,/3&:CI&: &: H%	&:
 #8,&: &: 
&: &:P sCx , +$ +>8C 8 8rA   r   )os.pathr0   pathlibr   typingr   r   r   r   numpyr5   PILr   utilsr
   r   r   visionr   r   rW   rA   r?   <module>rl      s.      1 1   @ @ !v8= v8rA   