-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (54 loc) · 2.29 KB
/
main.py
File metadata and controls
68 lines (54 loc) · 2.29 KB
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
66
67
68
#!/usr/bin/env python3
import argparse
import sys
import subprocess
import os
import json
import pandas as pd
from src.tag2pixel.utils import load_config, setup_logging
from src.tag2pixel.osm import run_osm_extraction
from src.tag2pixel.labeling import run_label_generation
from src.tag2pixel.features import run_feature_extraction
logger = setup_logging("Orchestrator")
def run_r_training(cfg):
logger.info("--- Running: Model Training (R) ---")
try:
# Pass the config path if needed, though R script currently assumes root or fixed paths
subprocess.run(["Rscript", "src/r_scripts/train_rf.R"], check=True)
except subprocess.CalledProcessError as e:
logger.error(f"❌ Error during R training: {e}")
sys.exit(1)
def main():
parser = argparse.ArgumentParser(description="Tag2Pixel: Universal Geospatial Framework")
parser.add_argument("--config", default="config/config.yaml", help="Path to config file")
parser.add_argument("--step", choices=["osm", "labels", "features", "train", "all"], default="all")
args = parser.parse_args()
try:
cfg = load_config(args.config)
except Exception as e:
logger.error(f"❌ Failed to load config: {e}")
sys.exit(1)
# Ensure directories
for d in ["data/raw_osm_data", "data/ground_truth", "data/labels", "data/training", "output/plots"]:
os.makedirs(d, exist_ok=True)
steps = [args.step] if args.step != "all" else ["osm", "labels", "features", "train"]
if "osm" in steps:
logger.info("--- Step 1/4: OSM Extraction ---")
run_osm_extraction(cfg)
if "labels" in steps:
logger.info("--- Step 2/4: Label Generation ---")
run_label_generation(cfg)
if "features" in steps:
logger.info("--- Step 3/4: Feature Extraction ---")
run_feature_extraction(cfg)
if "train" in steps:
logger.info("--- Step 4/4: Model Training ---")
run_r_training(cfg)
# Post-training validation
if os.path.exists("output/metrics.json"):
with open("output/metrics.json", "r") as f:
m = json.load(f)
logger.info(f"✨ Results - AUC: {m.get('auc',0):.4f}, Acc: {m.get('accuracy',0):.4f}")
logger.info("🎉 Tag2Pixel Pipeline Finished!")
if __name__ == "__main__":
main()