Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
---
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
Download and unpack merged dataset in Colab/Kaggle
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import json
|
| 11 |
+
import os
|
| 12 |
+
from huggingface_hub import snapshot_download
|
| 13 |
+
from tqdm import tqdm
|
| 14 |
+
|
| 15 |
+
# ═══════════════════════════════════════════════════════════
|
| 16 |
+
# CONFIG
|
| 17 |
+
# ═══════════════════════════════════════════════════════════
|
| 18 |
+
|
| 19 |
+
HF_REPO = "nnsohamnn/runner-game-dataset" # ← Change this!
|
| 20 |
+
DOWNLOAD_DIR = "runner_dataset_merged"
|
| 21 |
+
OUTPUT_DIR = "runner_dataset"
|
| 22 |
+
|
| 23 |
+
# ═══════════════════════════════════════════════════════════
|
| 24 |
+
# DOWNLOAD
|
| 25 |
+
# ═══════════════════════════════════════════════════════════
|
| 26 |
+
|
| 27 |
+
print("📥 Downloading from Hugging Face...")
|
| 28 |
+
snapshot_download(
|
| 29 |
+
repo_id=HF_REPO,
|
| 30 |
+
repo_type="dataset",
|
| 31 |
+
local_dir=DOWNLOAD_DIR
|
| 32 |
+
)
|
| 33 |
+
print("✅ Download complete!")
|
| 34 |
+
|
| 35 |
+
# ═══════════════════════════════════════════════════════════
|
| 36 |
+
# OPTION A: USE MERGED FILES DIRECTLY (RECOMMENDED)
|
| 37 |
+
# ═══════════════════════════════════════════════════════════
|
| 38 |
+
|
| 39 |
+
# You can use the merged files directly in training!
|
| 40 |
+
# This is actually MORE efficient than individual files.
|
| 41 |
+
|
| 42 |
+
# Example loading:
|
| 43 |
+
print("\n📊 Dataset info:")
|
| 44 |
+
with open(os.path.join(DOWNLOAD_DIR, "metadata.json"), 'r') as f:
|
| 45 |
+
metadata = json.load(f)
|
| 46 |
+
print(f" Total frames: {metadata['total_frames']:,}")
|
| 47 |
+
print(f" Chunks: {metadata['num_chunks']}")
|
| 48 |
+
print(f" Actions: {metadata['actions']}")
|
| 49 |
+
|
| 50 |
+
# ═══════════════════════════════════════════════════════════
|
| 51 |
+
# OPTION B: UNPACK TO INDIVIDUAL FILES (if needed)
|
| 52 |
+
# ═══════════════════════════════════════════════════════════
|
| 53 |
+
|
| 54 |
+
def unpack_dataset():
|
| 55 |
+
"""Unpack merged files back to individual files (optional)"""
|
| 56 |
+
|
| 57 |
+
print("\n📦 Unpacking to individual files...")
|
| 58 |
+
|
| 59 |
+
os.makedirs(os.path.join(OUTPUT_DIR, "frames"), exist_ok=True)
|
| 60 |
+
os.makedirs(os.path.join(OUTPUT_DIR, "actions"), exist_ok=True)
|
| 61 |
+
|
| 62 |
+
# Unpack frames
|
| 63 |
+
chunk_files = sorted([f for f in os.listdir(DOWNLOAD_DIR) if f.startswith("frames_chunk")])
|
| 64 |
+
|
| 65 |
+
frame_idx = 0
|
| 66 |
+
for chunk_file in chunk_files:
|
| 67 |
+
print(f" Unpacking {chunk_file}...")
|
| 68 |
+
data = np.load(os.path.join(DOWNLOAD_DIR, chunk_file))
|
| 69 |
+
frames = data['frames']
|
| 70 |
+
|
| 71 |
+
for i in tqdm(range(len(frames)), desc=f" {chunk_file}"):
|
| 72 |
+
np.save(
|
| 73 |
+
os.path.join(OUTPUT_DIR, "frames", f"{frame_idx:06d}.npy"),
|
| 74 |
+
frames[i]
|
| 75 |
+
)
|
| 76 |
+
frame_idx += 1
|
| 77 |
+
|
| 78 |
+
data.close()
|
| 79 |
+
|
| 80 |
+
# Unpack actions
|
| 81 |
+
print(" Unpacking actions.jsonl...")
|
| 82 |
+
with open(os.path.join(DOWNLOAD_DIR, "actions.jsonl"), 'r') as f:
|
| 83 |
+
for idx, line in enumerate(tqdm(f, desc=" actions")):
|
| 84 |
+
action_data = json.loads(line)
|
| 85 |
+
with open(os.path.join(OUTPUT_DIR, "actions", f"{idx:06d}.json"), 'w') as out_f:
|
| 86 |
+
json.dump(action_data, out_f)
|
| 87 |
+
|
| 88 |
+
print(f"\n✅ Unpacked to {OUTPUT_DIR}/")
|
| 89 |
+
|
| 90 |
+
# Uncomment to unpack:
|
| 91 |
+
# unpack_dataset()
|