
    ڧgT                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
mZmZmZmZmZmZ d dlmZ d dlZ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mZ  G d	 d
e          Z  G d de           Z! G d de           Z" G d de           Z# G d de           Z$de%de&fdZ'ej(        ej)        ej*        ej+        ej,        ej-        dZ.dde/de0dej1        fdZ2de/dej1        fdZ3de/dej1        fdZ4dS )    N)Path)AnyCallableDictListOptionalTupleUnion)URLError)Image   )_flip_byte_ordercheck_integritydownload_and_extract_archiveextract_archiveverify_str_arg)VisionDatasetc                       e Zd ZdZddgZg dZdZdZg dZe	d             Z
e	d	             Ze	d
             Ze	d             Z	 	 	 	 d"deeef         dedee         dee         deddf fdZd Zd Zd Zdedeeef         fdZdefdZe	defd            Ze	defd            Ze	deeef         fd            Z defdZ!d#d Z"defd!Z# xZ$S )$MNISTam  `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``.
        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.
    z!http://yann.lecun.com/exdb/mnist/z.https://ossci-datasets.s3.amazonaws.com/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                 8    t          j        d           | j        S )Nz%train_labels has been renamed targetswarningswarntargetsselfs    V/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/mnist.pytrain_labelszMNIST.train_labels@   s    =>>>|    c                 8    t          j        d           | j        S )Nz$test_labels has been renamed targetsr    r$   s    r&   test_labelszMNIST.test_labelsE   s    <===|r(   c                 8    t          j        d           | j        S )Nz train_data has been renamed datar!   r"   datar$   s    r&   
train_datazMNIST.train_dataJ   s    8999yr(   c                 8    t          j        d           | j        S )Nztest_data has been renamed datar,   r$   s    r&   	test_datazMNIST.test_dataO   s    7888yr(   TNFroottrain	transformtarget_transformdownloadreturnc                    t                                          |||           || _        |                                 r#|                                 \  | _        | _        d S |r|                                  |                                 st          d          | 
                                \  | _        | _        d S )N)r3   r4   z;Dataset not found. You can use download=True to download it)super__init__r2   _check_legacy_exist_load_legacy_datar-   r#   r5   _check_existsRuntimeError
_load_data)r%   r1   r2   r3   r4   r5   	__class__s         r&   r9   zMNIST.__init__T   s     	EUVVV
##%% 	&*&<&<&>&>#DIt|F 	MMOOO!!## 	^\]]]"&//"3"3	4<<<r(   c                      t           j                             j                  }|sdS t	           fd j         j        fD                       S )NFc              3   |   K   | ]6}t          t          j                            j        |                    V  7d S N)r   ospathjoinprocessed_folder).0filer%   s     r&   	<genexpr>z,MNIST._check_legacy_exist.<locals>.<genexpr>p   sO       
 
KOOBGLL)>EEFF
 
 
 
 
 
r(   )rC   rD   existsrF   alltraining_file	test_file)r%   processed_folder_existss   ` r&   r:   zMNIST._check_legacy_existk   sk    "$'..1F"G"G& 	5 
 
 
 
TXTfhlhvSw
 
 
 
 
 	
r(   c                     | j         r| j        n| j        }t          j        t
          j                            | j        |          d          S )NT)weights_only)	r2   rL   rM   torchloadrC   rD   rE   rF   )r%   	data_files     r&   r;   zMNIST._load_legacy_datat   sC     +/*HD&&$.	z"',,t'<iHHW[\\\\r(   c                 
   | j         rdnd d}t          t          j                            | j        |                    }| j         rdnd d}t          t          j                            | j        |                    }||fS )Nr2   t10k-images-idx3-ubyte-labels-idx1-ubyte)r2   read_image_filerC   rD   rE   
raw_folderread_label_file)r%   
image_filer-   
label_filer#   s        r&   r>   zMNIST._load_dataz   s|    #':96MMM
rw||DOZHHII#':96MMM
!"',,t
"K"KLLW}r(   indexc                    | j         |         t          | j        |                   }}t          j        |                                d          }| j        |                     |          }| j        |                     |          }||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        Lmode)r-   intr#   r   	fromarraynumpyr3   r4   r%   r]   imgtargets       r&   __getitem__zMNIST.__getitem__   s     i&DL,?(@(@V ociikk444>%..%%C ,**622FF{r(   c                 *    t          | j                  S rB   )lenr-   r$   s    r&   __len__zMNIST.__len__   s    49~~r(   c                 b    t           j                            | j        | j        j        d          S )NrawrC   rD   rE   r1   r?   __name__r$   s    r&   rY   zMNIST.raw_folder   s!    w||DIt~'>FFFr(   c                 b    t           j                            | j        | j        j        d          S )N	processedrn   r$   s    r&   rF   zMNIST.processed_folder   s!    w||DIt~'>LLLr(   c                 >    d t          | j                  D             S )Nc                     i | ]\  }}||	S  rt   )rG   i_classs      r&   
<dictcomp>z&MNIST.class_to_idx.<locals>.<dictcomp>   s    CCCiaCCCr(   )	enumerateclassesr$   s    r&   class_to_idxzMNIST.class_to_idx   s     CC9T\+B+BCCCCr(   c                 D     t           fd j        D                       S )Nc              3     K   | ]y\  }}t          t          j                            j        t          j                            t          j                            |                    d                              V  zdS )r   N)r   rC   rD   rE   rY   splitextbasename)rG   url_r%   s      r&   rI   z&MNIST._check_exists.<locals>.<genexpr>   s|       
 
Q BGLL"':J:J27K[K[\_K`K`:a:abc:deeff
 
 
 
 
 
r(   )rK   	resourcesr$   s   `r&   r<   zMNIST._check_exists   s=     
 
 
 
.
 
 
 
 
 	
r(   c                    |                                  rdS t          j        | j        d           | j        D ]\  }}| j        D ]}| | }	 t          d|            t          || j        ||           n7# t          $ r*}t          d|            Y d}~t                       cd}~ww xY w	 t                       n# t                       w xY w nt          d|           dS )z4Download the MNIST data if it doesn't exist already.NTexist_okzDownloading )download_rootfilenamemd5z"Failed to download (trying next):
zError downloading )
r<   rC   makedirsrY   r   mirrorsprintr   r   r=   )r%   r   r   mirrorr   errors         r&   r5   zMNIST.download   sB     	F
DOd3333 "^ 	D 	DMHc, D D+++...///0DO^floppppp   GGGHHHHHHGGGG	 q
 GGGGEGGGG"#B#B#BCCC 	D 	Ds0   *A98C 9
B-B(C (B--C  Cc                 &    | j         du rdnd}d| S )NTTrainTestSplit: )r2   )r%   splits     r&   
extra_reprzMNIST.extra_repr   s%    :--6    r(   )TNNFr6   N)%ro   
__module____qualname____doc__r   r   rL   rM   ry   propertyr'   r*   r.   r0   r
   strr   boolr   r   r9   r:   r;   r>   rb   r	   r   rh   rk   rY   rF   r   rz   r<   r5   r   __classcell__r?   s   @r&   r   r      s        " 	,8G
  I "MI  G   X   X   X   X (,/34 4CI4 4 H%	4
 #8,4 4 
4 4 4 4 4 4.
 
 
] ] ]   sCx    ,     GC G G G XG M# M M M XM Dd38n D D D XD
t 
 
 
 
D D D D0!C ! ! ! ! ! ! ! !r(   r   c                   (    e Zd ZdZdgZg dZg dZdS )FashionMNISTa  `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``.
        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.
    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 bootNro   r   r   r   r   r   ry   rt   r(   r&   r   r      sB           MMG  I yxxGGGr(   r   c                   (    e Zd ZdZdgZg dZg dZdS )KMNISTa{  `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``.
        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.
    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woNr   rt   r(   r&   r   r      sA           ??G  I KJJGGGr(   r   c                       e Zd ZdZdZdZdZh dZ ee	j
        e	j        z             Z e ee                     e eeez
                       e eeez
                      dg ee	j                  z    ee	j
                   ee	j
                  dZdeeef         ded	ed
df fdZed
efd            Zed
efd            Zed
efd            Zed
efd            Zed
efd            Zd Zd
efdZddZ  xZ!S )EMNISTaH  `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>   cru   jklmr   psuvwxyzzN/Ar1   r   kwargsr6   Nc                    t          |d| j                  | _        |                     |          | _        |                     |          | _         t                      j        |fi | | j	        | j                 | _
        d S )Nr   )r   splitsr   _training_filerL   
_test_filerM   r8   r9   classes_split_dictry   )r%   r1   r   r   r?   s       r&   r9   zEMNIST.__init__&  su    #E7DK@@
!0077//(((((.tz:r(   c                     d|  dS )N	training_.ptrt   r   s    r&   r   zEMNIST._training_file-  s    %5%%%%r(   c                     d|  dS )Ntest_r   rt   r   s    r&   r   zEMNIST._test_file1  s    !u!!!!r(   c                 .    d| j          d| j        rdnd S )Nzemnist--r2   test)r   r2   r$   s    r&   _file_prefixzEMNIST._file_prefix5  s%    III&GggIIIr(   c                 \    t           j                            | j        | j         d          S )NrV   rC   rD   rE   rY   r   r$   s    r&   images_filezEMNIST.images_file9  &    w||DO0A-U-U-UVVVr(   c                 \    t           j                            | j        | j         d          S )NrW   r   r$   s    r&   labels_filezEMNIST.labels_file=  r   r(   c                 R    t          | j                  t          | j                  fS rB   )rX   r   rZ   r   r$   s    r&   r>   zEMNIST._load_dataA  s#    t/00/$BR2S2SSSr(   c                 L    t          d | j        | j        fD                       S )Nc              3   4   K   | ]}t          |          V  d S rB   r   rG   rH   s     r&   rI   z'EMNIST._check_exists.<locals>.<genexpr>E  *      ZZT?4((ZZZZZZr(   rK   r   r   r$   s    r&   r<   zEMNIST._check_existsD  *    ZZd6FHX5YZZZZZZr(   c                    |                                  rdS t          j        | j        d           t	          | j        | j        | j                   t          j                            | j        d          }t          j	        |          D ]J}|
                    d          r3t          t          j                            ||          | j                   Kt          j        |           dS )z5Download the EMNIST data if it doesn't exist already.NTr   )r   r   gzipz.gz)r<   rC   r   rY   r   r   r   rD   rE   listdirendswithr   shutilrmtree)r%   gzip_folder	gzip_files      r&   r5   zEMNIST.downloadG  s      	F
DOd3333$TXT_RVRZ[[[[gll4?F;;K00 	W 	WI!!%(( W[) D DdoVVVk"""""r(   r   )"ro   r   r   r   r   r   r   _merged_classessetstringr   ascii_letters_all_classessortedlistascii_lowercaser   r
   r   r   r   r9   staticmethodr   r   r   r   r   r   r>   r   r<   r5   r   r   s   @r&   r   r     sK        & AC
,CMFaaaO3v}v';;<<L6$$|,,--6$$|o=>>??F44 >??@@7TT&"8999$v}%%fm$$ ;U39- ;c ;S ;T ; ; ; ; ; ; & & & & \& "S " " " \" Jc J J J XJ WS W W W XW WS W W W XWT T T[t [ [ [ [# # # # # # # #r(   r   c                   B    e Zd ZU dZddddddZddgdd	gd
dgdZeeee	eef                  f         e
d<   g dZ	 ddeeef         dee         dedededdf fdZedefd            Zedefd            ZdefdZd Zd dZdede	eef         fdZdefdZ xZS )!QMNISTa`  `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.
        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.
        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.
    r2   r   nist)r2   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)r2   r   r  r   r   NTr1   whatcompatr   r6   c                    ||rdnd}t          |dt          | j                                                            | _        || _        |dz   | _        | j        | _        | j        | _         t                      j
        ||fi | d S )Nr2   r   r  r   )r   tuplesubsetskeysr  r  rS   rL   rM   r8   r9   )r%   r1   r  r  r2   r   r?   s         r&   r9   zQMNIST.__init__  s     <#/77D"4t|7H7H7J7J1K1KLL	!^u///////r(   c                    | j         | j        | j                          \  \  }}}t          j                            | j        t          j                            t          j                            |                    d                   S Nr   	r   r  r  rC   rD   rE   rY   r}   r~   )r%   r   r   s      r&   r   zQMNIST.images_file  s]    nT\$)%<=a!w||DORW-=-=bg>N>Ns>S>S-T-TUV-WXXXr(   c                    | j         | j        | j                          \  }\  }}t          j                            | j        t          j                            t          j                            |                    d                   S r  r  )r%   r   r   s      r&   r   zQMNIST.labels_file  s]    nT\$)%<=8Cw||DORW-=-=bg>N>Ns>S>S-T-TUV-WXXXr(   c                 L    t          d | j        | j        fD                       S )Nc              3   4   K   | ]}t          |          V  d S rB   r   r   s     r&   rI   z'QMNIST._check_exists.<locals>.<genexpr>  r   r(   r   r$   s    r&   r<   zQMNIST._check_exists  r   r(   c                    t          | j                  }|j        t          j        k    rt          d|j                   |                                dk    rt          d          t          | j                  	                                }|                                dk    r$t          d|                                           | j
        dk    rD|ddd d d d f                                         }|ddd d f                                         }nN| j
        d	k    rC|dd d d d d f                                         }|dd d d f                                         }||fS )
Nz/data should be of dtype torch.uint8 instead of    z<data should have 3 dimensions instead of {data.ndimension()}   z,targets should have 2 dimensions instead of r  r   i'  r  )read_sn3_pascalvincent_tensorr   dtyperQ   uint8	TypeError
ndimension
ValueErrorr   longr  clone)r%   r-   r#   s      r&   r>   zQMNIST._load_data  sn   ,T-=>>:$$ZdjZZ[[[??!![\\\/0@AAFFHH1$$bGL^L^L`L`bbccc9	!!%AAA&,,..Dagqqqj)//11GGY)##111%++--Deffaaai(..00GW}r(   c                     |                                  rdS t          j        | j        d           | j        | j        | j                          }|D ]\  }}t          || j        |           dS )zDownload the QMNIST data if it doesn't exist already.
        Note that we only download what has been asked for (argument 'what').
        NTr   )r   )r<   rC   r   rY   r   r  r  r   )r%   r   r   r   s       r&   r5   zQMNIST.download  s      	F
DOd3333t|DI67 	H 	HHC(do3GGGGG	H 	Hr(   r]   c                 6   | j         |         | j        |         }}t          j        |                                d          }| j        |                     |          }| j        rt          |d                   }| j        |                     |          }||fS )Nr_   r`   r   )	r-   r#   r   rc   rd   r3   r  rb   r4   re   s       r&   rh   zQMNIST.__getitem__  s    i&U(;Vociikk444>%..%%C; 	$^^F ,**622FF{r(   c                     d| j          S )Nr   )r  r$   s    r&   r   zQMNIST.extra_repr  s    $$$$r(   )NTTr   )ro   r   r   r   r  r   r   r   r   r	   __annotations__ry   r
   r   r   r   r   r9   r   r   r   r<   r>   r5   rb   rh   r   r   r   s   @r&   r  r  W  s         :  Fv_effG	
	
	
+3 3ItCeCHo../   @  G fj
0 
0#t)$
0,4SM
0JN
0^b
0ux
0	
0 
0 
0 
0 
0 
0 YS Y Y Y XY YS Y Y Y XY[t [ [ [ [  (H H H H
 
sCx 
 
 
 
%C % % % % % % % %r(   r  br6   c                 H    t          t          j        | d          d          S )Nhex   )rb   codecsencode)r&  s    r&   get_intr,    s    v}Q&&+++r(   )   	               TrD   strictc                 :  
 t          | d          5 }|                                
ddd           n# 1 swxY w Y   t          j        dk    r"t	          
dd                   }|dz  }|dz  }ngt	          
dd                   }t	          
dd                   t	          
dd	                   dz  z   t	          
d	d                   dz  dz  z   }d|cxk    rd	k    sn J d
|cxk    rdk    sn J t
          |         }
fdt          |          D             }t          j        dk    rZt          t          |                    D ]=}t          	                    ||         
                    dd          dd          ||<   >t          j        t          
          |d|dz   z            }	t          j        dk    r'|	                                dk    rt          |	          }	|	j        d         t#          j        |          k    s|rJ  |	j        | S )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littler         r   r  r  r-  r2  c           	      V    g | ]%}t          d |dz   z  d |dz   z                     &S )r7  r   r  )r,  )rG   ru   r-   s     r&   
<listcomp>z1read_sn3_pascalvincent_tensor.<locals>.<listcomp>  s;    EEEaa1q5kAQK/0	1	1EEEr(   big)	byteorderF)r<  signed)r  offset)openreadsysr<  r,  SN3_PASCALVINCENT_TYPEMAPrangerj   rb   
from_bytesto_bytesrQ   
frombuffer	bytearrayelement_sizer   shapenpprodview)rD   r3  fmagicndty
torch_typer   ru   parsedr-   s             @r&   r  r    sW   
 
dD		 Qvvxx               }  QqS	""S[c\T!A#YT!A#Y'$qs)"4"4s"::WT!A#Y=O=ORU=UX[=[[<<<<a<<<<<<====b======*2.JEEEE599EEEA
}s1vv 	g 	gA>>!A$--X-"F"FRW`e>ffAaDDiooZbSTfWWWF }  V%8%8%:%:Q%>%>!&))<?bgajj(((((6;?s   377c                    t          | d          }|j        t          j        k    rt	          d|j                   |                                dk    r$t          d|                                           |                                S )NFr3  ,x should be of dtype torch.uint8 instead of r   z%x should have 1 dimension instead of )r  r  rQ   r  r  r  r  r   rD   r   s     r&   rZ   rZ      s{    %d5999Aw%+PqwPPQQQ||~~QQQRRR6688Or(   c                     t          | d          }|j        t          j        k    rt	          d|j                   |                                dk    r$t          d|                                           |S )NFrT  rU  r  z%x should have 3 dimension instead of )r  r  rQ   r  r  r  r  rV  s     r&   rX   rX   )  ss    %d5999Aw%+PqwPPQQQ||~~QQQRRRHr(   )T)5r*  rC   os.pathr   r   rA  r!   pathlibr   typingr   r   r   r   r   r	   r
   urllib.errorr   rd   rJ  rQ   PILr   utilsr   r   r   r   r   visionr   r   r   r   r   r  bytesrb   r,  r  int8int16int32float32float64rB  r   r   Tensorr  rZ   rX   rt   r(   r&   <module>rf     s    				    



        D D D D D D D D D D D D D D D D D D ! ! ! ! ! !            s s s s s s s s s s s s s s ! ! ! ! ! !t! t! t! t! t!M t! t! t!ny y y y y5 y y y8K K K K KU K K K8Q# Q# Q# Q# Q#U Q# Q# Q#hS% S% S% S% S%U S% S% S%l,u , , , , ,
 {z  " " "T "U\ " " " "J# %,    # %,      r(   