o
    NiB                     @   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d	ZG d
d dejjZG dd dejjZdS )zRoboNet dataset.

RoboNet: Large-Scale Multi-Robot Learning

Sudeep Dasari, Frederik Ebert, Stephen Tian, Suraj Nair, Bernadette Bucher,
Karl Schmeckpeper, Siddharth Singh, Sergey Levine, Chelsea Finn

https://www.robonet.wiki/
    )absolute_import)division)print_functionNzPhttps://drive.google.com/uc?export=download&id=1YX2TgT8IKSn9V4wGCwdzbRnS53yicV2PzPhttps://drive.google.com/uc?export=download&id=1BkqHzfRkfzgzCfc73NbNnPMK_rg3i1n9   aK  @article{dasari2019robonet,
  title={RoboNet: Large-Scale Multi-Robot Learning},
  author={Dasari, Sudeep and Ebert, Frederik and Tian, Stephen and
  Nair, Suraj and Bucher, Bernadette and Schmeckpeper, Karl
  and Singh, Siddharth and Levine, Sergey and Finn, Chelsea},
  journal={arXiv preprint arXiv:1910.11215},
  year={2019}
}
c                       s*   e Zd ZdZejjd fdd	Z  ZS )RobonetConfigz+"Configuration for RoboNet video rescaling.FNc                    sP   t t| jddtjdi| |du |du A rtd|| _|| _|| _	dS )a  The parameters specifying how the dataset will be processed.

    The dataset comes with three separate splits. You can specify which split
    you want in `split_number`. If `width` and `height` are set, the videos
    will be rescaled to have those heights and widths (using ffmpeg).

    Args:
      sample_dataset: Whether or not to use the sample dataset.
      width: An integer with the width or None.
      height: An integer with the height or None.
      **kwargs: Passed on to the constructor of `BuilderConfig`.
    versionz4.0.0Nz5Either both dimensions should be set, or none of them )
superr   __init__tfdscoreVersion
ValueErrorsample_datasetwidthheight)selfr   r   r   kwargs	__class__r   U/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/video/robonet.pyr
   ?   s   

zRobonetConfig.__init__)FNN)	__name__
__module____qualname____doc__r   r   disallow_positional_argsr
   __classcell__r   r   r   r   r   <   s    r   c                
   @   sl   e Zd ZdZeddddddedddd	d	ded
dddddedddd	d	dgZdd Zdd Zdd ZdS )Robonetz*RoboNet: Large-Scale Multi-Robot Learning.robonet_sample_64z64x64 RoboNet Sample.T@   )namedescriptionr   r   r   robonet_sample_128z128x128 RoboNet Sample.   
robonet_64z64x64 RoboNet.Frobonet_128z128x128 RoboNet.c                 C   s   | j jd ur| j jd u rtddd| j j| j jf}ng }d | j j| j jdf}tjtjj||ddtjj	d t
ftjdtjj	d tftjdd}tjj| td	|d
tdS )Nz-Provide either both height and width or none.z-vfzscale={}x{}   png)ffmpeg_extra_argsencoding_format)shapedtypevideoactionsstatesa          RoboNet contains over 15 million video frames of robot-object
        interaction, taken from 113 unique camera viewpoints.

        * The actions are deltas in position and rotation to the robot
        end-effector with one additional dimension of the action vector
        reserved for the gripper joint.

        * The states are cartesian end-effector control action space
        with restricted rotation, and a gripper jointzhttps://www.robonet.wiki/)builderr!   featureshomepagecitation)builder_configr   r   r   formatr   r1   FeaturesDictVideoTensorACTIONS_DIMtffloat32
STATES_DIMr   DatasetInfotextwrapdedent	_CITATION)r   r(   video_shaper1   r   r   r   _infox   s<   


zRobonet._infoc                 C   s:   | | jjrtnt}tjjtjj	dt
j|didgS )Nfiledirhdf5)r    
gen_kwargs)download_and_extractr4   r   DATA_URL_SAMPLEDATA_URLr   r   SplitGeneratorSplitTRAINospathjoin)r   
dl_managerfilesr   r   r   _split_generators   s   zRobonet._split_generatorsc                 C   sB   t jjj}dd }tjjtj	
|d}|||B ||B S )zGenerate examples as dicts.c              	   S   s   t jjj}|| R}|d d d dd  }|d d dd tj}t	|ddt
|jd  ffd	}|d
 d dd tj}t	|ddt|jd  ffd	}W d   n1 s_w   Y  |||d}tj| |fS )z$Converts one video from hdf5 format.env
cam0_videoframesNstate)r   r   r      constantpolicyr.   r,   )r   r   lazy_importsh5pyFiletostringastypenpr;   padr<   r*   r9   rL   rM   basename)filenamerZ   hfvideo_bytesr/   r.   r1   r   r   r   _process_example   s"   

z4Robonet._build_pcollection.<locals>._process_examplez*.hdf5)r   r   rY   apache_beamr:   iogfileglobrL   rM   rN   CreateMap)r   pipelinerC   beamrd   	filenamesr   r   r   _build_pcollection   s   
zRobonet._build_pcollectionN)	r   r   r   r   r   BUILDER_CONFIGSrB   rQ   rn   r   r   r   r   r   V   sD    ,r   )r   
__future__r   r   r   rL   r>   numpyr^   tensorflow.compat.v2compatv2r:   tensorflow_datasets.public_api
public_apir   rG   rH   r<   r9   r@   r   BuilderConfigr   BeamBasedBuilderr   r   r   r   r   <module>   s    
