o
    NiT                     @   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ZddlZddlm	  m
Z ddlmZ dZdZdZd	ZG d
d dejjZdS )CLEVR dataset.    )absolute_import)division)print_functionNzCLEVR is a diagnostic dataset that tests a range of visual reasoning abilities.
It contains minimal biases and has detailed annotations describing the kind of
reasoning each question requires.
a|  @inproceedings{johnson2017clevr,
  title={{CLEVR}: A diagnostic dataset for compositional language and elementary visual reasoning},
  author={Johnson, Justin and Hariharan, Bharath and van der Maaten, Laurens and Fei-Fei, Li and Lawrence Zitnick, C and Girshick, Ross},
  booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
  year={2017}
}
z-https://cs.stanford.edu/people/jcjohns/clevr/z3https://dl.fbaipublicfiles.com/clevr/CLEVR_v1.0.zipc                   @   sD   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S )CLEVRr   z3.1.0zAdd question/answer text.3.0.0c                 C   s   t j t j t jt jjg ddt jjddgdt jjg ddt jjddgdt jjdtjd	t jjd
tjd	t jjd
tjd	dd}| j	dkr_t jt j t j d|d< t j
j| tt j|ttdS )N)graybluebrownyellowredgreenpurplecyan)namesrubbermetal)cubespherecylindersmalllarge )shapedtype)   )colormaterialr   sizerotation	3d_coordspixel_coords)image	file_nameobjectsr   questionanswerquestion_answer)builderdescriptionfeatureshomepagecitation)tfdsr+   ImageTextSequence
ClassLabelTensortffloat32versioncoreDatasetInfo_DESCRIPTIONFeaturesDict	_BASE_URL	_CITATION)selfr+   r   r   S/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image/clevr.py_info;   s4   

zCLEVR._infoc           	      C   s   | t}tj|d}tj|d}tj|d}g }dD ]4}tjjtjjtjj	d}|
tjj|| tj||tj|d|tj|d|dd q|S )	zReturns splits.zCLEVR_v1.0/imageszCLEVR_v1.0/questionszCLEVR_v1.0/scenes)trainvaltestzCLEVR_{}_questions.jsonzCLEVR_{}_scenes.json)images_dir_pathquestion_filescenes_description_file)name
gen_kwargs)download_and_extract_DOWNLOAD_URLospathjoinr.   SplitTRAIN
VALIDATIONTESTappendr7   SplitGeneratorformat)	r=   
dl_managerrK   images_path_dirquestions_path_dirscenes_path_dirsplits
split_namename_mapr   r   r>   _split_generators[   s.   



zCLEVR._split_generatorsc                 #   sV   t fddtjjD }tjj|}t|}W d    n1 s(w   Y  t	t
}|d D ]}||d  |d |ddd q6tjj|rotjj|}t|}	W d    n1 siw   Y  nd	d
g igt| i}	g d t||	d	 D ]#\}
}|d
 }tj|
}|
|||  fdd|D d}||fV  qd S )Nc                    s   g | ]	}t j |qS r   )rJ   rK   rL   ).0filename)rC   r   r>   
<listcomp>z   s    z,CLEVR._generate_examples.<locals>.<listcomp>	questionsimage_filenamer&   r'    r%   scenesr$   )r   r   r   r   r   r!   r    c                    s   g | ]  fd dD qS )c                    s   i | ]}| | qS r   r   )r\   attrobjr   r>   
<dictcomp>   s    z7CLEVR._generate_examples.<locals>.<listcomp>.<dictcomp>r   )r\   )attrsrd   r>   r^      s    )r"   r#   r(   r$   )sortedr4   iogfilelistdirGFilejsonloadcollectionsdefaultdictlistrQ   getexistslenziprJ   rK   basename)r=   rC   rD   rE   image_pathsfquestions_jsonr_   qscenes_json
image_pathscener$   fnamerecordr   )rg   rC   r>   _generate_examplesx   s<   


zCLEVR._generate_examplesN)__name__
__module____qualname____doc__r.   r7   VersionVERSIONSUPPORTED_VERSIONSr?   r[   r   r   r   r   r>   r   3   s    
 r   )r   
__future__r   r   r   ro   rm   rJ   tensorflow.compat.v2compatv2r4   tensorflow_datasets.public_api
public_apir.   r9   r<   r;   rI   r7   GeneratorBasedBuilderr   r   r   r   r>   <module>   s   	