Upload mc_dataset.py with huggingface_hub
Browse files- mc_dataset.py +51 -0
mc_dataset.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
import pyarrow.parquet as pq
|
| 3 |
+
|
| 4 |
+
class TrajectoryDataset(datasets.GeneratorBasedBuilder):
|
| 5 |
+
def _info(self):
|
| 6 |
+
return datasets.DatasetInfo(
|
| 7 |
+
description="minecraft image-action data for world model",
|
| 8 |
+
features=datasets.Features({
|
| 9 |
+
"UID": datasets.Value("string"),
|
| 10 |
+
"Frame_base64": datasets.Value("string"),
|
| 11 |
+
"Action": datasets.Sequence(datasets.Value("int32")),
|
| 12 |
+
}),
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _split_generators(self, dl_manager):
|
| 17 |
+
|
| 18 |
+
base_url = "https://huggingface.co/datasets/Catill520/MC_data/resolve/main/data/"
|
| 19 |
+
sub_paths = [
|
| 20 |
+
"find-cave-Jul-28",
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
data_files = []
|
| 24 |
+
for sub_path in sub_paths:
|
| 25 |
+
subpath_url = f"{base_url}{sub_path}/"
|
| 26 |
+
|
| 27 |
+
files = dl_manager.list_files(subpath_url)
|
| 28 |
+
for file in files:
|
| 29 |
+
data_files.append(f"{subpath_url}{file}")
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
downloaded_files = dl_manager.download(data_files)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
return [
|
| 36 |
+
datasets.SplitGenerator(name="all_data", gen_kwargs={"filepaths": downloaded_files}),
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def _generate_examples(self, filepaths):
|
| 41 |
+
for filepath in filepaths:
|
| 42 |
+
|
| 43 |
+
table = pq.read_table(filepath)
|
| 44 |
+
df = table.to_pandas()
|
| 45 |
+
for idx, row in df.iterrows():
|
| 46 |
+
yield idx, {
|
| 47 |
+
"UID": row["UID"],
|
| 48 |
+
"Frame_base64": row["Frame_base64"],
|
| 49 |
+
"Action": row["Action"],
|
| 50 |
+
}
|
| 51 |
+
|