
    QЦiz>                     2   % 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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JrJrJrJrJr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"  Sr#SDS\$S	\\$\RJ                  4   S
\&SS4S jjr'SES\\$\RJ                  4   S
\&S\$4S jjr(S\\$\RJ                  4   S\$S\S\)4S jr*SFS\\$\RJ                  4   S\\$   S\)4S jjr+SGS\$S\&S\$4S jjr,S\$S\\$   4S jr-   SHS\$S\\$\RJ                  4   S	\\\$\RJ                  4      S\\$   S\&SS4S jjr.SIS\\$\RJ                  4   S\)S\\$   4S jjr/SIS\\$\RJ                  4   S\$S\)S\\$   4S jjr0  SJS\$S\\$\RJ                  4   S	\\\$\RJ                  4      S\\$   4S jjr1S\\$\RJ                  4   S \\$\RJ                  4   S!\\$   SS4S" jr2\Rf                  \Rh                  S#.r5\\$\&4   \6S$'   S\\$\RJ                  4   S \\$\RJ                  4   S!\\$   SS4S% jr7\2\7S&.r8\\$\\\$\RJ                  4   \\$\RJ                  4   \\$   /S4   4   \6S''   \ Rr                  \Rr                  \Rr                  S(.r:\\$\S)\4   4   \6S*'   S+S+S,S-.r;\\$\\\$   \\$   4   4   \6S.'   S/\\$\RJ                  4   S\\$\\$   \\$   4   4S0 jr<  SKS\\$\RJ                  4   S \\\$\RJ                  4      S1\)S\RJ                  4S2 jjr=  SKS\\$\RJ                  4   S \\\$\RJ                  4      S1\)S\\$\RJ                  4   4S3 jjr>    SLS\$S4\\$\RJ                  4   S5\\\$\RJ                  4      S	\\\$\RJ                  4      S\\$   S1\)SS4S6 jjr?S7\S\$4S8 jr@\" S9\$\A5      rB   SMS:\BS;\\$   S<\\\B      S=\\$   S\B4
S> jjrCSNS?\\$\RJ                  4   S@\&S\R                  4SA jjrESB\R                  S\R                  4SC jrGg)O    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                    [         R                  R                  [         R                  R                  U S[        0S95       n[        US5       n[        UR                  SSS9 nUR                  U5      =n(       aE  UR                  U5        UR                  [        U5      5        UR                  U5      =n(       a  ME  S S S 5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       N(= f! , (       d  f       g = f)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          Y/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/utils.py_urlretriever/      s    			 6 6s\S]D^ 6 _	`dl(D!RHOO#Z^)_cg#==44%4CJ' $==44%4 *`! 
a	`)_)_!! 
a	`s=   C>C-%ACC-C>
C*&C--
C;	7C>>
Dfpathc                    [         R                  S:  a  [        R                  " SS9nO[        R                  " 5       n[	        U S5       nUR                  U5      =n(       a+  UR                  U5        UR                  U5      =n(       a  M+  S S S 5        UR                  5       $ ! , (       d  f       UR                  5       $ = f)N)   	   F)usedforsecurityrb)sysversion_infohashlibmd5r$   r&   r(   	hexdigest)r0   r   r9   fr-   s        r.   calculate_md5r<   #   s     6!kk%0kkm	eT	avvj))e)JJu vvj))e) 
 ==? 
	 ==?s   AB''
Cr9   kwargsc                      U[        U 40 UD6:H  $ N)r<   )r0   r9   r=   s      r.   	check_md5r@   1   s    -0000    c                 j    [         R                  R                  U 5      (       d  gUc  g[        X5      $ )NFT)ospathisfiler@   )r0   r9   s     r.   check_integrityrF   5   s+    77>>%  
{U  rA   max_hopsc           	         U nS[         S.n[        US-   5       H|  n[        R                  R	                  [        R                  R                  XS95       nUR                  U :X  d  UR                  c  U sS S S 5        s  $ UR                  n S S S 5        M~     [        SU SU SU  S35      e! , (       d  f       M  = f)	NHEAD)Methodr      r   zRequest to z
 exceeded z( redirects. The last redirect points to .)r#   ranger   r    r!   r"   r   RecursionError)r   rG   initial_urlr   _r*   s         r.   _get_redirect_urlrQ   =   s    Kz:G8a< ^^##FNN$:$:3$:$PQU]||s"hll&: RQ ,,C	 RQ ! +j
:bcfbgghi
 	
 RQs   B/B//
B>	c                     [        U 5      n[        R                  " SUR                  5      c  g [        R                  " SUR                  5      nUc  g UR                  S5      $ )Nz(drive|docs)[.]google[.]comz/file/d/(?P<id>[^/]*)id)r   rematchnetlocrD   group)r   partsrU   s      r.   _get_google_drive_file_idrY   M   sP    SME	xx.=EHH-uzz:E};;trA   rootmax_redirect_hopsc                    [         R                  R                  U5      nU(       d  [         R                  R                  U 5      n[         R                  " [         R                  R                  X5      5      n[         R                  " USS9  [        XS5      (       a  g[        5       (       a  [        XP5        O/[        XS9n [        U 5      nUb  [        XaX#5      $  [        X5        [        XS5      (       d  ['        S	5      eg! [        R                  R                   ["        4 a2  nU SS S:X  a"  U R%                  SS5      n [        X5         SnANkUeSnAff = f)
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_okN)rG      httpszhttps:zhttp:File not found or corrupted.)rC   rD   
expanduserbasenamefspathjoinmakedirsrF   r   r   rQ   rY   download_file_from_google_driver/   r   errorURLErrorOSErrorreplaceRuntimeError)r   rZ   r   r9   r[   r0   file_ides           r.   download_urlro   Z   s     77d#D77##C(IIbggll423EKKt$ u""$&&+E7  @ ,C027(PP	$ 5&&9:: ' %%w/ 	2Aw'!kk(G4S((	s   D $E)&EEEprefixc           	         [         R                  R                  U 5      n [         R                  " U 5       Vs/ s HH  n[         R                  R	                  [         R                  R                  X5      5      (       d  MF  UPMJ     nnUSL a/  U Vs/ s H"  n[         R                  R                  X5      PM$     nnU$ s  snf s  snf )zList 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
T)rC   rD   rb   listdirisdirre   )rZ   rp   pdirectoriesds        r.   list_dirrw      s     77d#D jj.W."''--T@U2V1.KW~6ABkrww||D,kB XBs   AB?B?)Csuffixc           	         [         R                  R                  U 5      n [         R                  " U 5       Vs/ s H`  n[         R                  R	                  [         R                  R                  X5      5      (       d  MF  UR                  U5      (       d  M^  UPMb     nnUSL a/  U Vs/ s H"  n[         R                  R                  X5      PM$     nnU$ s  snf s  snf )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
T)rC   rD   rb   rr   rE   re   endswith)rZ   rx   rp   rt   filesrv   s         r.   
list_filesr|      s     77d#D

4(i(1BGGNN277<<;P,QQVWV`V`agVhQ(Ei~0561d&6L j6s   ACCC*)Crm   c                     SSK n[        R                  R                  U5      nU(       d  U n[        R                  " [        R                  R                  X5      5      n[        R                  " USS9  [        XS5      (       a  gUR                  XS[        S9  [        XS5      (       d  [        S5      eg! [         a    [        S5      ef = f)	aN  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]   F)rS   outputquiet
user_agentra   )gdownModuleNotFoundErrorrl   rC   rD   rb   rd   re   rf   rF   downloadr#   )rm   rZ   r   r9   r   r0   s         r.   rg   rg      s    
 77d#DIIbggll423EKKt$u""	NNg5ZNP5&&9:: '#  
n
 	

s   B8 8C	from_pathto_pathcompressionc                     [         R                  " X(       a  SUSS   3OS5       nUR                  U5        S S S 5        g ! , (       d  f       g = f)Nzr:rK   r)tarfiler$   
extractall)r   r   r   tars       r.   _extract_tarr      s@     
i;2k!"o%6!7C	PTWw 
Q	P	Ps   A
A).bz2.xz_ZIP_COMPRESSION_MAPc                     [         R                  " U SU(       a	  [        U   O[         R                  S9 nUR	                  U5        S S S 5        g ! , (       d  f       g = f)Nr   )r   )zipfileZipFiler   
ZIP_STOREDr   )r   r   r   zips       r.   _extract_zipr      sG     
3$8$EZaZlZl
	w
 
 
s   A
A).tarz.zip_ARCHIVE_EXTRACTORS)r   .gzr   ._COMPRESSED_FILE_OPENERS)r   r   )r   r   )z.tbzz.tbz2z.tgz_FILE_TYPE_ALIASESfilec                    [         R                  " U 5      R                  nU(       d  [        SU  S35      eUS   nU[        ;   a  U/[        U   Q7$ U[
        ;   a  X"S4$ U[        ;   a)  [        U5      S:  a  US   nU[
        ;   a  X2-   X24$ USU4$ [        [        [        5      [        [
        5      -  [        [        5      -  5      n[        SU SU S	35      e)
zDetect 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.NrK   z&Unknown compression or archive type: 'z'.
Known suffixes are: 'z'.)
pathlibPathsuffixesrl   r   r   r   r)   sortedset)r   r   rx   suffix2valid_suffixess        r.   _detect_file_typer      s    ||D!**HTFjk
 	
 b\F ##4+F344 $$t## ))x=1rlG --'88tV##C 23c:M6NNQTUmQnnoN
?xG`ao`pprs
ttrA   remove_finishedc                    [        U 5      u  p4nU(       d  [        SU S35      eUc>  [        R                  " [        R
                  " U 5      R                  X4b  UOS5      5      n[        U   nU" U S5       n[        US5       nUR                  UR                  5       5        SSS5        SSS5        U(       a  [        R                  " U 5        [        R                  " U5      $ ! , (       d  f       NI= f! , (       d  f       NR= f)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 rL   N r5   r   )r   rl   r   r   rC   rd   rk   r   r$   r'   r&   remove)	r   r   r   rx   archive_typer   compressed_file_openerrfhwfhs	            r.   _decompressr   %  s    " ):)(D%F+GxqQRR,,ryy3;;FTlLrtuv 6kB		4	0Cgt9LPS		#((* :M	0 
		)<<   :M9L	0	0s$   8C9 C(%C9(
C6	2C99
Dc           
      .  ^  S[         R                  S[        [        [         R                  4   4U 4S jjnUc  [        R
                  R                  T 5      n[        T 5      u  pEnU(       d^  [        T [        R
                  R                  U[        R
                  R                  T 5      R                  US5      5      US9nU" U5      $ [        U   nU" T X5        U(       a  [        R                  " T 5        U" [         R                  " U5      5      $ )a  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                 ^   > [        T[        5      (       a  [        R                  " U 5      $ U $ r?   )
isinstancestrrC   rd   )r   r   s    r.   path_or_str$extract_archive.<locals>.path_or_str]  s$    i%%99X&&OrA   r   )r   )r   r   r   r   rC   rD   dirnamer   r   re   rc   rk   r   r   )	r   r   r   r   rx   r   r   r   	extractors	   `        r.   extract_archiver   I  s    (gll uS',,5F/G  ''//),(9)(D%F+GGLL"''"2"29"="E"Efb"QR+

 8$$ $L1Ii.
		)w||G,--rA   download_rootextract_rootc                    [         R                  R                  U5      nUc  UnU(       d  [         R                  R                  U 5      n[	        XX45        [         R                  R                  X5      n[        XbU5        g r?   )rC   rD   rb   rc   ro   re   r   )r   r   r   r   r9   r   archives          r.   download_and_extract_archiver   y  s`     GG&&}5M$77##C(X3ggll=3GG?;rA   iterablec           	      n    SSR                  U  Vs/ s H  n[        U5      PM     sn5      -   S-   $ s  snf )N'z', ')re   r   )r   items     r.   iterable_to_strr     s1    H=HDc$iH=>>DD=s   2
Tvalueargvalid_values
custom_msgc                     [        U [        5      (       d,  Uc  SnOSnUR                  [        U 5      US9n[	        U5      eUc  U $ X;  a,  Ub  UnOSnUR                  X[        U5      S9n[	        U5      eU $ )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!!;;CNCjjd5ksj3o !CdC**5P\@]*^CoLrA   	file_nameslice_channelsc                    [        U S5       nUR                  5       R                  5       nUS;  a  [        S5      e[        R
                  " SUR                  5       5      nU(       d  [        S5      eS UR                  5        5       u  pV[        UR                  5       R                  5       5      nUS:  a  SnU* nOS	n[        R                  " X(S
-   S9n	SSS5        WS:X  a  SOSn
W	R                  WWU
5      R                  SSS5      n	[        R                  " U	SS9n	U	SU2SS2SS24   n	U	R                  [        R                  5      $ ! , (       d  f       N~= f)a0  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.
r5   )   PFs   PfzInvalid PFM files   ^(\d+)\s(\d+)\s$zMalformed PFM header.c              3   8   #    U  H  n[        U5      v   M     g 7fr?   )int).0dims     r.   	<genexpr>_read_pfm.<locals>.<genexpr>  s     7$6SC$6s   r   <>r;   )dtypeNr   r2   rK   r   )axis)r$   readlinerstripr   rT   rU   	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	!$$&'/00HH11::<@	3447I$4$4$67ajjl))+,19FFEF{{1SL1# 
& %1QL<<1l+55aA>D774a DA%&D;;rzz""1 
	s   CE
Etc                 >   U R                  5       R                  [        R                  5      R                  " / U R                  QU R                  5       P76 R                  S5      R                  " / U R                  S S QSP76 R                  U R                  5      $ )Nr   )
contiguousviewtorchuint8shapeelement_sizer   r   )r   s    r.   _flip_byte_orderr     s~    	EKK(--IqwwI8HINNrRWWjYZY`Y`adbdYejgijoopqpwpwxrA   )i   )i   r?   )r2   )NNr2   )F)NN)NF)NNNF)NNN)r   )Hbz2gzipr8   lzmarC   os.pathr   rT   r6   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   r/   r<   boolr@   rF   rQ   rY   ro   rw   r|   rg   r   	ZIP_BZIP2ZIP_LZMAr   __annotations__r   r   r$   r   r   r   r   r   r   r   bytesr   r   ndarrayr   Tensorr    rA   r.   <module>r     s   
    	   	 
      [ [ [ !   & k
(c (U3+<%= (3 (_c (sGLL01 s UX 1U3,- 1C 13 14 1!5gll!23 !(3- !SW !
3 
# 
c 
 
3 
8C= 
  482;	2;
W\\!
"2; uS',,./02; 
#	2;
 2; 
2;j5gll*+ T d3i U3,- s D UYZ]U^ ( 48	";";
W\\!
""; uS',,./0"; 
#	";J S',,&' 27W\\8I2J YabeYf 	  ( d38n  S',,&' 27W\\8I2J YabeYf 	  w T#xsGLL/@)A5gllIZC[]efi]j(kmq(qrrs 
 HH9999: $sHS"W$556  F DeHSM8C=$@AAB (uE#w||"34 (usHSMS[\_S`?`9a (uZ 37!!!S',,&'!!eC-./!! !! \\	!!L 37!-.S',,&'-.eC-./-. -. 3	-.f 8<37!<	<gll*+< 5gll!234< uS',,./0	<
 
#< < 
<(Eh E3 E Ce
 *. $		# 8A;' 	
 8!#sGLL01 !#3 !#rzz !#H  rA   