File size: 2,108 Bytes
d2efaca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)
    # Normalize column access
    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  # local import
                total += len(pd.read_csv(csv_path))
    if total:
        print(f"Overall: {total_ok}/{total} rows valid")


if __name__ == "__main__":
    main()