Create unpack_data.py
Browse files- unpack_data.py +31 -0
unpack_data.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Example script to unpack one shard of the 1xGPT v2.0 video dataset."""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import pathlib
|
| 5 |
+
import subprocess
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
dir_path = pathlib.Path("worldmodel/val_v2.0")
|
| 10 |
+
rank = 0
|
| 11 |
+
|
| 12 |
+
# load metadata.json
|
| 13 |
+
metadata = json.load(open(dir_path / "metadata.json"))
|
| 14 |
+
metadata_shard = json.load(open(dir_path / f"metadata_{rank}.json"))
|
| 15 |
+
|
| 16 |
+
total_frames = metadata_shard["shard_num_frames"]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
maps = [
|
| 20 |
+
("segment_idx", np.int32, []),
|
| 21 |
+
("states", np.float32, [25]),
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
video_path = dir_path / "video_0.mp4"
|
| 25 |
+
|
| 26 |
+
for m, dtype, shape in maps:
|
| 27 |
+
filename = dir_path / f"{m}_{rank}.bin"
|
| 28 |
+
print("Reading", filename, [total_frames] + shape)
|
| 29 |
+
m_out = np.memmap(filename, dtype=dtype, mode="r", shape=tuple([total_frames] + shape))
|
| 30 |
+
assert m_out.shape[0] == total_frames
|
| 31 |
+
|