
    QЦi                          S SK r S SKrS SKJr  S SKJr  S SKJrJrJ	r	J
r
JrJr  S SKrS SKrSSKJrJrJrJr  SSKJr  \" S/ S	Q5      r " S
 S\5      rg)    N)
namedtuple)Path)AnyCallableListOptionalTupleUnion   )check_integritydownload_file_from_google_driveextract_archiveverify_str_arg)VisionDatasetCSV)headerindexdatac                      ^  \ rS rSrSrSr/ SQr     SS\\\	4   S\S\\
\   \4   S	\\   S
\\   S\SS4U 4S jjjr SS\S\\   S\4S jjrS\4S jrSS jrS\S\\\4   4S jrS\4S jrS\4S jrSrU =r$ )CelebA   a  `Large-scale CelebFaces Attributes (CelebA) Dataset <http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html>`_ Dataset.

Args:
    root (str or ``pathlib.Path``): Root directory where images are downloaded to.
    split (string): One of {'train', 'valid', 'test', 'all'}.
        Accordingly dataset is selected.
    target_type (string or list, optional): Type of target to use, ``attr``, ``identity``, ``bbox``,
        or ``landmarks``. Can also be a list to output a tuple with all specified target types.
        The targets represent:

            - ``attr`` (Tensor shape=(40,) dtype=int): binary (0, 1) labels for attributes
            - ``identity`` (int): label for each person (data points with the same identity are the same person)
            - ``bbox`` (Tensor shape=(4,) dtype=int): bounding box (x, y, width, height)
            - ``landmarks`` (Tensor shape=(10,) dtype=int): landmark points (lefteye_x, lefteye_y, righteye_x,
              righteye_y, nose_x, nose_y, leftmouth_x, leftmouth_y, rightmouth_x, rightmouth_y)

        Defaults to ``attr``. If empty, ``None`` will be returned as target.

    transform (callable, optional): A function/transform that takes in a PIL image
        and returns a transformed version. E.g, ``transforms.PILToTensor``
    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.

        .. warning::

            To download the dataset `gdown <https://github.com/wkentaro/gdown>`_ is required.
celeba))0B7EVK8r0v71pZjFTYXZWM3FlRnM 00d2c5bc6d35e252742224ab0c1e8fcbimg_align_celeba.zip)0B7EVK8r0v71pblRyaVFSWGxPY0U 75e246fa4810816ffd6ee81facbd244clist_attr_celeba.txt)z!1_ee_0u7vcNLOfNLegJRHmolfH5ICW-XS 32bd1bd63d3c78cd57e08160ec5ed1e2identity_CelebA.txt)0B7EVK8r0v71pbThiMVRxWXZ4dU0 00566efa6fedff7a56946cd1c10f1c16list_bbox_celeba.txt)0B7EVK8r0v71pd0FJY3Blby1HUTQ cc24ecafdb5b50baae59b03474781f8clist_landmarks_align_celeba.txt)0B7EVK8r0v71pY0NSMzRuSXJEVkk d32c9cbf5e040fd4025c592c306e6668list_eval_partition.txtNrootsplittarget_type	transformtarget_transformdownloadreturnc                 p  > [         TU ]  XUS9  X l        [        U[        5      (       a  X0l        OU/U l        U R
                  (       d  U R                  b  [        S5      eU(       a  U R                  5         U R                  5       (       d  [        S5      eSSSS S.nU[        UR                  5       SS5         nU R                  S	5      n	U R                  S
5      n
U R                  SSS9nU R                  SSS9nU R                  SSS9nUc  [        S 5      OU	R                  U:H  R                  5       nU[        S 5      :X  a  U	R                   U l        OL[$        R                  " [$        R&                  " U5      5       Vs/ s H  oR                   U   PM     snU l        U
R                  U   U l        UR                  U   U l        UR                  U   U l        UR                  U   U l        [$        R0                  " U R.                  S-   SSS9U l        UR2                  U l        g s  snf )N)r-   r.   z6target_transform is specified but target_type is emptyzHDataset not found or corrupted. You can use download=True to download itr   r      )trainvalidtestallr+   r)   r    r#   )r   r&   r   floor)rounding_mode)super__init__r+   
isinstancelistr,   r.   RuntimeErrorr/   _check_integrityr   lower	_load_csvslicer   squeezer   filenametorchnonzeroidentitybboxlandmarks_alignattrdivr   
attr_names)selfr*   r+   r,   r-   r.   r/   	split_mapsplit_splitsrF   rG   rH   rI   maski	__class__s                   Z/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/celeba.pyr:   CelebA.__init__A   s    	EUV
k4((* +}DD$9$9$EWXXMMO$$&&ijj 	
	 >%++-Bcde 9:>>"78~~4Q~?..)JST.U~~4Q~?$nuT{6;;&3H2Q2Q2S5;"LLDM6;mmEMMRVDW6XY6X\\!_6XYDM d+IIdO	.33D9IIdO	IIdii!mQgF	++ Zs   	H3rC   r   c           	         [        [        R                  R                  U R                  U R
                  U5      5       n[        [        R                  " USSS95      nS S S 5        Ub  WU   nXBS-   S  nO/ nW Vs/ s H  ofS   PM	     nnU Vs/ s H  ofSS  PM	     nnU Vs/ s H  n[        [        [        U5      5      PM     n	n[        XW[        R                  " U	5      5      $ ! , (       d  f       N= fs  snf s  snf s  snf )N T)	delimiterskipinitialspacer   r   )openospathjoinr*   base_folderr<   csvreadermapintr   rD   tensor)
rL   rC   r   csv_filer   headersrowindicesrQ   data_ints
             rS   r@   CelebA._load_csvu   s    
 "'',,tyy$*:*:HEF(

8sTRSD G 6lG
%DG%)*Tcq6T*#'(4CAB4(/34t!DS!%t47U\\(%;<< GF +(4s    C*=C;D %#D*
C8c                    U R                    Hv  u  pn[        R                  R                  U R                  U R
                  U5      n[        R                  R                  U5      u  pUS;  d  Md  [        XB5      (       a  Mv    g   [        R                  R                  [        R                  R                  U R                  U R
                  S5      5      $ )N)z.zipz.7zFimg_align_celeba)		file_listrZ   r[   r\   r*   r]   splitextr   isdir)rL   _md5rC   fpathexts         rS   r>   CelebA._check_integrity   s    "&..QXGGLLD,<,<hGEWW%%h/FA /)/%2M2M #1 ww}}RWW\\$))T5E5EGYZ[[    c                 V   U R                  5       (       a  g U R                   HE  u  pn[        U[        R                  R                  U R                  U R                  5      X25        MG     [        [        R                  R                  U R                  U R                  S5      5        g )Nr   )	r>   rk   r   rZ   r[   r\   r*   r]   r   )rL   file_idro   rC   s       rS   r/   CelebA.download   ss      ""(,$W8+GRWW\\$))TM]M]5^`hn )7 	TYY0@0@BXYZrs   r   c           	      &   [         R                  R                  [        R                  R                  U R                  U R                  SU R                  U   5      5      n/ nU R                   H  nUS:X  a$  UR                  U R                  US S 24   5        M-  US:X  a"  UR                  U R                  US4   5        MU  US:X  a$  UR                  U R                  US S 24   5        M  US:X  a$  UR                  U R                  US S 24   5        M  [        SU S35      e   U R                   b  U R!                  U5      nU(       a@  [#        U5      S	:  a  [%        U5      OUS   nU R&                  b  U R'                  U5      nX#4$ S nX#4$ )
Nrj   rI   rF   r   rG   	landmarkszTarget type "z" is not recognized.r   )PILImagerY   rZ   r[   r\   r*   r]   rC   r,   appendrI   rF   rG   rH   
ValueErrorr-   lentupler.   )rL   r   Xtargetts        rS   __getitem__CelebA.__getitem__   sY   IINN277<<		43C3CEWY]YfYfglYmno!!AF{diiq12jdmmE1H56fdiiq12k!d225!8<= !=3G!HII " >>%q!A&)&kAoU6]6!9F$$0..v6 y Fyrs   c                 ,    [        U R                  5      $ N)r}   rI   )rL   s    rS   __len__CelebA.__len__   s    499~rs   c                 `    SS/nSR                  U5      R                  " S0 U R                  D6$ )NzTarget type: {target_type}zSplit: {split}
 )r\   format__dict__)rL   liness     rS   
extra_reprCelebA.extra_repr   s.    -/?@yy&&777rs   )rI   rK   rG   rC   rF   rH   r+   r,   )r3   rI   NNFr   )r0   N)__name__
__module____qualname____firstlineno____doc__r]   rk   r
   strr   r   r   r   boolr:   ra   r   r@   r>   r/   r	   r   r   r   r   __static_attributes____classcell__)rR   s   @rS   r   r      s   > KI  -3(,/32&CI2& 2& 49c>*	2&
 H%2& #8,2& 2& 
2& 2&n !%== = 
	=(
\$ 
\[ sCx < 8C 8 8rs   r   )r^   rZ   collectionsr   pathlibr   typingr   r   r   r   r	   r
   ry   rD   utilsr   r   r   r   visionr   r   r   r   rs   rS   <module>r      sA    
 	 "  > > 
  d d !34q8] q8rs   