
    h,                         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
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g)    N)Path)AnyCallableOptionalUnion   )default_loader)check_integritydownload_and_extract_archivedownload_urlverify_str_arg)VisionDatasetc                   
  ^  \ rS rSrSrSrSSSS.rSS	S
SSSSS.rSSSS.rSr	SSS\
4S\\\4   S\S\S\S\\   S\\   S\S\\/\4   SS4U 4S  jjjrS\4S! jrS)S" jrS#\S$\\\4   S\4S% jrS\4S& jrS\4S' jrS(rU =r$ )*_LFW
   zlfw-pyz http://vis-www.cs.umass.edu/lfw/)lfwzlfw.tgz a17d05bd522c52d84eca14327a23d494)lfw_funneledzlfw-funneled.tgz 1b42dfed7d15c9b2dd63d5e5840c86ad)zlfw-deepfunneledzlfw-deepfunneled.tgz 68331da3eb755a505a502b5aacb3c201)originalfunneleddeepfunneled 9f1ba174e4e1c508ff7cdf10ac338a7d 5132f7440eb68cf58910c8a45a2ac10b 4f27cbf15b2da4a85c1907eb4181ad21 450f0863dd89e85e73936a6d71a3474b e4bf5be0a43b5dcd9dc5ccfcb8fb19c5 54eaac34beb6d042ed3a7d883e247a21 a6d0a479bd074669f656265a6e693f6d)z	pairs.txtzpairsDevTest.txtzpairsDevTrain.txtz
people.txtzpeopleDevTest.txtzpeopleDevTrain.txtlfw-names.txt DevTrainDevTest10foldtraintestr!   NFrootsplit	image_setview	transformtarget_transformdownloadloaderreturnc	                   > [         T
U ]  [        R                  R	                  XR
                  5      XVS9  [        UR                  5       SU R                  R                  5       5      U l
        U R                  U R                     u  ol        U l        [        UR                  5       SSS/5      U l        [        UR                  5       S/ SQ5      U l        U R                   U R                  U R                      S3U l        / U l        U(       a  [%        S	5      eU R)                  5       (       d  [+        S
5      e[        R                  R	                  U R,                  U	5      U l        Xl        g )N)r-   r.   r+   r,   peoplepairsr*   r%   z.txtz|LFW dataset is no longer available for download.Please download the dataset manually and place it in the specified directoryzHDataset not found or corrupted. You can use download=True to download it)super__init__ospathjoinbase_folderr   lower	file_dictkeysr+   filenamemd5r,   r*   
annot_filelabels_filedata
ValueErrorr/   _check_integrityRuntimeErrorr)   
images_dir_loader)selfr)   r*   r+   r,   r-   r.   r/   r0   rF   	__class__s             P/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/datasets/lfw.pyr6   _LFW.__init__    s    	d,<,<=v'	(9;H[H[H]^.2nnT^^.L+
M48"4::<(G9LM	#EKKM7<WX
"ii[)D(ETJ!	_  $$&&ijj'',,tyy*=    c                 &   [        [        R                  R                  U R                  U R
                  5      U R                  5      n[        [        R                  R                  U R                  U R                  5      U R                  U R                     5      nU(       a  U(       d  gU R                  S:X  aU  [        [        R                  R                  U R                  U R                  5      U R                  U R                     5      $ g)NFr3   T)r
   r7   r8   r9   r)   r>   r?   rA   	checksumsr,   names)rH   st1st2s      rJ   rD   _LFW._check_integrityB   s    bggll499dmmDdhhObggll499d6F6FGX\XhXhIij#99 "277<<		4::#FW[WaWaHbccrL   c                    U R                  5       (       a  g U R                   U R                   3n[        XR                  U R                  U R
                  S9  [        U R                   U R                   3U R                  5        U R                  S:X  a/  [        U R                   U R                   3U R                  5        g g )N)r>   r?   r3   )
rD   download_url_prefixr>   r   r)   r?   r   rA   r,   rO   )rH   urls     rJ   r/   _LFW.downloadK   s      ""))*4==/:$S))dmmQUQYQYZ001$2B2B1CDdiiP99 D445djj\BDIIN !rL   identitynoc           	      v    [         R                  R                  U R                  X S[	        U5      S S35      $ )N_04dz.jpg)r7   r8   r9   rF   int)rH   rW   rX   s      rJ   	_get_path_LFW._get_pathT   s/    ww||DOOX1SWSMQU7VWWrL   c                 :    SU R                    SU R                   3$ )NzAlignment: z
Split: )r+   r*   rH   s    rJ   
extra_repr_LFW.extra_reprW   s    T^^,Idjj\BBrL   c                 ,    [        U R                  5      $ )N)lenrB   r`   s    rJ   __len___LFW.__len__Z   s    499~rL   )	rG   rB   r>   r+   rF   rA   r?   r*   r,   )r1   N)__name__
__module____qualname____firstlineno__r:   rT   r<   rN   r@   rO   r	   r   strr   r   r   boolr   r6   rD   r/   r\   r]   ra   re   __static_attributes____classcell__rI   s   @rJ   r   r   
   s8   K< K\hI 8>?8?@;I YGJE )-/3'5 CI    	 
   H%  #8,    #$  
   D$ OX# X5c? Xs XCC C  rL   r   c                      ^  \ rS rSrSrSSSSS\4S\S\S	\S
\\   S\\   S\	S\\/\
4   SS4U 4S jjjrS\\\   \\   4   4S jrS\\\4   4S jrS\S\\
\
4   4S jrS\4U 4S jjrSrU =r$ )	LFWPeople^   a  `LFW <http://vis-www.cs.umass.edu/lfw/>`_ Dataset.

.. warning:

    The LFW dataset is no longer available for automatic download. Please
    download it manually and place it in the specified directory.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where directory
        ``lfw-py`` exists or will be saved to if download is set to True.
    split (string, optional): The image split to use. Can be one of ``train``, ``test``,
        ``10fold`` (default).
    image_set (str, optional): Type of image funneling to use, ``original``, ``funneled`` or
        ``deepfunneled``. Defaults to ``funneled``.
    transform (callable, optional): A function/transform that takes in a PIL image or torch.Tensor, depends on the given loader,
        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): NOT SUPPORTED ANYMORE, leave to False.
    loader (callable, optional): A function to load an image given its path.
        By default, it uses PIL as its image loader, but users could also pass in
        ``torchvision.io.decode_image`` for decoding image data into tensors directly.
r&   r   NFr)   r*   r+   r-   r.   r/   r0   r1   c                    > [         TU ]  XUSXEXgS9  U R                  5       U l        U R	                  5       u  U l        U l        g )Nr3   r0   )r5   r6   _get_classesclass_to_idx_get_peoplerB   targets	rH   r)   r*   r+   r-   r.   r/   r0   rI   s	           rJ   r6   LFWPeople.__init__w   sF     	i9X`p --/"&"2"2"4	4<rL   c           	         / / p![        [        R                  R                  U R                  U R
                  5      5       nUR                  5       nU R                  S:X  a  [        US   5      S4OSu  pV[        U5       H  n[        XF   5      nXFS-   Xh-   S-     V	s/ s H!  oR                  5       R                  S5      PM#     n
n	XhS-   -  n[        U
5       Hg  u  nu  p[        S[        U5      S-   5       HC  nU R                  X5      nUR                  U5        UR                  U R                  U   5        ME     Mi     M     S S S 5        X4$ s  sn	f ! , (       d  f       X4$ = f)Nr&   r   r   )r   r   	)openr7   r8   r9   r)   rA   	readlinesr*   r\   rangestrip	enumerater]   appendrv   )rH   rB   rx   flinesn_foldssfoldn_linesliner3   irW   num_imgsnumimgs                   rJ   rw   LFWPeople._get_people   s=   Bg"'',,tyy$*:*:;<KKME/3zzX/E#eAh-+6JGgeh-?DUQ[[\_?]^?]t**,,,T2?]^q[ /8/@+A+$QH(9:"nnX;C(t'8'8'BC  ; 0A	 '	 = } _ =< }s    AE(EBEE
E*c                    [        [        R                  R                  U R                  U R
                  5      5       nUR                  5       nU Vs/ s H#  o3R                  5       R                  5       S   PM%     nnS S S 5        [        W5       VVs0 s H  u  pVXe_M	     nnnU$ s  snf ! , (       d  f       N4= fs  snnf )Nr   )
r}   r7   r8   r9   r)   rO   r~   r   r*   r   )rH   r   r   r   rO   r   namerv   s           rJ   ru   LFWPeople._get_classes   s    "'',,tyy$**56!KKME9>?ZZ\'')!,E? 7 09/?@/?GA/?@ @ 76 As#   B-*B(=B-B>(B--
B;indexc                     U R                  U R                  U   5      nU R                  U   nU R                  b  U R                  U5      nU R                  b  U R	                  U5      nX#4$ )zu
Args:
    index (int): Index

Returns:
    tuple: Tuple (image, target) where target is the identity of the person.
)rG   rB   rx   r-   r.   )rH   r   r   targets       rJ   __getitem__LFWPeople.__getitem__   se     ll499U+,e$>>%..%C  ,**62F{rL   c                 R   > [         TU ]  5       S[        U R                  5       3-   $ )Nz
Classes (identities): )r5   ra   rd   rv   )rH   rI   s    rJ   ra   LFWPeople.extra_repr   s*    w!#(@TEVEVAW@X&YYYrL   )rv   rB   rx   )rg   rh   ri   rj   __doc__r	   rk   r   r   rl   r   r6   tuplelistr\   rw   dictru   r   ra   rm   rn   ro   s   @rJ   rq   rq   ^   s    6 #(,/3'555 5 	5
 H%5 #8,5 5 #$5 
5 5U49d3i#78 $d38n  sCx &ZC Z ZrL   rq   c                      ^  \ rS rSrSrSSSSS\4S\S\S	\S
\\   S\\   S\	S\\/\
4   SS4U 4S jjjrS\S\\\\\4      \\\\4      \\   4   4S jrS\S\\
\
\4   4S jrSrU =r$ )LFWPairs   a  `LFW <http://vis-www.cs.umass.edu/lfw/>`_ Dataset.

.. warning:

    The LFW dataset is no longer available for automatic download. Please
    download it manually and place it in the specified directory.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where directory
        ``lfw-py`` exists or will be saved to if download is set to True.
    split (string, optional): The image split to use. Can be one of ``train``, ``test``,
        ``10fold``. Defaults to ``10fold``.
    image_set (str, optional): Type of image funneling to use, ``original``, ``funneled`` or
        ``deepfunneled``. Defaults to ``funneled``.
    transform (callable, optional): A function/transform that takes in a PIL image
        and returns a transformed version. E.g, ``transforms.RandomRotation``
    target_transform (callable, optional): A function/transform that takes in the
        target and transforms it.
    download (bool, optional): NOT SUPPORTED ANYMORE, leave to False.
    loader (callable, optional): A function to load an image given its path.
        By default, it uses PIL as its image loader, but users could also pass in
        ``torchvision.io.decode_image`` for decoding image data into tensors directly.

r&   r   NFr)   r*   r+   r-   r.   r/   r0   r1   c                    > [         TU ]  XUSXEXgS9  U R                  U R                  5      u  U l        U l        U l        g )Nr4   rt   )r5   r6   
_get_pairsrF   
pair_namesrB   rx   ry   s	           rJ   r6   LFWPairs.__init__   s=     	i)W_o37??4??3S0DLrL   rF   c           	      ~   / / / pCn[        [        R                  R                  U R                  U R
                  5      5       nUR                  5       nU R                  S:X  a,  US   R                  S5      u  px[        U5      [        U5      pOS[        US   5      pSn	[        U5       GHg  n
XiX-     Vs/ s H!  oR                  5       R                  S5      PM#     nnXiU-   U	SU-  -     Vs/ s H!  oR                  5       R                  S5      PM#     nnU	SU-  -  n	U Hr  nU R                  US   US   5      U R                  US   US   5      SnnnUR                  US   US   45        UR                  UU45        UR                  U5        Mt     U Hr  nU R                  US   US   5      U R                  US   US   5      SnnnUR                  US   US   45        UR                  UU45        UR                  U5        Mt     GMj     S S S 5        X#U4$ s  snf s  snf ! , (       d  f       N= f)Nr&   r   r|   r         )r}   r7   r8   r9   r)   rA   r~   r*   r\   r   r   r]   r   )rH   rF   r   rB   rx   r   r   r   n_pairsr   r   r   matched_pairsunmatched_pairspairimg1img2sames                     rJ   r   LFWPairs._get_pairs   s!   $&B'
"'',,tyy$*:*:;<KKMEzzX%#(8>>$#7 #&w<W#$c%(mAgFKPQP[F\ ]F\d!3!3D!9F\ ]HMRYk\]abelal\mHn"oHn::<#5#5d#;Hn"oQ[ )D'+~~d1gtAw'GX\]^X_aefgahIikl$D%%tAwQ&89KKt-NN4(	 *
 ,D'+~~d1gtAw'GX\]^X_aefgahIikl$D%%tAwQ&89KKt-NN4(	 , ' =0 (( !^"o =<s,   A5H.8(H$ H.1(H)C?H.$
H..
H<r   c                 $   U R                   U   u  p#U R                  U5      U R                  U5      p2U R                  U   nU R                  b!  U R                  U5      U R                  U5      p2U R                  b  U R	                  U5      nX#U4$ )z
Args:
    index (int): Index

Returns:
    tuple: (image1, image2, target) where target is `0` for different indentities and `1` for same identities.
)rB   rG   rx   r-   r.   )rH   r   r   r   r   s        rJ   r   LFWPairs.__getitem__   s     YYu%
\\$'d);de$>>%-t~~d/C$  ,**62F6!!rL   )rB   r   rx   )rg   rh   ri   rj   r   r	   rk   r   r   rl   r   r6   r   r   r\   r   r   rm   rn   ro   s   @rJ   r   r      s    8 #(,/3'5TT T 	T
 H%T #8,T T #$T 
T T)S )U4c3h3H$uUXZ]U]J_aefiaj3j-k )8" "sC})= " "rL   r   )r7   pathlibr   typingr   r   r   r   folderr	   utilsr
   r   r   r   visionr   r   rq   r    rL   rJ   <module>r      sK    	  1 1 " ^ ^ !Q= QhUZ UZpV"t V"rL   