| |
|
|
| import json |
| import pandas as pd |
| import shutil |
| from pathlib import Path |
| import jsonlines |
|
|
| def load_jsonlines(fpath): |
| with jsonlines.open(fpath, "r") as reader: |
| return list(reader) |
|
|
| def convert_local_dataset(): |
| root = Path(".") |
| |
| |
| with open("meta/info.json", "r") as f: |
| info = json.load(f) |
| |
| |
| info["codebase_version"] = "v3.0" |
| |
| |
| if "total_chunks" in info: |
| del info["total_chunks"] |
| if "total_videos" in info: |
| del info["total_videos"] |
| |
| |
| info["data_files_size_in_mb"] = 100 |
| info["video_files_size_in_mb"] = 500 |
| info["data_path"] = "data/chunk-{chunk_index:03d}/file_{file_index:03d}.parquet" |
| info["video_path"] = "videos/chunk-{chunk_index:03d}/{video_key}/file_{file_index:03d}.mp4" |
| |
| |
| info["fps"] = float(info["fps"]) |
| |
| |
| for key in info["features"]: |
| if info["features"][key]["dtype"] != "video": |
| info["features"][key]["fps"] = info["fps"] |
| |
| |
| with open("meta/info.json", "w") as f: |
| json.dump(info, f, indent=4) |
| |
| |
| if Path("meta/tasks.jsonl").exists(): |
| tasks = load_jsonlines(Path("meta/tasks.jsonl")) |
| tasks_dict = {str(task["task_index"]): task["task"] for task in tasks} |
| |
| with open("meta/tasks.json", "w") as f: |
| json.dump(tasks_dict, f, indent=4) |
| |
| |
| Path("meta/tasks.jsonl").unlink() |
| |
| |
| if Path("meta/episodes.jsonl").exists(): |
| episodes = load_jsonlines(Path("meta/episodes.jsonl")) |
| episodes_dict = {str(ep["episode_index"]): ep for ep in episodes} |
| |
| with open("meta/episodes.json", "w") as f: |
| json.dump(episodes_dict, f, indent=4) |
| |
| |
| Path("meta/episodes.jsonl").unlink() |
| |
| |
| if Path("meta/episodes_stats.jsonl").exists(): |
| stats = load_jsonlines(Path("meta/episodes_stats.jsonl")) |
| stats_dict = {str(stat["episode_index"]): stat for stat in stats} |
| |
| with open("meta/episodes_stats.json", "w") as f: |
| json.dump(stats_dict, f, indent=4) |
| |
| |
| Path("meta/episodes_stats.jsonl").unlink() |
| |
| print("Dataset successfully converted from v2.1 to v3.0") |
| print("Updated files:") |
| print("- meta/info.json (codebase_version updated to v3.0)") |
| print("- meta/tasks.jsonl -> meta/tasks.json") |
| print("- meta/episodes.jsonl -> meta/episodes.json") |
| print("- meta/episodes_stats.jsonl -> meta/episodes_stats.json") |
|
|
| if __name__ == "__main__": |
| convert_local_dataset() |
|
|