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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 )zBerkeley (BAIR) robot pushing dataset.

Self-Supervised Visual Planning with Temporal Skip Connections
Frederik Ebert, Chelsea Finn, Alex X. Lee, and Sergey Levine.
https://arxiv.org/abs/1710.05268
    )absolute_import)division)print_functionN)loggingzHhttp://rail.eecs.berkeley.edu/datasets/bair_robot_pushing_dataset_v0.tar   )@   r      z@misc{1710.05268,
  Author = {Frederik Ebert and Chelsea Finn and Alex X. Lee and Sergey Levine},
  Title = {Self-Supervised Visual Planning with Temporal Skip Connections},
  Year = {2017},
  Eprint = {arXiv:1710.05268},
}
c                   @   s6   e Zd ZdZejddZdd Zdd Z	dd	 Z
d
S )BairRobotPushingSmallz6Robot pushing dataset from BAIR (Small 64x64 version).z2.0.0z6New split API (https://tensorflow.org/datasets/splits)c                 C   s`   t jjt jjtdt jjtdt jjdtjdt jjdtjddtd}t j	j
| d|dtd	S )
N)shape)   )r
   dtype)r   )
image_main
image_aux1actionendeffector_pos)lengthzThis data set contains roughly 44,000 examples of robot pushing motions, including one training set (train) and two test sets of previously seen (testseen) and unseen (testnovel) objects. This is the small 64x64 version.z-https://sites.google.com/view/sna-visual-mpc/)builderdescriptionfeatureshomepagecitation)tfdsr   SequenceImage	IMG_SHAPETensortffloat32FRAMES_PER_VIDEOcoreDatasetInfo	_CITATION)selfr    r#   `/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/video/bair_robot_pushing.py_info;   s   zBairRobotPushingSmall._infoc              	   C   sR   | t}tjjtjjdtj	|ddidtjjtjj
dtj	|ddidgS )Nfiledirsoftmotion30_44ktrain)name
gen_kwargstest)download_and_extractDATA_URLr   r   SplitGeneratorSplitTRAINospathjoinTEST)r"   
dl_managerfilesr#   r#   r$   _split_generatorsP   s   
z'BairRobotPushingSmall._split_generatorsc                 #   s6   t d| tjj|}t dt| ttjj|D ]y}tj	
||}ttjjj|D ]e\}}tjj| g }ttD ]J fdddD }dD ]}	||	 jjfddttD ||	< qQd	D ]}	||	 jjd
 }
tj|
tjd}
t|
t}
|
||	< qk|| qCd||f |fV  q2qd S )NzReading data from %s.z%d files found.c                    s$   i | ]\}}| j j| qS r#   )contextfeatureformat).0out_keyin_key)exampleframe_idr#   r$   
<dictcomp>q   s    z<BairRobotPushingSmall._generate_examples.<locals>.<dictcomp>))r   z{}/image_main/encoded)r   z{}/image_aux1/encoded)r   z{}/endeffector_pos)r   z	{}/action)r   r   c                    s   g | ]} | qS r#   r#   )r;   i)valuesr#   r$   
<listcomp>~   s    z<BairRobotPushingSmall._generate_examples.<locals>.<listcomp>)r   r   r   )r   z%s_%s)r   infor   iogfilelistdirlensortedr1   r2   r3   	enumeratecompatv1tf_record_iteratorr(   SequenceExample
FromStringranger   
float_listvalue
bytes_listnp
frombufferuint8reshaper   append)r"   r&   r6   filenamefilepathvideo_idexample_str
all_framesframe_featurekeyimgr#   )r>   r?   rB   r$   _generate_examples_   s6    
z(BairRobotPushingSmall._generate_examplesN)__name__
__module____qualname____doc__r   r   VersionVERSIONr%   r7   ra   r#   r#   r#   r$   r	   5   s    r	   )re   
__future__r   r   r   r1   abslr   numpyrT   tensorflow.compat.v2rK   v2r   tensorflow_datasets.public_api
public_apir   r-   r   r   r!   r   GeneratorBasedBuilderr	   r#   r#   r#   r$   <module>   s   
