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d	gZd
ZdZdZdd ZG dd dejjZdd ZG dd dejjZdS ) Frames Labeled In Cinema (FLIC).    )absolute_import)division)print_functionNz@inproceedings{modec13,
    title={MODEC: Multimodal Decomposable Models for Human Pose Estimation},
    author={Sapp, Benjamin and Taskar, Ben},
    booktitle={In Proc. CVPR},
    year={2013},
  }
a  
From the paper: We collected a 5003 image dataset automatically from popular
Hollywood movies. The images were obtained by running a state-of-the-art person
detector on every tenth frame of 30 movies. People detected with high confidence
(roughly 20K candidates) were then sent to the crowdsourcing marketplace Amazon
Mechanical Turk to obtain groundtruthlabeling. Each image was annotated by five
Turkers for $0.01 each to label 10 upperbody joints. The median-of-five labeling
was taken in each image to be robust to outlier annotation. Finally, images were
rejected manually by us if the person was occluded or severely non-frontal. We
set aside 20% (1016 images) of the data for testing.
smallfullz+https://bensapp.github.io/flic-dataset.htmlzKhttps://drive.google.com/uc?id=0B4K3PZp8xXDJN0Fpb0piVjQ3Y3M&export=downloadzKhttps://drive.google.com/uc?id=0B4K3PZp8xXDJd2VwblhhOVBfMDg&export=downloadc                 C   s~   t jj|d}tjjj|}|j	\}}W d   n1 s w   Y  tj
j| d | | d | | d | | d | dS )zNormalize torsobox bbox values.rbN      r      )yminymaxxminxmax)tfiogfileGFiletfdscorelazy_imports	PIL_ImageopensizefeaturesBBox)raw_bboximg_pathfpimgwidthheight r"   R/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image/flic.py_normalize_bbox8   s   



r$   c                       s(   e Zd ZdZejj fddZ  ZS )
FlicConfigzBuilderConfig for FLIC.c                    s   |t vr
tdt  ddd}|dd||  }||d< tt| jdi | || _|dkr1tnt| _	|dkr=d| _
d
S d	| _
d
S )zConstructs a FlicConfig.zdata must be one of %sz)5003 examples used in CVPR13 MODEC paper.zI20928 examples, a superset of FLIC consisting of more difficult examples.)r   r   descriptionzUses %sr   FLICz	FLIC-fullNr"   )_DATA_OPTIONS
ValueErrorgetsuperr%   __init__data_URL_SUBSET_URL_SUPERSETurldir)selfr-   kwargsdescriptionsr&   	__class__r"   r#   r,   I   s   zFlicConfig.__init__)	__name__
__module____qualname____doc__r   r   disallow_positional_argsr,   __classcell__r"   r"   r5   r#   r%   F   s    r%   c                  C   s.   g } t D ]}| t|tjd|d q| S )Nz2.0.0)nameversionr-   )r(   appendr%   r   r   Version)configsr-   r"   r"   r#   _make_builder_configs^   s   rB   c                   @   s.   e Zd ZdZe Zdd Zdd Zdd ZdS )	Flicr   c                 C   sr   t jj| tt jt jjdddt jtj	t j
 t jtjt jtjt jjdtjdt j dttdS )N)i  i  r
   jpeg)shapeencoding_formatr"   )rE   dtypeimageposelet_hit_idx	movienamexcoordsycoords	currframetorsobox)builderr&   r   homepagecitation)r   r   DatasetInfo_DESCRIPTIONr   FeaturesDictImageSequencer   uint16Textfloat64TensorBBoxFeature_HOMEPAGE_URL	_CITATION)r2   r"   r"   r#   _infok   s"   z
Flic._infoc                 C   s   | | jj}tj|| jjd}tjj	
|d}tjjjjj|dddd}W d   n1 s1w   Y  tjjtjj||dddtjjtjj||d	ddgS )
zReturns SplitGenerators.zexamples.matr   T)struct_as_record
squeeze_me	mat_dtypeN   )extract_pathr-   selection_column)r=   
gen_kwargs   )download_and_extractbuilder_configr0   ospathjoinr1   r   r   r   r   r   r   r   scipyloadmatSplitGeneratorSplitTRAINTEST)r2   
dl_managerrd   mat_pathfr-   r"   r"   r#   _split_generators   s0   zFlic._split_generatorsc                 c   s~    t |d D ]5\}}|| r<tj|| jjd|d }|||d |d |d d |d d |d t|d |d	fV  qd
S )zYields examples.examplesimagesr
   r   r	   r         rH   N)	enumeraterj   rk   rl   ri   r1   r$   )r2   rd   r-   re   u_idexampler   r"   r"   r#   _generate_examples   s"   


zFlic._generate_examplesN)	r7   r8   r9   r:   rB   BUILDER_CONFIGSr_   rv   r~   r"   r"   r"   r#   rC   f   s    rC   )r:   
__future__r   r   r   rj   tensorflow.compat.v2compatv2r   tensorflow_datasets.public_api
public_apir   r^   rT   r(   r]   r.   r/   r$   r   BuilderConfigr%   rB   GeneratorBasedBuilderrC   r"   r"   r"   r#   <module>   s"   