[code] add load_script
Browse files
RT-X.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from typing import Optional, List
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
from PIL import Image as PILImage
|
| 6 |
+
import os
|
| 7 |
+
import numpy as np
|
| 8 |
+
import datasets
|
| 9 |
+
|
| 10 |
+
try:
|
| 11 |
+
import webdataset as wds
|
| 12 |
+
except ImportError:
|
| 13 |
+
os.system("python3 -m pip install webdataset")
|
| 14 |
+
import webdataset as wds
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def load_webdataset(filepath):
|
| 18 |
+
def decode_image(data):
|
| 19 |
+
if isinstance(data, dict):
|
| 20 |
+
data = {k: decode_image(v) for k, v in data.items()}
|
| 21 |
+
elif isinstance(data, tuple) or isinstance(data, list):
|
| 22 |
+
data = [decode_image(v) for v in data]
|
| 23 |
+
elif isinstance(data, np.ndarray): # wds to datasets
|
| 24 |
+
data = data.tolist()
|
| 25 |
+
elif isinstance(data, bytes):
|
| 26 |
+
if len(data) > 1024:
|
| 27 |
+
data = PILImage.open(BytesIO(data))
|
| 28 |
+
else:
|
| 29 |
+
data = data.decode()
|
| 30 |
+
return data
|
| 31 |
+
return wds.WebDataset(filepath).decode().map(decode_image)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
_LICENSE = """\
|
| 35 |
+
This is an unofficial Dataset Repo.
|
| 36 |
+
More information can be found here https://robotics-transformer-x.github.io/.
|
| 37 |
+
|
| 38 |
+
Copyright Notice
|
| 39 |
+
● Copyright 2023 DeepMind Technologies Limited
|
| 40 |
+
● All software is licensed under the Apache License, Version 2.0 (Apache 2.0); you may
|
| 41 |
+
not use this file except in compliance with the Apache 2.0 license. You may obtain a
|
| 42 |
+
copy of the Apache 2.0 license at: https://www.apache.org/licenses/LICENSE-2.0
|
| 43 |
+
● All other materials are licensed under the Creative Commons Attribution 4.0
|
| 44 |
+
International License (CC-BY). You may obtain a copy of the CC-BY license at:
|
| 45 |
+
https://creativecommons.org/licenses/by/4.0/legalcode
|
| 46 |
+
● Unless required by applicable law or agreed to in writing, all software and materials
|
| 47 |
+
distributed here under the Apache 2.0 or CC-BY licenses are distributed on an "AS IS"
|
| 48 |
+
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 49 |
+
implied. See the licenses for the specific language governing permissions and
|
| 50 |
+
limitations under those licenses.
|
| 51 |
+
● This is not an official Google product
|
| 52 |
+
"""
|
| 53 |
+
_RTX_DATASETS = {
|
| 54 |
+
'fractal20220817_data': 78,
|
| 55 |
+
'kuka': 448,
|
| 56 |
+
'bridge': 49,
|
| 57 |
+
'taco_play': 11,
|
| 58 |
+
'jaco_play': 2,
|
| 59 |
+
'berkeley_cable_routing': 1,
|
| 60 |
+
'roboturk': 7,
|
| 61 |
+
'nyu_door_opening_surprising_effectiveness': 2,
|
| 62 |
+
'viola': 2,
|
| 63 |
+
'berkeley_autolab_ur5': 20,
|
| 64 |
+
'toto': 19,
|
| 65 |
+
'language_table': 291,
|
| 66 |
+
'columbia_cairlab_pusht_real': 1,
|
| 67 |
+
'stanford_kuka_multimodal_dataset_converted_externally_to_rlds': 31,
|
| 68 |
+
'nyu_rot_dataset_converted_externally_to_rlds': 1,
|
| 69 |
+
'stanford_hydra_dataset_converted_externally_to_rlds': 11,
|
| 70 |
+
'austin_buds_dataset_converted_externally_to_rlds': 1,
|
| 71 |
+
'nyu_franka_play_dataset_converted_externally_to_rlds': 2,
|
| 72 |
+
'maniskill_dataset_converted_externally_to_rlds': 132,
|
| 73 |
+
'furniture_bench_dataset_converted_externally_to_rlds': 79,
|
| 74 |
+
'cmu_franka_exploration_dataset_converted_externally_to_rlds': 1,
|
| 75 |
+
'ucsd_kitchen_dataset_converted_externally_to_rlds': 1,
|
| 76 |
+
'ucsd_pick_and_place_dataset_converted_externally_to_rlds': 1,
|
| 77 |
+
'austin_sailor_dataset_converted_externally_to_rlds': 5,
|
| 78 |
+
'austin_sirius_dataset_converted_externally_to_rlds': 3,
|
| 79 |
+
'bc_z': 69,
|
| 80 |
+
'usc_cloth_sim_converted_externally_to_rlds': 1,
|
| 81 |
+
'utokyo_pr2_opening_fridge_converted_externally_to_rlds': 1,
|
| 82 |
+
'utokyo_pr2_tabletop_manipulation_converted_externally_to_rlds': 1,
|
| 83 |
+
'utokyo_saytap_converted_externally_to_rlds': 1,
|
| 84 |
+
'utokyo_xarm_pick_and_place_converted_externally_to_rlds': 1,
|
| 85 |
+
'utokyo_xarm_bimanual_converted_externally_to_rlds': 1,
|
| 86 |
+
'robo_net': 142,
|
| 87 |
+
'berkeley_mvp_converted_externally_to_rlds': 2,
|
| 88 |
+
'berkeley_rpt_converted_externally_to_rlds': 9,
|
| 89 |
+
'kaist_nonprehensile_converted_externally_to_rlds': 2,
|
| 90 |
+
'stanford_mask_vit_converted_externally_to_rlds': 13,
|
| 91 |
+
'tokyo_u_lsmo_converted_externally_to_rlds': 1,
|
| 92 |
+
'dlr_sara_pour_converted_externally_to_rlds': 1,
|
| 93 |
+
'dlr_sara_grid_clamp_converted_externally_to_rlds': 1,
|
| 94 |
+
'dlr_edan_shared_control_converted_externally_to_rlds': 1,
|
| 95 |
+
'asu_table_top_converted_externally_to_rlds': 1,
|
| 96 |
+
'stanford_robocook_converted_externally_to_rlds': 25,
|
| 97 |
+
'eth_agent_affordances': 12,
|
| 98 |
+
'imperialcollege_sawyer_wrist_cam': 1,
|
| 99 |
+
'iamlab_cmu_pickup_insert_converted_externally_to_rlds': 7,
|
| 100 |
+
'uiuc_d3field': 5,
|
| 101 |
+
'utaustin_mutex': 6,
|
| 102 |
+
'berkeley_fanuc_manipulation': 2,
|
| 103 |
+
'cmu_playing_with_food': 8,
|
| 104 |
+
'cmu_play_fusion': 2,
|
| 105 |
+
'cmu_stretch': 1,
|
| 106 |
+
'berkeley_gnm_recon': 6,
|
| 107 |
+
'berkeley_gnm_cory_hall': 1,
|
| 108 |
+
'berkeley_gnm_sac_son': 3
|
| 109 |
+
}
|
| 110 |
+
_RTX_DATASETS_URLS = {k: [f"{k}/{k}_{i:05d}.tar" for i in range(v)] for k, v in _RTX_DATASETS.items()}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@dataclass
|
| 114 |
+
class RTXConfig(datasets.BuilderConfig):
|
| 115 |
+
features: Optional[datasets.Features] = None
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class RTXDataset(datasets.GeneratorBasedBuilder):
|
| 119 |
+
VERSION = datasets.Version("1.0.0")
|
| 120 |
+
BUILDER_CONFIG_CLASS = RTXConfig
|
| 121 |
+
BUILDER_CONFIGS = [RTXConfig(name=dn) for dn in _RTX_DATASETS.keys()]
|
| 122 |
+
DEFAULT_CONFIG_NAME = "fractal20220817_data"
|
| 123 |
+
|
| 124 |
+
def _info(self):
|
| 125 |
+
return datasets.DatasetInfo(features=self.config.features)
|
| 126 |
+
|
| 127 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
| 128 |
+
files = dl_manager.download(_RTX_DATASETS_URLS[self.info.config_name])
|
| 129 |
+
if self.info.features is None:
|
| 130 |
+
for d in load_webdataset(files[0]):
|
| 131 |
+
self.info.features = datasets.Dataset.from_list([d]).features
|
| 132 |
+
break
|
| 133 |
+
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"files": files})]
|
| 134 |
+
|
| 135 |
+
def _generate_examples(self, files):
|
| 136 |
+
print(self.info.features)
|
| 137 |
+
for file in files:
|
| 138 |
+
for d in load_webdataset(file):
|
| 139 |
+
yield f"{d['__url__']}_{d['__key__']}", d
|