o
    NiT                     @   sv   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlm	  m
Z ddlmZ dZdZG dd	 d	ejjZdS )
zAFLW2000-3D Dataset.    )absolute_import)division)print_functionNa  AFLW2000-3D is a dataset of 2000 images that have been annotated with image-level
68-point 3D facial landmarks.
This dataset is typically used for evaluation of 3D facial landmark detection
models. The head poses are very diverse and often hard to be detected by a 
cnn-based face detector.
The 2D landmarks are skipped in this dataset, since some of the data are not
consistent to 21 points, as the original paper mentioned.
an  @article{DBLP:journals/corr/ZhuLLSL15,
  author    = {Xiangyu Zhu and
               Zhen Lei and
               Xiaoming Liu and
               Hailin Shi and
               Stan Z. Li},
  title     = {Face Alignment Across Large Poses: {A} 3D Solution},
  journal   = {CoRR},
  volume    = {abs/1511.07212},
  year      = {2015},
  url       = {http://arxiv.org/abs/1511.07212},
  archivePrefix = {arXiv},
  eprint    = {1511.07212},
  timestamp = {Mon, 13 Aug 2018 16:48:23 +0200},
  biburl    = {https://dblp.org/rec/bib/journals/corr/ZhuLLSL15},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}
c                   @   s4   e Zd ZdZejdZdd Zdd Z	dd Z
d	S )
Aflw2k3dzAFLW2000-3D dataset.z1.0.0c                 C   sN   t jj| tt jt jjdddt jjdtj	dt jjdtj	dddt
d	S )
N)  r      jpeg)shapeencoding_format)D      )r	   dtype)r      imagelandmarks_68_3d_xy_normalizedlandmarks_68_3d_zzAhttp://www.cbsr.ia.ac.cn/users/xiangyuzhu/projects/3DDFA/main.htm)builderdescriptionfeatureshomepagecitation)tfdscoreDatasetInfo_DESCRIPTIONr   FeaturesDictImageTensortffloat32	_CITATION)self r#   V/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image/aflw2k3d.py_info@   s   
zAflw2k3d._infoc                 C   s.   | d}tjjtjjdtj|didgS )NzQhttp://www.cbsr.ia.ac.cn/users/xiangyuzhu/projects/3DDFA/Database/AFLW2000-3D.zipimage_dir_pathAFLW2000)name
gen_kwargs)	download_and_extractr   r   SplitGeneratorSplitTRAINospathjoin)r"   
dl_managerextracted_pathr#   r#   r$   _split_generatorsR   s   zAflw2k3d._split_generatorsc              	   c   s    t jjjtj|dd}dd |D }t||D ]M\}}t jj|d}t	j
jjj|}W d    n1 s:w   Y  |d jtj}|ddd	f d
 }	|dd	d f }
tj|||	|
dfV  qd S )Nzimage0*.jpg)patternc                 S   s   g | ]}| d dqS )jpgmat)replace).0sr#   r#   r$   
<listcomp>a   s    z/Aflw2k3d._generate_examples.<locals>.<listcomp>rbpt3d_68.r   r   g      |@r   )r   iogfileglobr.   r/   r0   zipGFiler   r   lazy_importsscipyloadmatTastypenpr    basename)r"   r&   image_fileslabel_files
image_file
label_filefr6   landmarks_68_3d_xyzr   r   r#   r#   r$   _generate_examples^   s$   
zAflw2k3d._generate_examplesN)__name__
__module____qualname____doc__r   r   VersionVERSIONr%   r3   rO   r#   r#   r#   r$   r   ;   s    r   )rS   
__future__r   r   r   r.   numpyrG   tensorflow.compat.v2compatv2r   tensorflow_datasets.public_api
public_apir   r   r!   r   GeneratorBasedBuilderr   r#   r#   r#   r$   <module>   s   
