o
    Ni                      @   s   d Z ddlmZ ddlmZ ddlmZ ddlZddlm  mZ	 ddl
mZ dZdZdZd	Zd
 Zd ZdZdZG dd dejjZdS )zCelebA dataset.

Large-scale CelebFaces Attributes (CelebA) Dataset

Deep Learning Face Attributes in the Wild
Ziwei Liu and Ping Luo and Xiaogang Wang and Xiaoou Tang
    )absolute_import)division)print_functionNzKhttps://drive.google.com/uc?export=download&id=0B7EVK8r0v71pZjFTYXZWM3FlRnMzKhttps://drive.google.com/uc?export=download&id=0B7EVK8r0v71pY0NSMzRuSXJEVkkzKhttps://drive.google.com/uc?export=download&id=0B7EVK8r0v71pd0FJY3Blby1HUTQzKhttps://drive.google.com/uc?export=download&id=0B7EVK8r0v71pblRyaVFSWGxPY0Uzilefteye_x lefteye_y righteye_x righteye_y nose_x nose_y leftmouth_x leftmouth_y rightmouth_x rightmouth_ya  5_o_Clock_Shadow Arched_Eyebrows Attractive Bags_Under_Eyes Bald Bangs Big_Lips Big_Nose Black_Hair Blond_Hair Blurry Brown_Hair Bushy_Eyebrows Chubby Double_Chin Eyeglasses Goatee Gray_Hair Heavy_Makeup High_Cheekbones Male Mouth_Slightly_Open Mustache Narrow_Eyes No_Beard Oval_Face Pale_Skin Pointy_Nose Receding_Hairline Rosy_Cheeks Sideburns Smiling Straight_Hair Wavy_Hair Wearing_Earrings Wearing_Hat Wearing_Lipstick Wearing_Necklace Wearing_Necktie Younga  @inproceedings{conf/iccv/LiuLWT15,
  added-at = {2018-10-09T00:00:00.000+0200},
  author = {Liu, Ziwei and Luo, Ping and Wang, Xiaogang and Tang, Xiaoou},
  biburl = {https://www.bibsonomy.org/bibtex/250e4959be61db325d2f02c1d8cd7bfbb/dblp},
  booktitle = {ICCV},
  crossref = {conf/iccv/2015},
  ee = {http://doi.ieeecomputersociety.org/10.1109/ICCV.2015.425},
  interhash = {3f735aaa11957e73914bbe2ca9d5e702},
  intrahash = {50e4959be61db325d2f02c1d8cd7bfbb},
  isbn = {978-1-4673-8391-2},
  keywords = {dblp},
  pages = {3730-3738},
  publisher = {IEEE Computer Society},
  timestamp = {2018-10-11T11:43:28.000+0200},
  title = {Deep Learning Face Attributes in the Wild.},
  url = {http://dblp.uni-trier.de/db/conf/iccv/iccv2015.html#LiuLWT15},
  year = 2015
}
a  CelebFaces Attributes Dataset (CelebA) is a large-scale face attributes dataset with more than 200K celebrity images, each with 40 attribute annotations. The images in this dataset cover large pose variations and background clutter. CelebA has large diversities, large quantities, and rich annotations, including
 - 10,177 number of identities,
 - 202,599 number of face images, and
 - 5 landmark locations, 40 binary attributes annotations per image.

The dataset can be employed as the training and test sets for the following computer vision tasks: face attribute recognition, face detection, and landmark (or facial part) localization.

Note: CelebA dataset may contain potential bias. The fairness indicators
[example](https://github.com/tensorflow/fairness-indicators/blob/master/fairness_indicators/documentation/examples/Fairness_Indicators_TFCO_CelebA_Case_Study.ipynb)
goes into detail about several considerations to keep in mind while using the
CelebA dataset.
c                   @   sL   e Zd ZdZejddZejdgZdd Z	dd Z
d	d
 Zdd ZdS )CelebAz3CelebA dataset. Aligned and cropped. With metadata.z2.0.1z6New split API (https://tensorflow.org/datasets/splits)z2.0.0c              	   C   sF   t jj| tt jt jjddddd tD dd tD ddt	d	S )
N)         jpeg)shapeencoding_formatc                 S      i | ]}|t jqS  )tfint64.0namer   r   T/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image/celeba.py
<dictcomp>x       z CelebA._info.<locals>.<dictcomp>c                 S   r   r   )r   boolr   r   r   r   r   z   s    image	landmarks
attributesz0http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html)builderdescriptionfeatureshomepagecitation)
tfdscoreDatasetInfo_DESCRIPTIONr   FeaturesDictImageLANDMARK_HEADINGSATTR_HEADINGS	_CITATION)selfr   r   r   _infop   s   
zCelebA._infoc                 C   s~   | ttttd}dd ||d D }tjjtj	j
d||ddtjjtj	jd||ddtjjtj	jd	||ddgS )
N)img_align_celebalist_eval_partitionlist_attr_celebalandmarks_celebac                 S   s"   i | ]\}}t j|d  |qS ))ospathsplit)r   kimgr   r   r   r      s    z,CelebA._split_generators.<locals>.<dictcomp>r+   r   )file_iddownloaded_dirsdownloaded_images)r   
gen_kwargs      )downloadIMG_ALIGNED_DATA	EVAL_LIST	ATTR_DATALANDMARKS_DATAiter_archiver    r!   SplitGeneratorSplitTRAIN
VALIDATIONTEST)r)   
dl_managerr6   
all_imagesr   r   r   _split_generators   s>   	zCelebA._split_generatorsc           	      C   s   t jj|}| }W d   n1 sw   Y  |d}|d   }i }|dd D ]}|  }dd |dd D ||d < q0||fS )	a  Unpack the celeba config file.

    The file starts with the number of lines, and a header.
    Afterwards, there is a configuration for each file: one per line.

    Args:
      file_path: Path to the file with the configuration.

    Returns:
      keys: names of the attributes
      values: map from the file name to the list of attribute values for
              this file.
    N
r9   r:   r/   c                 S   s   g | ]}t |qS r   )int)r   vr   r   r   
<listcomp>   r   z6CelebA._process_celeba_config_file.<locals>.<listcomp>r   )r   iogfileGFilereadr2   strip)	r)   	file_pathfdata_rawlineskeysvaluesline
row_valuesr   r   r   _process_celeba_config_file   s   

 z"CelebA._process_celeba_config_filec                 #   s    |d }|d }|d }t jj|} fdd| D }W d   n1 s*w   Y  | |}	| |}
t|D ]+}|| dd t|
d	 |
d
 | D dd t|	d	 |	d
 | D d}||fV  q=dS )zYields examples.r,   r.   r-   c                    s,   g | ]}t | d   kr| d qS )r9   r   )rJ   r2   )r   rX   r5   r   r   rL      s
    
z-CelebA._generate_examples.<locals>.<listcomp>Nc                 S   s   i | ]\}}||qS r   r   r   r3   rK   r   r   r   r      s    
z-CelebA._generate_examples.<locals>.<dictcomp>r   r9   c                 S   s   i | ]	\}}||d kqS )r   r   r\   r   r   r   r      s    r   )r   rM   rN   rO   	readlinesrZ   sortedzip)r)   r5   r6   r7   img_list_pathlandmarks_path	attr_pathrS   filesr   r   	file_namerecordr   r[   r   _generate_examples   s,   



zCelebA._generate_examplesN)__name__
__module____qualname____doc__r    r!   VersionVERSIONSUPPORTED_VERSIONSr*   rH   rZ   rf   r   r   r   r   r   g   s    
'r   )rj   
__future__r   r   r   r0   tensorflow.compat.v2compatv2r   tensorflow_datasets.public_api
public_apir    r<   r=   r?   r>   r2   r&   r'   r(   r#   r!   GeneratorBasedBuilderr   r   r   r   r   <module>   s(   