
    ڧg?                        U 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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mZmZ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" dZ#dHd	e$d
ee$ej%        f         de&ddfdZ'dIdee$ej%        f         de&de$fdZ(dee$ej%        f         de$dede)fdZ*dJdee$ej%        f         dee$         de)fdZ+dKd	e$de&de$fdZ,d	e$dee$         fdZ-	 	 	 dLd	e$dee$ej%        f         d
eee$ej%        f                  dee$         de&ddfdZ.dMdee$ej%        f         de)dee$         fdZ/dMdee$ej%        f         de$de)dee$         fd Z0	 	 dNd!e$dee$ej%        f         d
eee$ej%        f                  dee$         fd"Z1d#ee$ej%        f         d$ee$ej%        f         d%ee$         ddfd&Z2ej3        ej4        d'Z5ee$e&f         e6d(<   d#ee$ej%        f         d$ee$ej%        f         d%ee$         ddfd)Z7e2e7d*Z8ee$eee$ej%        f         ee$ej%        f         ee$         gdf         f         e6d+<   e j9        ej9        ej9        d,Z:ee$ed-ef         f         e6d.<   d/d/d0d1Z;ee$eee$         ee$         f         f         e6d2<   d3ee$ej%        f         dee$ee$         ee$         f         fd4Z<	 	 dOd#ee$ej%        f         d$eee$ej%        f                  d5e)dej%        fd6Z=	 	 dOd#ee$ej%        f         d$eee$ej%        f                  d5e)dee$ej%        f         fd7Z>	 	 	 	 dPd	e$d8ee$ej%        f         d9eee$ej%        f                  d
eee$ej%        f                  dee$         d5e)ddfd:Z?d;ede$fd<Z@ ed=e$eA          ZB	 	 	 dQd>eBd?ee$         d@eeeB                  dAee$         deBf
dBZCdRdCee$ej%        f         dDe&dejD        fdEZEdFejF        dejF        fdGZGdS )S    N)
AnyCallableDictIOIterableListOptionalTupleTypeVarUnion)urlparse)tqdm   )#_download_file_from_remote_location_is_remote_location_availablezpytorch/vision   urlfilename
chunk_sizereturnc                 :   t           j                            t           j                            | dt          i                    5 }t          |d          5 }t          |j        dd          5 }|                    |          x}rN|	                    |           |
                    t          |                     |                    |          x}Nd d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )N
User-AgentheaderswbBT)totalunit
unit_scale)urllibrequesturlopenRequest
USER_AGENTopenr   lengthreadwriteupdatelen)r   r   r   responsefhpbarchunks          V/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/utils.py_urlretriever0      s   			 6 6s\S]D^ 6 _ _	`	` (dl(D!! 	(RHO#Z^)_)_)_ 	(cg#==444% (CJJ''' $==444% (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s[   DC8/A&C!C8!C%%C8(C%)C8,D8C<	<D?C<	 DDD   fpathc                 r   t           j        dk    rt          j        d          }nt          j                    }t	          | d          5 }|                    |          x}r,|                    |           |                    |          x},d d d            n# 1 swxY w Y   |                                S )N)   	   F)usedforsecurityrb)sysversion_infohashlibmd5r%   r'   r)   	hexdigest)r2   r   r;   fr.   s        r/   calculate_md5r>   #   s     6!!k%000kmm	eT		 avvj)))e 	JJu vvj)))e 	               ==??s   
ABB!Br;   kwargsc                 $    |t          | fi |k    S N)r>   )r2   r;   r?   s      r/   	check_md5rB   1   s    -000000    c                 l    t           j                            |           sdS |dS t          | |          S )NFT)ospathisfilerB   )r2   r;   s     r/   check_integrityrH   5   s7    7>>%   u
{tUC   rC   r4   max_hopsc           	      t   | }dt           d}t          |dz             D ]}t          j                            t          j                            | |                    5 }|j        | k    s|j        | cd d d            c S |j        } d d d            n# 1 swxY w Y   t          d| d| d|  d          )	NHEAD)Methodr      r   zRequest to z
 exceeded z( redirects. The last redirect points to .)r$   ranger    r!   r"   r#   r   RecursionError)r   rI   initial_urlr   _r+   s         r/   _get_redirect_urlrS   =   s3   Kz::G8a<   	
 	
^##FN$:$:3$:$P$PQQ 	U]|s""hl&:	 	 	 	 	 	 	 	 	 	 ,C		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 i+iiiicfiii
 
 	
s   BBB	B	c                     t          |           }t          j        d|j                  d S t          j        d|j                  }|d S |                    d          S )Nz(drive|docs)[.]google[.]comz/file/d/(?P<id>[^/]*)id)r   rematchnetlocrF   group)r   partsrW   s      r/   _get_google_drive_file_idr[   M   sW    SMME	x.==EtH-uz::E}t;;trC   rootmax_redirect_hopsc                    t           j                            |          }|st           j                            |           }t          j        t           j                            ||                    }t          j        |d           t          ||          rt          d|z              dS t                      rt          ||            nt          | |          } t          |           }|t          ||||          S 	 t          d| z   dz   |z              t          | |           nw# t          j        j        t$          f$ rY}| dd         d	k    r?|                     d
d          } t          d| z   dz   |z              t          | |           n|Y d}~nd}~ww xY wt          ||          st)          d          dS )a  Download a file from a url and place it in root.

    Args:
        url (str): URL to download file from
        root (str): Directory to place downloaded file in
        filename (str, optional): Name to save the file under. If None, use the basename of the URL
        md5 (str, optional): MD5 checksum of the download. If None, do not check
        max_redirect_hops (int, optional): Maximum number of redirect hops allowed
    Texist_okz$Using downloaded and verified file: N)rI   zDownloading  to    httpszhttps:zhttp:z;Failed download. Trying https -> http instead. Downloading File not found or corrupted.)rE   rF   
expanduserbasenamefspathjoinmakedirsrH   printr   r   rS   r[   download_file_from_google_driver0   r    errorURLErrorOSErrorreplaceRuntimeError)r   r\   r   r;   r]   r2   file_ides           r/   download_urlrs   Z   s     7d##D )7##C((Ibgll42233EKt$$$$ uc"" 4u<===$&& +E37777  .?@@@ ,C0027D(CPPP		.3&/%7888e$$$$%w/ 	 	 	2A2w'!!kk(G44SVYY\bbejjkkkS%(((( )((((		 5#&& ;9:::; ;s   (D* *FAFFFprefixc                      t           j                                         fdt          j                   D             }|du r fd|D             }|S )a  List all directories at a given root

    Args:
        root (str): Path to directory whose folders need to be listed
        prefix (bool, optional): If true, prepends the path to each result, otherwise
            only returns the name of the directories found
    c                     g | ]A}t           j                            t           j                            |                    ?|BS  )rE   rF   isdirrh   ).0pr\   s     r/   
<listcomp>zlist_dir.<locals>.<listcomp>   s=    WWW"'--TST@U@U2V2VW1WWWrC   Tc                 P    g | ]"}t           j                            |          #S rw   rE   rF   rh   ry   dr\   s     r/   r{   zlist_dir.<locals>.<listcomp>   s)    BBBrw||D!,,BBBrC   rE   rF   re   listdir)r\   rt   directoriess   `  r/   list_dirr      se     7d##DWWWWbj..WWWK~~BBBBkBBBrC   suffixc                      t           j                                         fdt          j                   D             }|du r fd|D             }|S )a  List all files ending with a suffix at a given root

    Args:
        root (str): Path to directory whose folders need to be listed
        suffix (str or tuple): Suffix of the files to match, e.g. '.png' or ('.jpg', '.png').
            It uses the Python "str.endswith" method and is passed directly
        prefix (bool, optional): If true, prepends the path to each result, otherwise
            only returns the name of the files found
    c                     g | ]V}t           j                            t           j                            |                    ?|                              T|WS rw   )rE   rF   rG   rh   endswith)ry   rz   r\   r   s     r/   r{   zlist_files.<locals>.<listcomp>   sQ    iii1BGNN27<<a;P;P,Q,QiVWV`V`agVhVhiQiiirC   Tc                 P    g | ]"}t           j                            |          #S rw   r}   r~   s     r/   r{   zlist_files.<locals>.<listcomp>   s)    6661dA&&666rC   r   )r\   r   rt   filess   ``  r/   
list_filesr      sh     7d##Diiiii
4((iiiE~~6666666LrC   rq   c                    	 ddl }n# t          $ r t          d          w xY wt          j                            |          }|s| }t          j        t          j                            ||                    }t          j        |d           t          ||          rt          d|rdnd d	|            dS |                    | |d
t                     t          ||          st          d          dS )af  Download a Google Drive file from  and place it in root.

    Args:
        file_id (str): id of file to be downloaded
        root (str): Directory to place downloaded file in
        filename (str, optional): Name to save the file under. If None, use the id of the file.
        md5 (str, optional): MD5 checksum of the download. If None, do not check
    r   Nz`To download files from GDrive, 'gdown' is required. You can install it with 'pip install gdown'.Tr_   zUsing downloaded zand verified  zfile: F)rU   outputquiet
user_agentrd   )gdownModuleNotFoundErrorrp   rE   rF   re   rg   rh   ri   rH   rj   downloadr$   )rq   r\   r   r;   r   r2   s         r/   rk   rk      s   
 
 
 
n
 
 	


 7d##D Ibgll42233EKt$$$$uc"" OS"@//bOOOOPPP	NNge5ZNPPP5#&& ;9:::; ;s    !	from_pathto_pathcompressionc                     t          j        | |rd|dd           nd          5 }|                    |           d d d            d S # 1 swxY w Y   d S )Nzr:rM   r)tarfiler%   
extractall)r   r   r   tars       r/   _extract_tarr      s     
i;!O!7k!""o!7!7!7C	P	P  TWw                                   s   AAA).bz2.xz_ZIP_COMPRESSION_MAPc                     t          j        | d|rt          |         nt           j                  5 }|                    |           d d d            d S # 1 swxY w Y   d S )Nr   )r   )zipfileZipFiler   
ZIP_STOREDr   )r   r   r   zips       r/   _extract_zipr      s     
3$l$8$E$EZaZl
 
 
  	w                                   s   AAA).tarz.zip_ARCHIVE_EXTRACTORS)r   .gzr   ._COMPRESSED_FILE_OPENERS)r   r   )r   r   )z.tbzz.tbz2z.tgz_FILE_TYPE_ALIASESfilec                    t          j        |           j        }|st          d|  d          |d         }|t          v r|gt          |         R S |t
          v r||dfS |t          v r1t          |          dk    r|d         }|t
          v r||z   ||fS |d|fS t          t          t                    t          t
                    z  t          t                    z            }t          d| d| d	          )
a  Detect the archive type and/or compression of a file.

    Args:
        file (str): the filename

    Returns:
        (tuple): tuple of suffix, archive type, and compression

    Raises:
        RuntimeError: if file has no suffix or suffix is not supported
    zFile 'zP' has no suffixes that could be used to detect the archive type and compression.NrM   z&Unknown compression or archive type: 'z'.
Known suffixes are: 'z'.)
pathlibPathsuffixesrp   r   r   r   r*   sortedset)r   r   r   suffix2valid_suffixess        r/   _detect_file_typer      s4    |D!!*H 
kTkkk
 
 	
 b\F ###4+F3444 $$$vt## )))x==1rlG ---'&88tV##C 233c:M6N6NNQTUmQnQnnooN
sssaosss
t
ttrC   remove_finishedc                 &   t          |           \  }}}|st          d| d          |>t          j        t	          j        |                               |||nd                    }t          |         } || d          5 }t          |d          5 }|	                    |
                                           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |rt	          j        |            t          j        |          S )a  Decompress a file.

    The compression is automatically detected from the file name.

    Args:
        from_path (str): Path to the file to be decompressed.
        to_path (str): Path to the decompressed file. If omitted, ``from_path`` without compression extension is used.
        remove_finished (bool): If ``True``, remove the file after the extraction.

    Returns:
        (str): Path to the decompressed file.
    z*Couldn't detect a compression from suffix rN   Nr   r7   r   )r   rp   r   r   rE   rg   ro   r   r%   r(   r'   remove)	r   r   r   r   archive_typer   compressed_file_openerrfhwfhs	            r/   _decompressr   )  s   " ):)(D(D%FL+ SQQQQRRR,ry33;;FT`TlLLrtuuvv 6kB			4	0	0 Cgt9L9L PS		#((**                               
	)<   s6   C(C;CC	CC	CC"%C"c           
      B    dt           j        dt          t          t           j        f         f fd}|t          j                                       }t                     \  }}}|slt           t          j        	                    |t          j        
                                                   |d                    |          } ||          S t          |         } | ||           |rt	          j                     |t          j        |                    S )aD  Extract an archive.

    The archive type and a possible compression is automatically detected from the file name. If the file is compressed
    but not an archive the call is dispatched to :func:`decompress`.

    Args:
        from_path (str): Path to the file to be extracted.
        to_path (str): Path to the directory the file will be extracted to. If omitted, the directory of the file is
            used.
        remove_finished (bool): If ``True``, remove the file after the extraction.

    Returns:
        (str): Path to the directory the file was extracted to.
    ret_pathr   c                 Z    t          t                    rt          j        |           S | S rA   )
isinstancestrrE   rg   )r   r   s    r/   path_or_strz$extract_archive.<locals>.path_or_stra  s*    i%% 	9X&&&OrC   Nr   )r   )r   r   r   r   rE   rF   dirnamer   r   rh   rf   ro   r   r   )	r   r   r   r   r   r   r   r   	extractors	   `        r/   extract_archiver   M  s$   (gl uS',5F/G       '//),,(9)(D(D%FL+ %GLL"'"2"29"="="E"Efb"Q"QRR+
 
 

 {8$$$ $L1IIi+... 
	);w|G,,---rC   download_rootextract_rootc                 >   t           j                            |          }||}|st           j                            |           }t	          | |||           t           j                            ||          }t          d| d|            t          |||           d S )NzExtracting ra   )rE   rF   re   rf   rs   rh   rj   r   )r   r   r   r   r;   r   archives          r/   download_and_extract_archiver   }  s     G&&}55M$ )7##C((mXs333gll=(33G	
3
3
3\
3
3444G\?;;;;;rC   iterablec                 L    dd                     d | D                       z   dz   S )N'z', 'c                 ,    g | ]}t          |          S rw   )r   )ry   items     r/   r{   z#iterable_to_str.<locals>.<listcomp>  s    ===Dc$ii===rC   )rh   )r   s    r/   iterable_to_strr     s-    ==H===>>>DDrC   Tvalueargvalid_values
custom_msgc                 *   t          | t                    s:|d}nd}|                    t          |           |          }t	          |          || S | |vr;||}n'd}|                    | |t          |                    }t	          |          | S )Nz'Expected type str, but got type {type}.z:Expected type str for argument {arg}, but got type {type}.)typer   zPUnknown value '{value}' for argument {arg}. Valid values are {{{valid_values}}}.)r   r   r   )r   r   formatr   
ValueErrorr   )r   r   r   r   msgs        r/   verify_str_argr     s     eS!! ;;CCNCjjd5kksj33ooL  !CCdC**5cP\@]@]*^^CooLrC   	file_nameslice_channelsc                 "   t          | d          5 }|                                                                }|dvrt          d          t	          j        d|                                          }|st          d          d |                                D             \  }}t          |                                                                          }|dk     rd}| }nd	}t          j
        ||d
z             }	ddd           n# 1 swxY w Y   |dk    rdnd}
|	                    |||
                              ddd          }	t          j        |	d          }	|	d|ddddf         }	|	                    t          j                  S )aD  Read file in .pfm format. Might contain either 1 or 3 channels of data.

    Args:
        file_name (str): Path to the file.
        slice_channels (int): Number of channels to slice out of the file.
            Useful for reading different data formats stored in .pfm files: Optical Flows, Stereo Disparity Maps, etc.
    r7   )   PFs   PfzInvalid PFM files   ^(\d+)\s(\d+)\s$zMalformed PFM header.c              3   4   K   | ]}t          |          V  d S rA   )int)ry   dims     r/   	<genexpr>z_read_pfm.<locals>.<genexpr>  s(      77SC777777rC   r   <>r=   )dtypeNr   r4   rM   r   )axis)r%   readlinerstripr   rV   rW   	Exceptiongroupsfloatnpfromfilereshape	transposeflipastypefloat32)r   r   r=   header	dim_matchwhscaleendiandatapfm_channelss              r/   	_read_pfmr     s    
i		 2!$$&&''/000H11::<<@@	 	5344477I$4$4$6$67771ajjll))++,,199FFEEF{1FSL111#2 2 2 2 2 2 2 2 2 2 2 2 2 2 2& %11QL<<1l++55aA>>D74a   DAAA%&D;;rz"""s   C-D

DDtc                 6     |                                                      t          j                  j        g | j        |                                 R                      d          j        g | j        d d         dR                      | j                  S )Nr   )
contiguousviewtorchuint8shapeelement_sizer   r   )r   s    r/   _flip_byte_orderr    s    W-EK((-IqwI8H8HIIINNrRRWjYZY`adbdadYejgijjjoopqpwxxrC   )r   )r1   rA   )r4   )NNr4   )F)NN)NF)NNNF)NNN)r   )Hbz2gzipr:   lzmarE   os.pathr   rV   r8   r   r    urllib.errorurllib.requestr   typingr   r   r   r   r   r   r	   r
   r   r   urllib.parser   numpyr   r  torch.utils.model_zoor   _internally_replaced_utilsr   r   r$   r   r   r   r0   r>   boolrB   rH   rS   r[   rs   r   r   rk   r   	ZIP_BZIP2ZIP_LZMAr   __annotations__r   r   r%   r   r   r   r   r   r   r   bytesr   r   ndarrayr   Tensorr  rw   rC   r/   <module>r     sl   




    				   				 



            [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ ! ! ! ! ! !      & & & & & & k k k k k k k k
( (c (U3+<%= (3 (_c ( ( ( ( sGL01 s UX    1U3,- 1C 13 14 1 1 1 1! !5gl!23 !(3- !SW ! ! ! !
 
3 
# 
c 
 
 
 
 
3 
8C= 
 
 
 
  485; 5;	5;
W\!
"5; uS',./05; 
#	5;
 5; 
5; 5; 5; 5;p 5gl*+ T d3i     U3,- s D UYZ]U^    ( 48	#; #;#;
W\!
"#; uS',./0#; 
#	#; #; #; #;L S',&' 27W\8I2J YabeYf 	        ( ( d38n    S',&' 27W\8I2J YabeYf 	        w w T#xsGL/@)A5glIZC[]efi]j(kmq(qrrs   
 H99: : $sHS"W$556    F F DeHSM8C=$@AAB   (uE#w|"34 (usHSMS[\_S`?`9a (u (u (u (uZ 37!!! !!S',&'!!eC-./!! !! \	!! !! !! !!L 37!-. -.S',&'-.eC-./-. -. 3	-. -. -. -.f 8<37!< <	<gl*+< 5gl!234< uS',./0	<
 
#< < 
< < < <*Eh E3 E E E E GCe
 *. $	 	# 8A;' 	
    8!# !#sGL01 !#3 !#rz !# !# !# !#H       rC   