| from __future__ import annotations |
|
|
| import argparse |
| from pathlib import Path |
| import pandas as pd |
|
|
|
|
| def verify_split(split_dir: Path) -> int: |
| csv_path = split_dir / "metadata.csv" |
| if not csv_path.exists(): |
| print(f"No metadata.csv in {split_dir}; skipping.") |
| return 0 |
|
|
| df = pd.read_csv(csv_path) |
| |
| lower = {c.lower(): c for c in df.columns} |
| ic = next((lower[c] for c in ("image", "file_name", "filename", "path") if c in lower), None) |
| latc = next((lower[c] for c in ("latitude", "lat") if c in lower), None) |
| lonc = next((lower[c] for c in ("longitude", "lon", "long") if c in lower), None) |
| if ic is None or latc is None or lonc is None: |
| print(f"Missing expected columns in {csv_path}: {df.columns.tolist()}") |
| return 0 |
|
|
| bad = 0 |
| for i, row in df.iterrows(): |
| img_rel = str(row[ic]) |
| img_path = (split_dir / img_rel).resolve() |
| if not img_path.exists(): |
| print(f"[missing] {split_dir.name} row {i}: {img_rel}") |
| bad += 1 |
| continue |
| lat = float(row[latc]) |
| lon = float(row[lonc]) |
| if not (-90.0 <= lat <= 90.0) or not (-180.0 <= lon <= 180.0): |
| print(f"[range] {split_dir.name} row {i}: lat={lat}, lon={lon}") |
| bad += 1 |
| ok = len(df) - bad |
| print(f"Split {split_dir.name}: {ok}/{len(df)} rows valid") |
| return ok |
|
|
|
|
| def main(): |
| ap = argparse.ArgumentParser(description="Verify dataset metadata and paths for splits") |
| ap.add_argument("--data-dir", type=Path, default=Path("data")) |
| args = ap.parse_args() |
|
|
| total_ok = 0 |
| total = 0 |
| for split in ("train", "validation", "test"): |
| sd = args.data_dir / split |
| if sd.exists(): |
| ok = verify_split(sd) |
| total_ok += ok |
| csv_path = sd / "metadata.csv" |
| if csv_path.exists(): |
| import pandas as pd |
| total += len(pd.read_csv(csv_path)) |
| if total: |
| print(f"Overall: {total_ok}/{total} rows valid") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|
|
|