import json from pathlib import Path def generate_metadata(base_path: Path, output_path: Path): """Generate metadata.jsonl for a split (e.g., data/sim/train)""" images_dir = base_path / "images" metadata = [] for scene_dir in sorted(images_dir.iterdir()): if not scene_dir.is_dir(): continue scene = scene_dir.name for img_file in sorted(scene_dir.glob("*.png")): fname = img_file.name image_path = f"images/{scene}/{fname}" seg_path = f"segmented/{scene}/{fname}" front_path = f"labels/{scene}/front/{fname}" back_path = f"labels/{scene}/back/{fname}" entry = { "file_name": image_path, "scene": scene, } if (base_path / seg_path).exists(): entry["segmentation_mask_file_name"] = seg_path if (base_path / front_path).exists(): entry["front_mask_file_name"] = front_path if (base_path / back_path).exists(): entry["back_mask_file_name"] = back_path metadata.append(entry) output_path.parent.mkdir(parents=True, exist_ok=True) with open(output_path, "w") as f: for entry in metadata: f.write(json.dumps(entry) + "\n") print(f"Generated {output_path} with {len(metadata)} entries") if __name__ == "__main__": dataset_root = Path(".") splits = [ ("sim", "train"), ("sim", "validation"), ("real", "train"), ("real", "validation"), ] for domain, split in splits: base_path = dataset_root / "data" / domain / split if base_path.exists(): output_path = base_path / "metadata.jsonl" generate_metadata(base_path, output_path) else: print(f"Skipping {base_path} (not found)")