
    h,U                     4   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
JrJrJr  S SKJr  S SKrS SKrSSKJr  SSKJrJrJrJrJr  SS	KJr   " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r S\!S\"4S jr#\RH                  \RJ                  \RL                  \RN                  \RP                  \RR                  S.r*SS\+S\,S\RZ                  4S jjr.S\+S\RZ                  4S jr/S\+S\RZ                  4S jr0g)    N)Path)AnyCallableOptionalUnion)URLError   )_Image_fromarray   )_flip_byte_ordercheck_integritydownload_and_extract_archiveextract_archiveverify_str_arg)VisionDatasetc                   ~  ^  \ rS rSrSrSS/r/ SQrSrSr/ SQr	\
S	 5       r\
S
 5       r\
S 5       r\
S 5       r    S"S\\\4   S\S\\   S\\   S\SS4U 4S jjjrS rS rS rS\S\\\4   4S jrS\4S jr\
S\4S j5       r\
S\4S j5       r\
S\ \\4   4S j5       r!S\4S jr"S#S jr#S\4S  jr$S!r%U =r&$ )$MNIST   a9  `MNIST <http://yann.lecun.com/exdb/mnist/>`_ Dataset.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where ``MNIST/raw/train-images-idx3-ubyte``
        and  ``MNIST/raw/t10k-images-idx3-ubyte`` exist.
    train (bool, optional): If True, creates dataset from ``train-images-idx3-ubyte``,
        otherwise from ``t10k-images-idx3-ubyte``.
    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.
z.https://ossci-datasets.s3.amazonaws.com/mnist/z!http://yann.lecun.com/exdb/mnist/))train-images-idx3-ubyte.gz f68b3c2dcbeaaa9fbdd348bbdeb94873)train-labels-idx1-ubyte.gz d53e105ee54ea40749a09fcbcd1e9432)t10k-images-idx3-ubyte.gz 9fb629c4189551a2d022fa330f9573f3)t10k-labels-idx1-ubyte.gz ec29112dd5afa0611ce80d1b7f02629cztraining.ptztest.pt
z0 - zeroz1 - onez2 - twoz	3 - threez4 - fourz5 - fivez6 - sixz	7 - sevenz	8 - eightz9 - ninec                 F    [         R                  " S5        U R                  $ )Nz%train_labels has been renamed targetswarningswarntargetsselfs    R/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/datasets/mnist.pytrain_labelsMNIST.train_labels@   s    =>||    c                 F    [         R                  " S5        U R                  $ )Nz$test_labels has been renamed targetsr   r#   s    r%   test_labelsMNIST.test_labelsE   s    <=||r(   c                 F    [         R                  " S5        U R                  $ )Nz train_data has been renamed datar    r!   datar#   s    r%   
train_dataMNIST.train_dataJ   s    89yyr(   c                 F    [         R                  " S5        U R                  $ )Nztest_data has been renamed datar-   r#   s    r%   	test_dataMNIST.test_dataO   s    78yyr(   Nroottrain	transformtarget_transformdownloadreturnc                 <  > [         TU ]  XUS9  X l        U R                  5       (       a  U R	                  5       u  U l        U l        g U(       a  U R                  5         U R                  5       (       d  [        S5      eU R                  5       u  U l        U l        g )N)r6   r7   z;Dataset not found. You can use download=True to download it)super__init__r5   _check_legacy_exist_load_legacy_datar.   r"   r8   _check_existsRuntimeError
_load_data)r$   r4   r5   r6   r7   r8   	__class__s         r%   r<   MNIST.__init__T   s     	EUV
##%%&*&<&<&>#DIt|MMO!!##\]]"&//"3	4<r(   c                    ^  [         R                  R                  T R                  5      nU(       d  g[	        U 4S jT R
                  T R                  4 5       5      $ )NFc              3      >#    U  H8  n[        [        R                  R                  TR                  U5      5      v   M:     g 7fN)r   ospathjoinprocessed_folder).0filer$   s     r%   	<genexpr>,MNIST._check_legacy_exist.<locals>.<genexpr>p   s2      
Sw4OBGGLL)>)>EFFSws   A A)rG   rH   existsrJ   alltraining_file	test_file)r$   processed_folder_existss   ` r%   r=   MNIST._check_legacy_existk   sN    "$''..1F1F"G& 
TXTfTfhlhvhvSw
 
 	
r(   c                     U R                   (       a  U R                  OU R                  n[        R                  " [
        R                  R                  U R                  U5      SS9$ )NT)weights_only)	r5   rQ   rR   torchloadrG   rH   rI   rJ   )r$   	data_files     r%   r>   MNIST._load_legacy_datat   sB     +/**D&&$..	zz"'',,t'<'<iHW[\\r(   c                 4   U R                   (       a  SOS S3n[        [        R                  R	                  U R
                  U5      5      nU R                   (       a  SOS S3n[        [        R                  R	                  U R
                  U5      5      nX$4$ )Nr5   t10k-images-idx3-ubyte-labels-idx1-ubyte)r5   read_image_filerG   rH   rI   
raw_folderread_label_file)r$   
image_filer.   
label_filer"   s        r%   rA   MNIST._load_dataz   sp    #'::6::LM
rww||DOOZHI#'::6::LM
!"'',,t
"KL}r(   indexc                     U R                   U   [        U R                  U   5      p2[        UR	                  5       SS9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.
Lmode)r.   intr"   r
   numpyr6   r7   r$   re   imgtargets       r%   __getitem__MNIST.__getitem__   sr     ii&DLL,?(@V syy{5>>%..%C  ,**62F{r(   c                 ,    [        U R                  5      $ rF   )lenr.   r#   s    r%   __len__MNIST.__len__   s    499~r(   c                     [         R                  R                  U R                  U R                  R
                  S5      $ )NrawrG   rH   rI   r4   rB   __name__r#   s    r%   r`   MNIST.raw_folder   s'    ww||DIIt~~'>'>FFr(   c                     [         R                  R                  U R                  U R                  R
                  S5      $ )N	processedrw   r#   s    r%   rJ   MNIST.processed_folder   s'    ww||DIIt~~'>'>LLr(   c                 b    [        U R                  5       VVs0 s H  u  pX!_M	     snn$ s  snnf rF   )	enumerateclasses)r$   i_classs      r%   class_to_idxMNIST.class_to_idx   s)    +4T\\+BC+Bia	+BCCCs   +c                 B   ^  [        U 4S jT R                   5       5      $ )Nc              3     >#    U  Hw  u  p[        [        R                  R                  TR                  [        R                  R                  [        R                  R                  U5      5      S    5      5      v   My     g7f)r   N)r   rG   rH   rI   r`   splitextbasename)rK   url_r$   s      r%   rM   &MNIST._check_exists.<locals>.<genexpr>   sZ      
( BGGLL"'':J:J277K[K[\_K`:abc:deff(s   A?B)rP   	resourcesr#   s   `r%   r?   MNIST._check_exists   s!     
..
 
 	
r(   c           	         U R                  5       (       a  g[        R                  " U R                  SS9  U R                   Hy  u  p/ nU R
                   H  nU U 3n [        XPR                  XS9    M4     SU S3n[        U R
                  U5       H  u  pHUSU S[        U5       S	3-  nM     [        U5      e   g! [         a  nUR                  U5         SnAM  SnAff = f)
z4Download the MNIST data if it doesn't exist already.NTexist_ok)download_rootfilenamemd5zError downloading z:
zTried z, got:

)r?   rG   makedirsr`   r   mirrorsr   r   appendzipstrr@   )	r$   r   r   errorsmirrorr   eserrs	            r%   r8   MNIST.download   s     
DOOd3 "^^MHF,,
+0OO^fp  ' )
#6#&t||V#<KF6&#c(2>>A $="1o% ,   MM!$s   C  
C&
C!!C&c                 2    U R                   SL a  SOSnSU 3$ )NTTrainTestSplit: )r5   )r$   splits     r%   
extra_reprMNIST.extra_repr   s!    ::-6  r(   )r.   r"   r5   )TNNFr9   N)'rx   
__module____qualname____firstlineno____doc__r   r   rQ   rR   r   propertyr&   r*   r/   r2   r   r   r   boolr   r   r<   r=   r>   rA   rj   tupler   ro   rs   r`   rJ   dictr   r?   r8   r   __static_attributes____classcell__rB   s   @r%   r   r      s   " 	9+G
I "MIG         (,/34CI4 4 H%	4
 #8,4 4 
4 4.
] sCx ,  GC G G M# M M Dd38n D D
t 
&2!C ! !r(   r   c                   .    \ rS rSrSrS/r/ SQr/ SQrSrg)FashionMNIST   a^  `Fashion-MNIST <https://github.com/zalandoresearch/fashion-mnist>`_ Dataset.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where ``FashionMNIST/raw/train-images-idx3-ubyte``
        and  ``FashionMNIST/raw/t10k-images-idx3-ubyte`` exist.
    train (bool, optional): If True, creates dataset from ``train-images-idx3-ubyte``,
        otherwise from ``t10k-images-idx3-ubyte``.
    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.
z;http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/))r    8d4fb7e6c68d591d4c3dfef9ec88bf0d)r    25c81989df183df01b3e8a0aad5dffbe)r    bef4ecab320f06d8554ea6380940ec79)r    bb300cfdad3c16e7a12a480ee83cd310)
zT-shirt/topTrouserPulloverDressCoatSandalShirtSneakerBagz
Ankle boot N	rx   r   r   r   r   r   r   r   r   r   r(   r%   r   r      s!      MMGI yGr(   r   c                   .    \ rS rSrSrS/r/ SQr/ SQrSrg)KMNIST   aG  `Kuzushiji-MNIST <https://github.com/rois-codh/kmnist>`_ Dataset.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where ``KMNIST/raw/train-images-idx3-ubyte``
        and  ``KMNIST/raw/t10k-images-idx3-ubyte`` exist.
    train (bool, optional): If True, creates dataset from ``train-images-idx3-ubyte``,
        otherwise from ``t10k-images-idx3-ubyte``.
    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.
z-http://codh.rois.ac.jp/kmnist/dataset/kmnist/))r    bdb82020997e1d708af4cf47b453dcf7)r    e144d726b3acfaa3e44228e80efcd344)r    5c965bf0a639b31b8f53240b1b52f4d7)r    7320c461ea6c1c855c0b718fb2a4b134)
okisutsunahamayarewor   Nr   r   r(   r%   r   r      s       ??GI KGr(   r   c                      ^  \ rS rSrSrSrSrSr1 Skr\	" \
R                  \
R                  -   5      r\" \" \5      5      \" \" \\-
  5      5      \" \" \\-
  5      5      S/\" \
R                   5      -   \" \
R                  5      \" \
R                  5      S.rS\\\4   S	\S
\SS4U 4S jjr\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       rS rS\4S jr SS jr!Sr"U =r#$ )EMNISTi  a  `EMNIST <https://www.westernsydney.edu.au/bens/home/reproducible_research/emnist>`_ Dataset.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where ``EMNIST/raw/train-images-idx3-ubyte``
        and  ``EMNIST/raw/t10k-images-idx3-ubyte`` exist.
    split (string): The dataset has 6 different splits: ``byclass``, ``bymerge``,
        ``balanced``, ``letters``, ``digits`` and ``mnist``. This argument specifies
        which one to use.
    train (bool, optional): If True, creates dataset from ``training.pt``,
        otherwise from ``test.pt``.
    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.
    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.
z4https://biometrics.nist.gov/cs_links/EMNIST/gzip.zip 58c8d27c78d21e728a6bc7b3cc06412e)byclassbymergebalancedlettersdigitsmnist>   cr   jklmr   pr   uvwxyzzN/Ar4   r   kwargsr9   Nc                    > [        USU R                  5      U l        U R                  U5      U l        U R                  U5      U l        [        TU ]   " U40 UD6  U R                  U R                     U l
        g )Nr   )r   splitsr   _training_filerQ   
_test_filerR   r;   r<   classes_split_dictr   )r$   r4   r   r   rB   s       r%   r<   EMNIST.__init__'  sb    #E7DKK@
!007/((..tzz:r(   c                     SU  S3$ )N	training_.ptr   r   s    r%   r   EMNIST._training_file.  s    5'%%r(   c                     SU  S3$ )Ntest_r   r   r   s    r%   r   EMNIST._test_file2  s    ugS!!r(   c                 P    SU R                    SU R                  (       a  S 3$ S 3$ )Nzemnist--r5   test)r   r5   r#   s    r%   _file_prefixEMNIST._file_prefix6  s+    Ag%HII%HIIr(   c                 p    [         R                  R                  U R                  U R                   S35      $ )Nr]   rG   rH   rI   r`   r   r#   s    r%   images_fileEMNIST.images_file:  *    ww||DOO0A0A/BBT-UVVr(   c                 p    [         R                  R                  U R                  U R                   S35      $ )Nr^   r   r#   s    r%   labels_fileEMNIST.labels_file>  r  r(   c                 V    [        U R                  5      [        U R                  5      4$ rF   )r_   r   ra   r  r#   s    r%   rA   EMNIST._load_dataB  s#    t//0/$BRBR2SSSr(   c                 R    [        S U R                  U R                  4 5       5      $ )Nc              3   8   #    U  H  n[        U5      v   M     g 7frF   r   rK   rL   s     r%   rM   'EMNIST._check_exists.<locals>.<genexpr>F       Z5YT?4((5Y   rP   r   r  r#   s    r%   r?   EMNIST._check_existsE  $    Zd6F6FHXHX5YZZZr(   c                    U R                  5       (       a  g[        R                  " U R                  SS9  [	        U R
                  U R                  U R                  S9  [        R                  R                  U R                  S5      n[        R                  " U5       HN  nUR                  S5      (       d  M  [        [        R                  R                  X5      U R                  5        MP     [        R                  " U5        g)z5Download the EMNIST data if it doesn't exist already.NTr   )r   r   gzipz.gz)r?   rG   r   r`   r   r   r   rH   rI   listdirendswithr   shutilrmtree)r$   gzip_folder	gzip_files      r%   r8   EMNIST.downloadH  s     
DOOd3$TXXT__RVRZRZ[ggll4??F;K0I!!%(([ DdooV 1 	k"r(   )r   r   rR   rQ   r   )$rx   r   r   r   r   r   r   r   _merged_classessetstringr   ascii_letters_all_classessortedlistascii_lowercaser   r   r   r   r   r<   staticmethodr   r   r   r   r   r  rA   r   r?   r8   r   r   r   s   @r%   r   r     sv   & AC
,CMFaOv}}v';';;<L$|,-$|o=>?4 >?@7T&"8"899v}}%fmm$;U39- ;c ;S ;T ; & & & "S " " Jc J J WS W W WS W WT[t [# #r(   r   c                   ,  ^  \ rS rSr% SrSSSSSS.rSS/S	S
/SS/S.r\\\	\
\\4      4   \S'   / SQr S S\\\4   S\\   S\S\S\SS4U 4S jjjr\S\4S j5       r\S\4S j5       rS\4S jrS rS!S jrS\S\
\\4   4S jrS\4S jrSrU =r$ )"QMNISTiX  a  `QMNIST <https://github.com/facebookresearch/qmnist>`_ Dataset.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset whose ``raw``
        subdir contains binary files of the datasets.
    what (string,optional): Can be 'train', 'test', 'test10k',
        'test50k', or 'nist' for respectively the mnist compatible
        training set, the 60k qmnist testing set, the 10k qmnist
        examples that match the mnist testing set, the 50k
        remaining qmnist testing examples, or all the nist
        digits. The default is to select 'train' or 'test'
        according to the compatibility argument 'train'.
    compat (bool,optional): A boolean that says whether the target
        for each example is class number (for compatibility with
        the MNIST dataloader) or a torch vector containing the
        full qmnist information. Default=True.
    train (bool,optional,compatibility): When argument 'what' is
        not specified, this boolean decides whether to load the
        training set or the testing set.  Default: True.
    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.
    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.
r5   r   nist)r5   r   test10ktest50kr%  )zbhttps://raw.githubusercontent.com/facebookresearch/qmnist/master/qmnist-train-images-idx3-ubyte.gz ed72d4157d28c017586c42bc6afe6370)z`https://raw.githubusercontent.com/facebookresearch/qmnist/master/qmnist-train-labels-idx2-int.gz 0058f8dd561b90ffdd0f734c6a30e5e4)zahttps://raw.githubusercontent.com/facebookresearch/qmnist/master/qmnist-test-images-idx3-ubyte.gz 1394631089c404de565df7b7aeaf9412)z_https://raw.githubusercontent.com/facebookresearch/qmnist/master/qmnist-test-labels-idx2-int.gz 5b5b05890a5e13444e108efe57b788aa)z[https://raw.githubusercontent.com/facebookresearch/qmnist/master/xnist-images-idx3-ubyte.xz 7f124b3b8ab81486c9d8c2749c17f834)zYhttps://raw.githubusercontent.com/facebookresearch/qmnist/master/xnist-labels-idx2-int.xz 5ed0e788978e45d4a8bd4b7caec3d79d)r5   r   r%  r   r   Nr4   whatcompatr   r9   c                   > Uc  U(       a  SOSn[        US[        U R                  R                  5       5      5      U l        X0l        US-   U l        U R                  U l        U R                  U l        [        TU ](  " X40 UD6  g )Nr5   r   r.  r   )r   r   subsetskeysr.  r/  rY   rQ   rR   r;   r<   )r$   r4   r.  r/  r5   r   rB   s         r%   r<   QMNIST.__init__  sn     <#7D"4t||7H7H7J1KL	!^^//r(   c                 (   U R                   U R                  U R                        u  u  n  n[        R                  R                  U R                  [        R                  R                  [        R                  R                  U5      5      S   5      $ Nr   	r   r1  r.  rG   rH   rI   r`   r   r   )r$   r   r   s      r%   r   QMNIST.images_file  sb    nnT\\$))%<=a!ww||DOORWW-=-=bgg>N>Ns>S-TUV-WXXr(   c                 &   U R                   U R                  U R                        u  nu  p![        R                  R                  U R                  [        R                  R                  [        R                  R                  U5      5      S   5      $ r5  r6  )r$   r   r   s      r%   r  QMNIST.labels_file  s`    nnT\\$))%<=8Cww||DOORWW-=-=bgg>N>Ns>S-TUV-WXXr(   c                 R    [        S U R                  U R                  4 5       5      $ )Nc              3   8   #    U  H  n[        U5      v   M     g 7frF   r	  r
  s     r%   rM   'QMNIST._check_exists.<locals>.<genexpr>  r  r  r  r#   s    r%   r?   QMNIST._check_exists  r  r(   c                    [        U R                  5      nUR                  [        R                  :w  a  [        SUR                   35      eUR                  5       S:w  a  [        S5      e[        U R                  5      R                  5       nUR                  5       S:w  a  [        SUR                  5        35      eU R                  S:X  a8  USS2S S 2S S 24   R                  5       nUSS2S S 24   R                  5       nX4$ U R                  S	:X  a5  USS 2S S 2S S 24   R                  5       nUSS 2S S 24   R                  5       nX4$ )
Nz/data should be of dtype torch.uint8 instead of    z<data should have 3 dimensions instead of {data.ndimension()}r	   z,targets should have 2 dimensions instead of r&  r   i'  r'  )read_sn3_pascalvincent_tensorr   dtyperW   uint8	TypeError
ndimension
ValueErrorr  longr.  clone)r$   r.   r"   s      r%   rA   QMNIST._load_data  s3   ,T-=-=>::$Mdjj\Z[[??![\\/0@0@AFFH1$KGL^L^L`Kabcc99	!%A&,,.Dagqj)//1G
 }	 YY)#1%++-Defai(..0G}r(   c                     U R                  5       (       a  g[        R                  " U R                  SS9  U R                  U R
                  U R                        nU H  u  p#[        X R                  US9  M     g)z|Download the QMNIST data if it doesn't exist already.
Note that we only download what has been asked for (argument 'what').
NTr   )r   )r?   rG   r   r`   r   r1  r.  r   )r$   r   r   r   s       r%   r8   QMNIST.download  s]     
DOOd3t||DII67HC(oo3G r(   re   c                 (   U R                   U   U R                  U   p2[        UR                  5       SS9nU R                  b  U R	                  U5      nU R
                  (       a  [        US   5      nU R                  b  U R                  U5      nX#4$ )Nrg   rh   r   )r.   r"   r
   rk   r6   r/  rj   r7   rl   s       r%   ro   QMNIST.__getitem__  s}    ii&U(;Vsyy{5>>%..%C;;^F  ,**62F{r(   c                      SU R                    3$ )Nr   )r.  r#   s    r%   r   QMNIST.extra_repr  s    $$r(   )r/  rY   rR   rQ   r.  )NTTr   )rx   r   r   r   r   r1  r   r   r   r   r   __annotations__r   r   r   r   r   r   r<   r   r   r  r?   rA   r8   rj   ro   r   r   r   r   s   @r%   r$  r$  X  sD   :  Fv_efG	
	
	
+3ItCeCHo../ @G fj
0#t)$
0,4SM
0JN
0^b
0ux
0	
0 
0 YS Y Y YS Y Y[t [(H
 
sCx 
%C % %r(   r$  br9   c                 D    [        [        R                  " U S5      S5      $ )Nhex   )rj   codecsencode)rP  s    r%   get_intrV    s    v}}Q&++r(   )   	               rH   strictc           
      D   [        U S5       nUR                  5       nSSS5        [        R                  S:X  d  [        R                  S:X  a  [        WSS 5      nUS-  nUS-  nOC[        WSS 5      n[        USS	 5      [        US	S
 5      S-  -   [        US
S 5      S-  S-  -   nSUs=::  a  S
::  d   e   eSUs=::  a  S::  d   e   e[        U   n[        U5       Vs/ s H  n[        USUS-   -  SUS	-   -   5      PM     n	n[        R                  S:X  aV  [        R                  S:X  dB  [        [        U	5      5       H*  n[        R                  X   R                  SSS9SSS9X'   M,     [        R                  " [        U5      USUS-   -  S9n
[        R                  S:X  a  U
R                  5       S:  a  [!        U
5      n
U
R"                  S   [$        R&                  " U	5      :X  d	  U(       a   eU
R(                  " U	6 $ ! , (       d  f       GN= fs  snf )zRead a SN3 file in "Pascal Vincent" format (Lush file 'libidx/idx-io.lsh').
Argument may be a filename, compressed filename, or file object.
rbNlittleaixr         r   r	   r?  rW  r\  big)	byteorderF)re  signed)rA  offset)openreadsysre  platformrV  SN3_PASCALVINCENT_TYPEMAPrangerr   rj   
from_bytesto_bytesrW   
frombuffer	bytearrayelement_sizer   shapenpprodview)rH   r]  fr.   magicndty
torch_typer   r   parseds              r%   r@  r@    s   
 
dD	Qvvx 
 }} CLLE$9Qq	"S[c\T!AYT!AY'$q)"4s"::WT!AY=ORU=UX[=[[<a<<<=b===*2.J;@9E9aa1q5kAQK0	19AE
}}clle&;s1vA>>!$--X-"FRW`e>fAD  ioZbSTfWF }} V%8%8%:Q%>!&)<<?bggaj(66;;?; 
	 	Fs   H$$H
Hc                    [        U SS9nUR                  [        R                  :w  a  [	        SUR                   35      eUR                  5       S:w  a  [        SUR                  5        35      eUR                  5       $ )NFr]  ,x should be of dtype torch.uint8 instead of r   z%x should have 1 dimension instead of )r@  rA  rW   rB  rC  rD  rE  rF  rH   r   s     r%   ra   ra   !  sh    %d59Aww%++FqwwiPQQ||~@@PQRR668Or(   c                     [        U SS9nUR                  [        R                  :w  a  [	        SUR                   35      eUR                  5       S:w  a  [        SUR                  5        35      eU$ )NFr~  r  r?  z%x should have 3 dimension instead of )r@  rA  rW   rB  rC  rD  rE  r  s     r%   r_   r_   *  sb    %d59Aww%++FqwwiPQQ||~@@PQRRHr(   )T)1rT  rG   os.pathr  r  rj  r    pathlibr   typingr   r   r   r   urllib.errorr   rk   rt  rW   utilsr
   r   r   r   r   r   visionr   r   r   r   r   r$  bytesrj   rV  rB  int8int16int32float32float64rl  r   r   Tensorr@  ra   r_   r   r(   r%   <module>r     s    	    
   1 1 !   $ s s !u!M u!py5 y8KU K8Q#U Q#hS%U S%l,u , ,
 {{zz " "T "U\\ "J# %,, # %,, r(   