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ZddlmZ ddl	m
  mZ ddlmZ dZG dd	 d	ejjZdS )
Dmlab dataset.    )absolute_import)division)print_functionN)loggingzBhttps://storage.googleapis.com/akolesnikov-dmlab-tfds/dmlab.tar.gzc                   @   s<   e Zd ZdZejdZdd Zdd Z	dd Z
d	d
 ZdS )Dmlabr   z2.0.0c              
   C   sD   t jj| dt jt jjdddt j t jjddddd	d
dS )Na!  
        The Dmlab dataset contains frames observed by the agent acting in the
        DeepMind Lab environment, which are annotated by the distance between
        the agent and various objects present in the environment. The goal is to
        is to evaluate the ability of a visual model to reason about distances
        from the visual input in 3D environments. The Dmlab dataset consists of
        360x480 color images in 6 classes. The classes are
        {close, far, very far} x {positive reward, negative reward}
        respectively.)ih  i     jpeg)shapeencoding_format   )num_classesimagefilenamelabelz2https://github.com/google-research/task_adaptationa  @article{zhai2019visual,
        title={The Visual Task Adaptation Benchmark},
        author={Xiaohua Zhai and Joan Puigcerver and Alexander Kolesnikov and
               Pierre Ruyssen and Carlos Riquelme and Mario Lucic and
               Josip Djolonga and Andre Susano Pinto and Maxim Neumann and
               Alexey Dosovitskiy and Lucas Beyer and Olivier Bachem and
               Michael Tschannen and Marcin Michalski and Olivier Bousquet and
               Sylvain Gelly and Neil Houlsby},
                              year={2019},
                              eprint={1910.04867},
                              archivePrefix={arXiv},
                              primaryClass={cs.CV},
                              url = {https://arxiv.org/abs/1910.04867}
                          })r   r   )builderdescriptionfeatureshomepagecitationsupervised_keys)tfdscoreDatasetInfor   FeaturesDictImageText
ClassLabel)self r    b/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image_classification/dmlab.py_info&   s   	zDmlab._infoc                 C   sV   | t}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train)images_dir_path
split_name)name
gen_kwargs
validationtest)	download_and_extract_URLr   r   SplitGeneratorSplitTRAIN
VALIDATIONTEST)r   
dl_managerpathr    r    r!   _split_generatorsJ   s(   
zDmlab._split_generatorsc                 C   sH   t jjg t jdt jjg t jdt jjg t jdd}t j||}|S )zParses single video from the input tfrecords.

    Args:
      example_proto: tfExample proto with a single video.

    Returns:
      dict with all frames, positions and actions.
    )r
   dtyper   )tfioFixedLenFeaturestringint64parse_single_example)r   example_protofeature_mapparse_singler    r    r!   _parse_single_imageb   s   zDmlab._parse_single_imagec           	   
   c   s6   t j|d|}tjj|}t	dd| t
  p tj|}|j| jtjjjd}tjjj| }tjj >}|tjj  z	 ||}|d t|d |d |d d	fV  qO tjjy   Y W d    W d    d S w 1 sw   Y  W d    d S 1 sw   Y  d S )
Nzdmlab-{}.tfrecord*zReading data from %s.,)num_parallel_callsTr   r   r   r   )osr2   joinformatr5   r6   gfileglobr   infoGraph
as_defaultdataTFRecordDatasetmapr>   experimentalAUTOTUNEcompatv1make_one_shot_iteratorget_nextSessionrunglobal_variables_initializerBytesIOerrorsOutOfRangeError)	r   r$   r%   	path_globfilesdsiteratorsessresultr    r    r!   _generate_examplesv   s>   

"zDmlab._generate_examplesN)__name__
__module____qualname____doc__r   r   VersionVERSIONr"   r3   r>   r^   r    r    r    r!   r   !   s    $r   )rb   
__future__r   r   r   r6   rA   abslr   tensorflow.compat.v2rN   v2r5   tensorflow_datasets.public_api
public_apir   r+   r   GeneratorBasedBuilderr   r    r    r    r!   <module>   s   