MC_data / mc_dataset.py
Catill520's picture
Upload mc_dataset.py with huggingface_hub
c0e2115 verified
import datasets
import pyarrow.parquet as pq
class TrajectoryDataset(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description="minecraft image-action data for world model",
features=datasets.Features({
"episode_id": datasets.Value("string"),
"frame_image": datasets.Value("string"),
"frame_actions": datasets.Sequence(datasets.Value("int32")),
"step_id":datasets.Value("int32")
}),
)
def _split_generators(self, dl_manager):
base_url = "https://huggingface.co/datasets/Catill520/MC_data/resolve/main/data/"
sub_paths = [
"find-cave-Jul-28",
]
data_files = []
for sub_path in sub_paths:
subpath_url = f"{base_url}{sub_path}/"
files = dl_manager.list_files(subpath_url)
for file in files:
data_files.append(f"{subpath_url}{file}")
downloaded_files = dl_manager.download(data_files)
return [
datasets.SplitGenerator(name="all_data", gen_kwargs={"filepaths": downloaded_files}),
]
def _generate_examples(self, filepaths):
for filepath in filepaths:
table = pq.read_table(filepath)
df = table.to_pandas()
for idx, row in df.iterrows():
yield idx, {
"episode_id": row["episode_id"],
"frame_image": row["frame_image"],
"frame_actions": row["frame_actions"],
"step_id": row["step_id"],
}