
    Yh^!                         d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlZd dlZddlmZmZmZmZ ddlmZ  edg d	          Z G d
 de          ZdS )    N)
namedtuple)Path)AnyCallableOptionalUnion   )check_integritydownload_file_from_google_driveextract_archiveverify_str_arg)VisionDatasetCSV)headerindexdatac                       e Zd ZdZdZg dZ	 	 	 	 	 ddeeef         d	ed
ee	e         ef         de
e         de
e         deddf fdZ	 ddede
e         defdZdefdZddZdedeeef         fdZdefdZdefdZ xZS )CelebAa  `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.txttrainattrNFrootsplittarget_type	transformtarget_transformdownloadreturnc                    t                                          |||           || _        t          |t                    r|| _        n|g| _        | j        s| j        t          d          |r|                                  | 	                                st          d          dddd d}|t          t          |t                    r|                                n|dd                   }|                     d	          |                     d
          }	|                     dd          }
|                     dd          }|                     dd          }|t          d           nj        |k                                    }|t          d           k    rj        | _        n7fdt'          j        t'          j        |                    D             | _        |	j        |         | _        |
j        |         | _        |j        |         | _        |j        |         | _        t'          j        | j        dz   dd          | _        |j        | _        d S )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	      )r'   validtestallr*   r&   r   r    )r   r#   r   c                 *    g | ]}j         |         S  )r   ).0isplitss     m/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torchvision/datasets/celeba.py
<listcomp>z#CelebA.__init__.<locals>.<listcomp>r   s    YYYV\!_YYY    floor)rounding_mode)super__init__r*   
isinstancelistr+   r-   RuntimeErrorr.   _check_integrityr   strlower	_load_csvslicer   squeezer   filenametorchnonzeroidentitybboxlandmarks_alignr(   divr   
attr_names)selfr)   r*   r+   r,   r-   r.   	split_mapsplit_rM   rN   rO   r(   maskr9   	__class__s                 @r:   r@   zCelebA.__init__A   sE    	EUVVV
k4(( 	-*D +}D 	YD$9$EWXXX 	MMOOO$$&& 	kijjj 	
 
	 !+E3!7!7BU1 
  9::>>"788~~4Q~??..)JST.UU~~4Q~??$nuT{{{6;&3H2Q2Q2S2S5;;"LDMMYYYYemEMRVDWDW6X6XYYYDM d+IdO	.3D9IdO	Idi!mQgFFF	+r<   rJ   r   c                    t          t          j                            | j        | j        |                    5 }t          t          j        |dd                    }d d d            n# 1 swxY w Y   |||         }||dz   d          }ng }d |D             }d |D             }d |D             }t          ||t          j        |                    S )N T)	delimiterskipinitialspacer	   c                     g | ]
}|d          S )r   r6   r7   rows     r:   r;   z$CelebA._load_csv.<locals>.<listcomp>   s    ***c3q6***r<   c                 "    g | ]}|d d         S )r	   Nr6   r\   s     r:   r;   z$CelebA._load_csv.<locals>.<listcomp>   s     (((CABB(((r<   c                 R    g | ]$}t          t          t          |                    %S r6   )rB   mapint)r7   r8   s     r:   r;   z$CelebA._load_csv.<locals>.<listcomp>   s(    444!DS!%%444r<   )openospathjoinr)   base_folderrB   csvreaderr   rK   tensor)rR   rJ   r   csv_filer   headersindicesdata_ints           r:   rG   zCelebA._load_csv{   s(   
 "',,ty$*:HEEFF 	T(
8sTRRRSSD	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 6lG
%DDG**T***((4(((44t4447GU\(%;%;<<<s   %A**A.1A.c                 v   | j         D ]j\  }}}t          j                            | j        | j        |          }t          j                            |          \  }}|dvrt          ||          s dS kt          j                            t          j                            | j        | j        d                    S )N)z.zipz.7zFimg_align_celeba)		file_listrc   rd   re   r)   rf   splitextr
   isdir)rR   _md5rJ   fpathexts         r:   rD   zCelebA._check_integrity   s     $ 	 	AsHGLLD,<hGGEW%%h//FAs /))/%2M2M)uu w}}RW\\$)T5EGYZZ[[[r<   c                 2   |                                  rd S | j        D ]@\  }}}t          |t          j                            | j        | j                  ||           At          t          j                            | j        | j        d                     d S )Nr   )	rD   rp   r   rc   rd   re   r)   rf   r   )rR   file_idrt   rJ   s       r:   r.   zCelebA.download   s      "" 	F&*n 	o 	o"GS(+GRW\\$)TM]5^5^`hjmnnnnTY0@BXYYZZZZZr<   r   c           	         t           j                            t          j                            | j        | j        d| j        |                             }g }| j	        D ]}|dk    r%|
                    | j        |d d f                    -|dk    r#|
                    | j        |df                    V|dk    r%|
                    | j        |d d f                    |dk    r%|
                    | j        |d d f                    t          d| d          | j        |                     |          }|rGt#          |          d	k    rt%          |          n|d         }| j        |                     |          }nd }||fS )
Nro   r(   rM   r   rN   	landmarkszTarget type "z" is not recognized.r	   )PILImagerb   rc   rd   re   r)   rf   rJ   r+   appendr(   rM   rN   rO   
ValueErrorr,   lentupler-   )rR   r   Xtargetts        r:   __getitem__zCelebA.__getitem__   s   INN27<<	43CEWY]YfglYmnnoo! 	J 	JAF{{diqqq12222jdmE1H56666fdiqqq12222k!!d25!!!8<==== !!H!H!H!HIII>%q!!A 	&)&kkAooU6]]]6!9F$0..v66F&yr<   c                 *    t          | j                  S N)r   r(   )rR   s    r:   __len__zCelebA.__len__   s    49~~r<   c                 T    ddg} d                     |          j        di | j        S )NzTarget type: {target_type}zSplit: {split}
r6   )re   format__dict__)rR   liness     r:   
extra_reprzCelebA.extra_repr   s4    -/?@&tyy&77777r<   )r'   r(   NNFr   )r/   N)__name__
__module____qualname____doc__rf   rp   r   rE   r   rB   r   r   boolr@   ra   r   rG   rD   r.   r   r   r   r   r   __classcell__)rV   s   @r:   r   r      s        > K  I  -3(,/38& 8&CI8& 8& 49c>*	8&
 H%8& #8,8& 8& 
8& 8& 8& 8& 8& 8&z !%= == = 
	= = = =(
\$ 
\ 
\ 
\ 
\[ [ [ [ sCx    <    8C 8 8 8 8 8 8 8 8r<   r   )rg   rc   collectionsr   pathlibr   typingr   r   r   r   r{   rK   utilsr
   r   r   r   visionr   r   r   r6   r<   r:   <module>r      s    



 				 " " " " " "       1 1 1 1 1 1 1 1 1 1 1 1 



  d d d d d d d d d d d d ! ! ! ! ! !j33344w8 w8 w8 w8 w8] w8 w8 w8 w8 w8r<   