--- license: mit --- ``` import numpy as np import json import os from huggingface_hub import snapshot_download from tqdm import tqdm # ═══════════════════════════════════════════════════════════ # CONFIG # ═══════════════════════════════════════════════════════════ HF_REPO = "nnsohamnn/runner-game-dataset" # ← Change this! DOWNLOAD_DIR = "runner_dataset_merged" OUTPUT_DIR = "runner_dataset" # ═══════════════════════════════════════════════════════════ # DOWNLOAD # ═══════════════════════════════════════════════════════════ print("📥 Downloading from Hugging Face...") snapshot_download( repo_id=HF_REPO, repo_type="dataset", local_dir=DOWNLOAD_DIR ) print("✅ Download complete!") # ═══════════════════════════════════════════════════════════ # OPTION A: USE MERGED FILES DIRECTLY (RECOMMENDED) # ═══════════════════════════════════════════════════════════ # You can use the merged files directly in training! # This is actually MORE efficient than individual files. # Example loading: print("\n📊 Dataset info:") with open(os.path.join(DOWNLOAD_DIR, "metadata.json"), 'r') as f: metadata = json.load(f) print(f" Total frames: {metadata['total_frames']:,}") print(f" Chunks: {metadata['num_chunks']}") print(f" Actions: {metadata['actions']}") # ═══════════════════════════════════════════════════════════ # OPTION B: UNPACK TO INDIVIDUAL FILES (if needed) # ═══════════════════════════════════════════════════════════ def unpack_dataset(): """Unpack merged files back to individual files (optional)""" print("\n📦 Unpacking to individual files...") os.makedirs(os.path.join(OUTPUT_DIR, "frames"), exist_ok=True) os.makedirs(os.path.join(OUTPUT_DIR, "actions"), exist_ok=True) # Unpack frames chunk_files = sorted([f for f in os.listdir(DOWNLOAD_DIR) if f.startswith("frames_chunk")]) frame_idx = 0 for chunk_file in chunk_files: print(f" Unpacking {chunk_file}...") data = np.load(os.path.join(DOWNLOAD_DIR, chunk_file)) frames = data['frames'] for i in tqdm(range(len(frames)), desc=f" {chunk_file}"): np.save( os.path.join(OUTPUT_DIR, "frames", f"{frame_idx:06d}.npy"), frames[i] ) frame_idx += 1 data.close() # Unpack actions print(" Unpacking actions.jsonl...") with open(os.path.join(DOWNLOAD_DIR, "actions.jsonl"), 'r') as f: for idx, line in enumerate(tqdm(f, desc=" actions")): action_data = json.loads(line) with open(os.path.join(OUTPUT_DIR, "actions", f"{idx:06d}.json"), 'w') as out_f: json.dump(action_data, out_f) print(f"\n✅ Unpacked to {OUTPUT_DIR}/") # Uncomment to unpack: # unpack_dataset() ```