tkadkghdlf commited on
Commit
59dcb8f
·
verified ·
1 Parent(s): 1b4f589

Sync DemoService e67f324e83da453ceb34f001d8a99739d051c338

Browse files
api/ai-service/app/api/v1/endpoints/route_generation.py CHANGED
@@ -668,9 +668,13 @@ def discover_shapes(payload: ShapeDiscoveryRequest) -> dict[str, Any]:
668
  from gpx_outline_prefilter import load_prefilter
669
  outlines = getattr(module, "GPX_SHAPE_TEMPLATES", {})
670
  prefilter_path = workspace_dir / "data" / "models" / "gpx_outline_prefilter_experiment.pkl"
 
671
  stage = "load_prefilter"
672
  try:
673
- prefilter_model = load_prefilter(str(prefilter_path))
 
 
 
674
  outline_selection_mode = "learned_top_100_plus_geometric_12"
675
  except (OSError, ValueError, ImportError):
676
  logger.exception("GPX outline prefilter unavailable; using full search")
 
668
  from gpx_outline_prefilter import load_prefilter
669
  outlines = getattr(module, "GPX_SHAPE_TEMPLATES", {})
670
  prefilter_path = workspace_dir / "data" / "models" / "gpx_outline_prefilter_experiment.pkl"
671
+ legacy_prefilter_path = workspace_dir / "data" / "models" / "gpx_outline_prefilter_legacy.pkl"
672
  stage = "load_prefilter"
673
  try:
674
+ heart_model = load_prefilter(str(prefilter_path))
675
+ legacy_model = load_prefilter(str(legacy_prefilter_path))
676
+ prefilter_model = {label: legacy_model for label in ("dog", "symbol_star", "t_shirt")}
677
+ prefilter_model["heart"] = heart_model
678
  outline_selection_mode = "learned_top_100_plus_geometric_12"
679
  except (OSError, ValueError, ImportError):
680
  logger.exception("GPX outline prefilter unavailable; using full search")
api/ai-service/tests/test_gpx_shape_templates.py CHANGED
@@ -14,6 +14,7 @@ STAR_TEMPLATES = ROOT / "router" / "ai" / "data" / "star_shape_templates.json"
14
  ALL_STAR_TEMPLATES = ROOT / "router" / "ai" / "data" / "star_shape_templates_all.json"
15
  ALL_DOG_TEMPLATES = ROOT / "router" / "ai" / "data" / "dog_shape_templates_all.json"
16
  MULTIREGION_TEMPLATES = ROOT / "router" / "ai" / "data" / "multiregion_shape_templates_all.json"
 
17
 
18
 
19
  def test_dog_and_star_gpx_examples_are_normalized_and_closed():
@@ -68,7 +69,7 @@ def test_all_tshirt_tracks_are_packaged_for_point_discovery():
68
  exec(compile(ast.Module(body=[loader], type_ignores=[]), str(script), "exec"), scope)
69
  loaded = scope["_load_gpx_shape_templates"]()
70
  assert len(loaded["t_shirt"]) == 1067
71
- assert len(loaded["heart"]) == 53
72
  regional = json.loads(MULTIREGION_TEMPLATES.read_text(encoding="utf-8"))
73
  loaded_tshirts = {tuple(map(tuple, item)) for item in loaded["t_shirt"]}
74
  assert all(tuple(map(tuple, outline)) in loaded_tshirts
@@ -76,10 +77,14 @@ def test_all_tshirt_tracks_are_packaged_for_point_discovery():
76
 
77
 
78
  def test_heart_training_and_sample_routes_are_packaged():
 
79
  report = json.loads((ROOT / "router" / "ai" / "data" / "models" /
80
  "gatv2_next_edge_experiment.metrics.json").read_text(encoding="utf-8"))
81
  samples = json.loads((ROOT / "main" / "public" / "heart-sample-runs.json").read_text(encoding="utf-8"))
82
- assert report["sources"]["heart:seen"] == 55
 
 
 
83
  assert len(samples) == 55
84
  assert all(item["label"] == "heart" and len(item["route"]) > 1 for item in samples)
85
 
 
14
  ALL_STAR_TEMPLATES = ROOT / "router" / "ai" / "data" / "star_shape_templates_all.json"
15
  ALL_DOG_TEMPLATES = ROOT / "router" / "ai" / "data" / "dog_shape_templates_all.json"
16
  MULTIREGION_TEMPLATES = ROOT / "router" / "ai" / "data" / "multiregion_shape_templates_all.json"
17
+ ALL_HEART_TEMPLATES = ROOT / "router" / "ai" / "data" / "heart_shape_templates_all.json"
18
 
19
 
20
  def test_dog_and_star_gpx_examples_are_normalized_and_closed():
 
69
  exec(compile(ast.Module(body=[loader], type_ignores=[]), str(script), "exec"), scope)
70
  loaded = scope["_load_gpx_shape_templates"]()
71
  assert len(loaded["t_shirt"]) == 1067
72
+ assert len(loaded["heart"]) == 988
73
  regional = json.loads(MULTIREGION_TEMPLATES.read_text(encoding="utf-8"))
74
  loaded_tshirts = {tuple(map(tuple, item)) for item in loaded["t_shirt"]}
75
  assert all(tuple(map(tuple, outline)) in loaded_tshirts
 
77
 
78
 
79
  def test_heart_training_and_sample_routes_are_packaged():
80
+ hearts = json.loads(ALL_HEART_TEMPLATES.read_text(encoding="utf-8"))["heart"]
81
  report = json.loads((ROOT / "router" / "ai" / "data" / "models" /
82
  "gatv2_next_edge_experiment.metrics.json").read_text(encoding="utf-8"))
83
  samples = json.loads((ROOT / "main" / "public" / "heart-sample-runs.json").read_text(encoding="utf-8"))
84
+ assert len(hearts) == 968
85
+ assert len({tuple(map(tuple, points)) for points in hearts}) == 968
86
+ assert all(5 <= len(points) <= 25 and points[0] == points[-1] for points in hearts)
87
+ assert report["sources"]["heart:seen"] == 1055
88
  assert len(samples) == 55
89
  assert all(item["label"] == "heart" and len(item["route"]) > 1 for item in samples)
90
 
api/ai-service/tests/test_point_discovery_all_outlines.py CHANGED
@@ -57,6 +57,34 @@ def test_model_checks_every_variant_before_choosing_road_work():
57
  assert {row[1] for row in chosen} == {0, 1, 17, 18, 19}
58
 
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  def test_packaged_prefilter_can_score_candidates():
61
  checkpoint = SCRIPTS.parent / "data" / "models" / "gpx_outline_prefilter_experiment.pkl"
62
  model = load_prefilter(str(checkpoint))
@@ -70,6 +98,8 @@ def test_heart_gpx_outlines_are_packaged_for_point_discovery():
70
  assert len(outlines["heart"]) == 53
71
  assert all(5 <= len(points) <= 25 and points[0] == points[-1]
72
  for points in outlines["heart"])
 
 
73
 
74
 
75
  def test_osm_download_is_shared_by_concurrent_requests_and_reused_from_disk(tmp_path, monkeypatch):
 
57
  assert {row[1] for row in chosen} == {0, 1, 17, 18, 19}
58
 
59
 
60
+ def test_point_discovery_uses_the_model_for_each_label():
61
+ graph = nx.MultiDiGraph()
62
+ for y in range(6):
63
+ for x in range(6):
64
+ node = y * 6 + x
65
+ graph.add_node(node, y=37.5 + y * .001, x=127 + x * .001)
66
+ if x:
67
+ graph.add_edge(node, node - 1, length=100)
68
+ graph.add_edge(node - 1, node, length=100)
69
+ if y:
70
+ graph.add_edge(node, node - 6, length=100)
71
+ graph.add_edge(node - 6, node, length=100)
72
+
73
+ class Model:
74
+ def __init__(self):
75
+ self.calls = 0
76
+
77
+ def predict(self, features):
78
+ self.calls += 1
79
+ return np.ones(len(features))
80
+
81
+ models = {label: Model() for label in ("dog", "heart")}
82
+ outline = [(-.4, -.4), (.4, -.4), (.4, .4), (-.4, .4), (-.4, -.4)]
83
+ discover_shape_paths(graph, {label: [outline] for label in models},
84
+ 37.502, 127.002, prefilter_model=models, prefilter_limit=1)
85
+ assert all(model.calls == 1 for model in models.values())
86
+
87
+
88
  def test_packaged_prefilter_can_score_candidates():
89
  checkpoint = SCRIPTS.parent / "data" / "models" / "gpx_outline_prefilter_experiment.pkl"
90
  model = load_prefilter(str(checkpoint))
 
98
  assert len(outlines["heart"]) == 53
99
  assert all(5 <= len(points) <= 25 and points[0] == points[-1]
100
  for points in outlines["heart"])
101
+ new_hearts = json.loads((SCRIPTS.parent / "data" / "heart_shape_templates_all.json").read_text(encoding="utf-8"))
102
+ assert len(new_hearts["heart"]) == 968
103
 
104
 
105
  def test_osm_download_is_shared_by_concurrent_requests_and_reused_from_disk(tmp_path, monkeypatch):
router/ai/data/heart_shape_templates_all.json ADDED
The diff for this file is too large to render. See raw diff
 
router/ai/data/models/gatv2_next_edge_experiment.metrics.json CHANGED
@@ -9,30 +9,33 @@
9
  "t_shirt:seen": 1073,
10
  "t_shirt:transferred": 1072,
11
  "t_shirt:unusable": 1,
12
- "heart:seen": 55,
13
- "heart:transferred": 55
 
14
  },
15
- "decisions": 64506,
16
  "train_graph_nodes": 1409,
17
  "holdout_graph_nodes": 1150,
18
- "epochs": 4,
19
  "comparison": {
20
  "shortest_path": {
21
  "routes": 40,
22
  "successes": 40,
23
  "road_valid": 40,
24
- "mean_similarity": 0.9422798653888365,
25
- "mean_retrace": 0.022345172883368358,
26
- "mean_seconds": 0.050375000000622096
27
  },
28
  "gatv2": {
29
  "routes": 40,
30
  "successes": 40,
31
  "road_valid": 40,
32
- "mean_similarity": 0.8322764769329318,
33
- "mean_retrace": 0.06514576014409465,
34
- "mean_seconds": 0.087149999999383
35
  }
36
  },
37
- "elapsed_seconds": 96.2
38
- }
 
 
 
9
  "t_shirt:seen": 1073,
10
  "t_shirt:transferred": 1072,
11
  "t_shirt:unusable": 1,
12
+ "heart:seen": 1055,
13
+ "heart:transferred": 1053,
14
+ "heart:unusable": 2
15
  },
16
+ "decisions": 84439,
17
  "train_graph_nodes": 1409,
18
  "holdout_graph_nodes": 1150,
19
+ "epochs": 1,
20
  "comparison": {
21
  "shortest_path": {
22
  "routes": 40,
23
  "successes": 40,
24
  "road_valid": 40,
25
+ "mean_similarity": 0.9416532587520763,
26
+ "mean_retrace": 0.02078341451374554,
27
+ "mean_seconds": 0.04962500000019645
28
  },
29
  "gatv2": {
30
  "routes": 40,
31
  "successes": 40,
32
  "road_valid": 40,
33
+ "mean_similarity": 0.8226414200436818,
34
+ "mean_retrace": 0.06050105494923399,
35
+ "mean_seconds": 0.08042499999983192
36
  }
37
  },
38
+ "initial_checkpoint": "gatv2_next_edge_experiment.pt",
39
+ "learning_rate": 1e-05,
40
+ "elapsed_seconds": 53.5
41
+ }
router/ai/data/models/gatv2_next_edge_experiment.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f2d4e7f3a8f58045c535fd3a7c71097f411e193c0423eb970099d6c0ecb0ae3d
3
- size 37269
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:858fce35c9ace0ef2d25653c1d1e261984f7210792c53e6516532c3af68b1cf2
3
+ size 37397
router/ai/data/models/gpx_outline_prefilter_experiment.metrics.json CHANGED
@@ -5,11 +5,11 @@
5
  "dog": 1092,
6
  "symbol_star": 1078,
7
  "t_shirt": 1067,
8
- "heart": 53
9
  },
10
  "training_points": 8,
11
  "validation_points": 5,
12
- "training_variants": 52640,
13
  "comparison": [
14
  {
15
  "city": "seoul",
@@ -31,7 +31,7 @@
31
  },
32
  "learned50_plus12": {
33
  "oracle": 0.99204,
34
- "best": 0.98828,
35
  "selected_outlines": 62
36
  }
37
  },
@@ -55,7 +55,7 @@
55
  },
56
  "learned50_plus12": {
57
  "oracle": 0.99301,
58
- "best": 0.98914,
59
  "selected_outlines": 62
60
  }
61
  },
@@ -92,19 +92,19 @@
92
  "label": "heart",
93
  "road_nodes": 1618,
94
  "geometric12": {
95
- "oracle": 0.98922,
96
- "best": 0.98922,
97
  "selected_outlines": 12
98
  },
99
  "geometric50": {
100
- "oracle": 0.98922,
101
- "best": 0.98922,
102
  "selected_outlines": 50
103
  },
104
  "learned50_plus12": {
105
- "oracle": 0.98922,
106
- "best": 0.98922,
107
- "selected_outlines": 53
108
  }
109
  },
110
  {
@@ -127,7 +127,7 @@
127
  },
128
  "learned50_plus12": {
129
  "oracle": 0.9904,
130
- "best": 0.98077,
131
  "selected_outlines": 62
132
  }
133
  },
@@ -151,7 +151,7 @@
151
  },
152
  "learned50_plus12": {
153
  "oracle": 0.99226,
154
- "best": 0.99133,
155
  "selected_outlines": 62
156
  }
157
  },
@@ -188,19 +188,19 @@
188
  "label": "heart",
189
  "road_nodes": 3220,
190
  "geometric12": {
191
- "oracle": 0.99331,
192
- "best": 0.98699,
193
  "selected_outlines": 12
194
  },
195
  "geometric50": {
196
- "oracle": 0.99331,
197
- "best": 0.99244,
198
  "selected_outlines": 50
199
  },
200
  "learned50_plus12": {
201
- "oracle": 0.99331,
202
- "best": 0.99331,
203
- "selected_outlines": 53
204
  }
205
  },
206
  {
@@ -223,7 +223,7 @@
223
  },
224
  "learned50_plus12": {
225
  "oracle": 0.99212,
226
- "best": 0.98842,
227
  "selected_outlines": 62
228
  }
229
  },
@@ -247,7 +247,7 @@
247
  },
248
  "learned50_plus12": {
249
  "oracle": 0.99278,
250
- "best": 0.98806,
251
  "selected_outlines": 62
252
  }
253
  },
@@ -284,19 +284,19 @@
284
  "label": "heart",
285
  "road_nodes": 2496,
286
  "geometric12": {
287
- "oracle": 0.99054,
288
- "best": 0.99054,
289
  "selected_outlines": 12
290
  },
291
  "geometric50": {
292
- "oracle": 0.99054,
293
- "best": 0.99054,
294
  "selected_outlines": 50
295
  },
296
  "learned50_plus12": {
297
- "oracle": 0.99054,
298
- "best": 0.99054,
299
- "selected_outlines": 53
300
  }
301
  },
302
  {
@@ -319,7 +319,7 @@
319
  },
320
  "learned50_plus12": {
321
  "oracle": 0.95214,
322
- "best": 0.93438,
323
  "selected_outlines": 62
324
  }
325
  },
@@ -343,7 +343,7 @@
343
  },
344
  "learned50_plus12": {
345
  "oracle": 0.96777,
346
- "best": 0.96777,
347
  "selected_outlines": 62
348
  }
349
  },
@@ -367,7 +367,7 @@
367
  },
368
  "learned50_plus12": {
369
  "oracle": 0.97927,
370
- "best": 0.97091,
371
  "selected_outlines": 62
372
  }
373
  },
@@ -380,19 +380,19 @@
380
  "label": "heart",
381
  "road_nodes": 583,
382
  "geometric12": {
383
- "oracle": 0.96063,
384
- "best": 0.92313,
385
  "selected_outlines": 12
386
  },
387
  "geometric50": {
388
- "oracle": 0.96063,
389
- "best": 0.96063,
390
  "selected_outlines": 50
391
  },
392
  "learned50_plus12": {
393
- "oracle": 0.96063,
394
- "best": 0.96063,
395
- "selected_outlines": 53
396
  }
397
  },
398
  {
@@ -439,7 +439,7 @@
439
  },
440
  "learned50_plus12": {
441
  "oracle": 0.9865,
442
- "best": 0.98491,
443
  "selected_outlines": 62
444
  }
445
  },
@@ -476,21 +476,21 @@
476
  "label": "heart",
477
  "road_nodes": 520,
478
  "geometric12": {
479
- "oracle": 0.98288,
480
- "best": 0.976,
481
  "selected_outlines": 12
482
  },
483
  "geometric50": {
484
- "oracle": 0.98288,
485
- "best": 0.98288,
486
  "selected_outlines": 50
487
  },
488
  "learned50_plus12": {
489
- "oracle": 0.98288,
490
- "best": 0.98288,
491
- "selected_outlines": 53
492
  }
493
  }
494
  ],
495
- "elapsed_seconds": 195.9
496
  }
 
5
  "dog": 1092,
6
  "symbol_star": 1078,
7
  "t_shirt": 1067,
8
+ "heart": 988
9
  },
10
  "training_points": 8,
11
  "validation_points": 5,
12
+ "training_variants": 67600,
13
  "comparison": [
14
  {
15
  "city": "seoul",
 
31
  },
32
  "learned50_plus12": {
33
  "oracle": 0.99204,
34
+ "best": 0.98592,
35
  "selected_outlines": 62
36
  }
37
  },
 
55
  },
56
  "learned50_plus12": {
57
  "oracle": 0.99301,
58
+ "best": 0.98804,
59
  "selected_outlines": 62
60
  }
61
  },
 
92
  "label": "heart",
93
  "road_nodes": 1618,
94
  "geometric12": {
95
+ "oracle": 0.99375,
96
+ "best": 0.98441,
97
  "selected_outlines": 12
98
  },
99
  "geometric50": {
100
+ "oracle": 0.99375,
101
+ "best": 0.9924,
102
  "selected_outlines": 50
103
  },
104
  "learned50_plus12": {
105
+ "oracle": 0.99375,
106
+ "best": 0.99035,
107
+ "selected_outlines": 62
108
  }
109
  },
110
  {
 
127
  },
128
  "learned50_plus12": {
129
  "oracle": 0.9904,
130
+ "best": 0.98134,
131
  "selected_outlines": 62
132
  }
133
  },
 
151
  },
152
  "learned50_plus12": {
153
  "oracle": 0.99226,
154
+ "best": 0.99007,
155
  "selected_outlines": 62
156
  }
157
  },
 
188
  "label": "heart",
189
  "road_nodes": 3220,
190
  "geometric12": {
191
+ "oracle": 0.99547,
192
+ "best": 0.99299,
193
  "selected_outlines": 12
194
  },
195
  "geometric50": {
196
+ "oracle": 0.99547,
197
+ "best": 0.99315,
198
  "selected_outlines": 50
199
  },
200
  "learned50_plus12": {
201
+ "oracle": 0.99547,
202
+ "best": 0.99452,
203
+ "selected_outlines": 62
204
  }
205
  },
206
  {
 
223
  },
224
  "learned50_plus12": {
225
  "oracle": 0.99212,
226
+ "best": 0.9837,
227
  "selected_outlines": 62
228
  }
229
  },
 
247
  },
248
  "learned50_plus12": {
249
  "oracle": 0.99278,
250
+ "best": 0.98754,
251
  "selected_outlines": 62
252
  }
253
  },
 
284
  "label": "heart",
285
  "road_nodes": 2496,
286
  "geometric12": {
287
+ "oracle": 0.99662,
288
+ "best": 0.99182,
289
  "selected_outlines": 12
290
  },
291
  "geometric50": {
292
+ "oracle": 0.99662,
293
+ "best": 0.99496,
294
  "selected_outlines": 50
295
  },
296
  "learned50_plus12": {
297
+ "oracle": 0.99662,
298
+ "best": 0.99355,
299
+ "selected_outlines": 62
300
  }
301
  },
302
  {
 
319
  },
320
  "learned50_plus12": {
321
  "oracle": 0.95214,
322
+ "best": 0.94418,
323
  "selected_outlines": 62
324
  }
325
  },
 
343
  },
344
  "learned50_plus12": {
345
  "oracle": 0.96777,
346
+ "best": 0.93434,
347
  "selected_outlines": 62
348
  }
349
  },
 
367
  },
368
  "learned50_plus12": {
369
  "oracle": 0.97927,
370
+ "best": 0.9607,
371
  "selected_outlines": 62
372
  }
373
  },
 
380
  "label": "heart",
381
  "road_nodes": 583,
382
  "geometric12": {
383
+ "oracle": 0.97993,
384
+ "best": 0.95661,
385
  "selected_outlines": 12
386
  },
387
  "geometric50": {
388
+ "oracle": 0.97993,
389
+ "best": 0.95661,
390
  "selected_outlines": 50
391
  },
392
  "learned50_plus12": {
393
+ "oracle": 0.97993,
394
+ "best": 0.97593,
395
+ "selected_outlines": 62
396
  }
397
  },
398
  {
 
439
  },
440
  "learned50_plus12": {
441
  "oracle": 0.9865,
442
+ "best": 0.98308,
443
  "selected_outlines": 62
444
  }
445
  },
 
476
  "label": "heart",
477
  "road_nodes": 520,
478
  "geometric12": {
479
+ "oracle": 0.99205,
480
+ "best": 0.97421,
481
  "selected_outlines": 12
482
  },
483
  "geometric50": {
484
+ "oracle": 0.99205,
485
+ "best": 0.9896,
486
  "selected_outlines": 50
487
  },
488
  "learned50_plus12": {
489
+ "oracle": 0.99205,
490
+ "best": 0.99147,
491
+ "selected_outlines": 62
492
  }
493
  }
494
  ],
495
+ "elapsed_seconds": 690.0
496
  }
router/ai/data/models/gpx_outline_prefilter_experiment.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:efe2bab6254e53f2251a30bf9b78d7553b1ac7ecea2b6e9c006fc86c397b79bd
3
- size 606224
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f3871ba906cb05f8fb0e84be9106c3151753b81b690975222f666fd300049aae
3
+ size 606267
router/ai/data/models/gpx_outline_prefilter_legacy.metrics.json ADDED
@@ -0,0 +1,496 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "GPXOutlinePrefilterHGB",
3
+ "feature_version": 3,
4
+ "outline_counts": {
5
+ "dog": 1092,
6
+ "symbol_star": 1078,
7
+ "t_shirt": 1067,
8
+ "heart": 53
9
+ },
10
+ "training_points": 8,
11
+ "validation_points": 5,
12
+ "training_variants": 52640,
13
+ "comparison": [
14
+ {
15
+ "city": "seoul",
16
+ "point": [
17
+ 37.5,
18
+ 127.061
19
+ ],
20
+ "label": "dog",
21
+ "road_nodes": 1618,
22
+ "geometric12": {
23
+ "oracle": 0.99204,
24
+ "best": 0.97908,
25
+ "selected_outlines": 12
26
+ },
27
+ "geometric50": {
28
+ "oracle": 0.99204,
29
+ "best": 0.99204,
30
+ "selected_outlines": 50
31
+ },
32
+ "learned50_plus12": {
33
+ "oracle": 0.99204,
34
+ "best": 0.98828,
35
+ "selected_outlines": 62
36
+ }
37
+ },
38
+ {
39
+ "city": "seoul",
40
+ "point": [
41
+ 37.5,
42
+ 127.061
43
+ ],
44
+ "label": "symbol_star",
45
+ "road_nodes": 1618,
46
+ "geometric12": {
47
+ "oracle": 0.99301,
48
+ "best": 0.97965,
49
+ "selected_outlines": 12
50
+ },
51
+ "geometric50": {
52
+ "oracle": 0.99301,
53
+ "best": 0.98804,
54
+ "selected_outlines": 50
55
+ },
56
+ "learned50_plus12": {
57
+ "oracle": 0.99301,
58
+ "best": 0.98914,
59
+ "selected_outlines": 62
60
+ }
61
+ },
62
+ {
63
+ "city": "seoul",
64
+ "point": [
65
+ 37.5,
66
+ 127.061
67
+ ],
68
+ "label": "t_shirt",
69
+ "road_nodes": 1618,
70
+ "geometric12": {
71
+ "oracle": 0.99371,
72
+ "best": 0.98272,
73
+ "selected_outlines": 12
74
+ },
75
+ "geometric50": {
76
+ "oracle": 0.99371,
77
+ "best": 0.99371,
78
+ "selected_outlines": 50
79
+ },
80
+ "learned50_plus12": {
81
+ "oracle": 0.99371,
82
+ "best": 0.99371,
83
+ "selected_outlines": 62
84
+ }
85
+ },
86
+ {
87
+ "city": "seoul",
88
+ "point": [
89
+ 37.5,
90
+ 127.061
91
+ ],
92
+ "label": "heart",
93
+ "road_nodes": 1618,
94
+ "geometric12": {
95
+ "oracle": 0.98922,
96
+ "best": 0.98922,
97
+ "selected_outlines": 12
98
+ },
99
+ "geometric50": {
100
+ "oracle": 0.98922,
101
+ "best": 0.98922,
102
+ "selected_outlines": 50
103
+ },
104
+ "learned50_plus12": {
105
+ "oracle": 0.98922,
106
+ "best": 0.98922,
107
+ "selected_outlines": 53
108
+ }
109
+ },
110
+ {
111
+ "city": "seoul",
112
+ "point": [
113
+ 37.516,
114
+ 127.049
115
+ ],
116
+ "label": "dog",
117
+ "road_nodes": 3220,
118
+ "geometric12": {
119
+ "oracle": 0.9904,
120
+ "best": 0.97992,
121
+ "selected_outlines": 12
122
+ },
123
+ "geometric50": {
124
+ "oracle": 0.9904,
125
+ "best": 0.98134,
126
+ "selected_outlines": 50
127
+ },
128
+ "learned50_plus12": {
129
+ "oracle": 0.9904,
130
+ "best": 0.98077,
131
+ "selected_outlines": 62
132
+ }
133
+ },
134
+ {
135
+ "city": "seoul",
136
+ "point": [
137
+ 37.516,
138
+ 127.049
139
+ ],
140
+ "label": "symbol_star",
141
+ "road_nodes": 3220,
142
+ "geometric12": {
143
+ "oracle": 0.99226,
144
+ "best": 0.98803,
145
+ "selected_outlines": 12
146
+ },
147
+ "geometric50": {
148
+ "oracle": 0.99226,
149
+ "best": 0.99018,
150
+ "selected_outlines": 50
151
+ },
152
+ "learned50_plus12": {
153
+ "oracle": 0.99226,
154
+ "best": 0.99133,
155
+ "selected_outlines": 62
156
+ }
157
+ },
158
+ {
159
+ "city": "seoul",
160
+ "point": [
161
+ 37.516,
162
+ 127.049
163
+ ],
164
+ "label": "t_shirt",
165
+ "road_nodes": 3220,
166
+ "geometric12": {
167
+ "oracle": 0.99653,
168
+ "best": 0.99215,
169
+ "selected_outlines": 12
170
+ },
171
+ "geometric50": {
172
+ "oracle": 0.99653,
173
+ "best": 0.99215,
174
+ "selected_outlines": 50
175
+ },
176
+ "learned50_plus12": {
177
+ "oracle": 0.99653,
178
+ "best": 0.99653,
179
+ "selected_outlines": 62
180
+ }
181
+ },
182
+ {
183
+ "city": "seoul",
184
+ "point": [
185
+ 37.516,
186
+ 127.049
187
+ ],
188
+ "label": "heart",
189
+ "road_nodes": 3220,
190
+ "geometric12": {
191
+ "oracle": 0.99331,
192
+ "best": 0.98699,
193
+ "selected_outlines": 12
194
+ },
195
+ "geometric50": {
196
+ "oracle": 0.99331,
197
+ "best": 0.99244,
198
+ "selected_outlines": 50
199
+ },
200
+ "learned50_plus12": {
201
+ "oracle": 0.99331,
202
+ "best": 0.99331,
203
+ "selected_outlines": 53
204
+ }
205
+ },
206
+ {
207
+ "city": "seoul",
208
+ "point": [
209
+ 37.528,
210
+ 127.038
211
+ ],
212
+ "label": "dog",
213
+ "road_nodes": 2496,
214
+ "geometric12": {
215
+ "oracle": 0.99212,
216
+ "best": 0.97976,
217
+ "selected_outlines": 12
218
+ },
219
+ "geometric50": {
220
+ "oracle": 0.99212,
221
+ "best": 0.98044,
222
+ "selected_outlines": 50
223
+ },
224
+ "learned50_plus12": {
225
+ "oracle": 0.99212,
226
+ "best": 0.98842,
227
+ "selected_outlines": 62
228
+ }
229
+ },
230
+ {
231
+ "city": "seoul",
232
+ "point": [
233
+ 37.528,
234
+ 127.038
235
+ ],
236
+ "label": "symbol_star",
237
+ "road_nodes": 2496,
238
+ "geometric12": {
239
+ "oracle": 0.99278,
240
+ "best": 0.98435,
241
+ "selected_outlines": 12
242
+ },
243
+ "geometric50": {
244
+ "oracle": 0.99278,
245
+ "best": 0.98714,
246
+ "selected_outlines": 50
247
+ },
248
+ "learned50_plus12": {
249
+ "oracle": 0.99278,
250
+ "best": 0.98806,
251
+ "selected_outlines": 62
252
+ }
253
+ },
254
+ {
255
+ "city": "seoul",
256
+ "point": [
257
+ 37.528,
258
+ 127.038
259
+ ],
260
+ "label": "t_shirt",
261
+ "road_nodes": 2496,
262
+ "geometric12": {
263
+ "oracle": 0.99486,
264
+ "best": 0.98839,
265
+ "selected_outlines": 12
266
+ },
267
+ "geometric50": {
268
+ "oracle": 0.99486,
269
+ "best": 0.99069,
270
+ "selected_outlines": 50
271
+ },
272
+ "learned50_plus12": {
273
+ "oracle": 0.99486,
274
+ "best": 0.99209,
275
+ "selected_outlines": 62
276
+ }
277
+ },
278
+ {
279
+ "city": "seoul",
280
+ "point": [
281
+ 37.528,
282
+ 127.038
283
+ ],
284
+ "label": "heart",
285
+ "road_nodes": 2496,
286
+ "geometric12": {
287
+ "oracle": 0.99054,
288
+ "best": 0.99054,
289
+ "selected_outlines": 12
290
+ },
291
+ "geometric50": {
292
+ "oracle": 0.99054,
293
+ "best": 0.99054,
294
+ "selected_outlines": 50
295
+ },
296
+ "learned50_plus12": {
297
+ "oracle": 0.99054,
298
+ "best": 0.99054,
299
+ "selected_outlines": 53
300
+ }
301
+ },
302
+ {
303
+ "city": "busan",
304
+ "point": [
305
+ 35.17,
306
+ 129.066
307
+ ],
308
+ "label": "dog",
309
+ "road_nodes": 583,
310
+ "geometric12": {
311
+ "oracle": 0.95214,
312
+ "best": 0.91957,
313
+ "selected_outlines": 12
314
+ },
315
+ "geometric50": {
316
+ "oracle": 0.95214,
317
+ "best": 0.93395,
318
+ "selected_outlines": 50
319
+ },
320
+ "learned50_plus12": {
321
+ "oracle": 0.95214,
322
+ "best": 0.93438,
323
+ "selected_outlines": 62
324
+ }
325
+ },
326
+ {
327
+ "city": "busan",
328
+ "point": [
329
+ 35.17,
330
+ 129.066
331
+ ],
332
+ "label": "symbol_star",
333
+ "road_nodes": 583,
334
+ "geometric12": {
335
+ "oracle": 0.96777,
336
+ "best": 0.93434,
337
+ "selected_outlines": 12
338
+ },
339
+ "geometric50": {
340
+ "oracle": 0.96777,
341
+ "best": 0.95557,
342
+ "selected_outlines": 50
343
+ },
344
+ "learned50_plus12": {
345
+ "oracle": 0.96777,
346
+ "best": 0.96777,
347
+ "selected_outlines": 62
348
+ }
349
+ },
350
+ {
351
+ "city": "busan",
352
+ "point": [
353
+ 35.17,
354
+ 129.066
355
+ ],
356
+ "label": "t_shirt",
357
+ "road_nodes": 583,
358
+ "geometric12": {
359
+ "oracle": 0.97927,
360
+ "best": 0.95512,
361
+ "selected_outlines": 12
362
+ },
363
+ "geometric50": {
364
+ "oracle": 0.97927,
365
+ "best": 0.95512,
366
+ "selected_outlines": 50
367
+ },
368
+ "learned50_plus12": {
369
+ "oracle": 0.97927,
370
+ "best": 0.97091,
371
+ "selected_outlines": 62
372
+ }
373
+ },
374
+ {
375
+ "city": "busan",
376
+ "point": [
377
+ 35.17,
378
+ 129.066
379
+ ],
380
+ "label": "heart",
381
+ "road_nodes": 583,
382
+ "geometric12": {
383
+ "oracle": 0.96063,
384
+ "best": 0.92313,
385
+ "selected_outlines": 12
386
+ },
387
+ "geometric50": {
388
+ "oracle": 0.96063,
389
+ "best": 0.96063,
390
+ "selected_outlines": 50
391
+ },
392
+ "learned50_plus12": {
393
+ "oracle": 0.96063,
394
+ "best": 0.96063,
395
+ "selected_outlines": 53
396
+ }
397
+ },
398
+ {
399
+ "city": "busan",
400
+ "point": [
401
+ 35.178,
402
+ 129.078
403
+ ],
404
+ "label": "dog",
405
+ "road_nodes": 520,
406
+ "geometric12": {
407
+ "oracle": 0.98287,
408
+ "best": 0.96987,
409
+ "selected_outlines": 12
410
+ },
411
+ "geometric50": {
412
+ "oracle": 0.98287,
413
+ "best": 0.97088,
414
+ "selected_outlines": 50
415
+ },
416
+ "learned50_plus12": {
417
+ "oracle": 0.98287,
418
+ "best": 0.97505,
419
+ "selected_outlines": 62
420
+ }
421
+ },
422
+ {
423
+ "city": "busan",
424
+ "point": [
425
+ 35.178,
426
+ 129.078
427
+ ],
428
+ "label": "symbol_star",
429
+ "road_nodes": 520,
430
+ "geometric12": {
431
+ "oracle": 0.9865,
432
+ "best": 0.97926,
433
+ "selected_outlines": 12
434
+ },
435
+ "geometric50": {
436
+ "oracle": 0.9865,
437
+ "best": 0.98262,
438
+ "selected_outlines": 50
439
+ },
440
+ "learned50_plus12": {
441
+ "oracle": 0.9865,
442
+ "best": 0.98491,
443
+ "selected_outlines": 62
444
+ }
445
+ },
446
+ {
447
+ "city": "busan",
448
+ "point": [
449
+ 35.178,
450
+ 129.078
451
+ ],
452
+ "label": "t_shirt",
453
+ "road_nodes": 520,
454
+ "geometric12": {
455
+ "oracle": 0.99289,
456
+ "best": 0.98704,
457
+ "selected_outlines": 12
458
+ },
459
+ "geometric50": {
460
+ "oracle": 0.99289,
461
+ "best": 0.98704,
462
+ "selected_outlines": 50
463
+ },
464
+ "learned50_plus12": {
465
+ "oracle": 0.99289,
466
+ "best": 0.98704,
467
+ "selected_outlines": 62
468
+ }
469
+ },
470
+ {
471
+ "city": "busan",
472
+ "point": [
473
+ 35.178,
474
+ 129.078
475
+ ],
476
+ "label": "heart",
477
+ "road_nodes": 520,
478
+ "geometric12": {
479
+ "oracle": 0.98288,
480
+ "best": 0.976,
481
+ "selected_outlines": 12
482
+ },
483
+ "geometric50": {
484
+ "oracle": 0.98288,
485
+ "best": 0.98288,
486
+ "selected_outlines": 50
487
+ },
488
+ "learned50_plus12": {
489
+ "oracle": 0.98288,
490
+ "best": 0.98288,
491
+ "selected_outlines": 53
492
+ }
493
+ }
494
+ ],
495
+ "elapsed_seconds": 195.9
496
+ }
router/ai/data/models/gpx_outline_prefilter_legacy.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:efe2bab6254e53f2251a30bf9b78d7553b1ac7ecea2b6e9c006fc86c397b79bd
3
+ size 606224
router/ai/scripts/build_heart_shape_templates.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Package the heart_1000_all.gpx tracks as location-free route outlines."""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ import sys
6
+ import xml.etree.ElementTree as ET
7
+ from pathlib import Path
8
+
9
+ from build_gpx_shape_templates import normalized_outline_from_track
10
+
11
+
12
+ def build(source: Path) -> dict[str, list[list[list[float]]]]:
13
+ outlines = []
14
+ seen = set()
15
+ for index, track in enumerate(ET.parse(source).getroot().iter()):
16
+ if track.tag.rsplit("}", 1)[-1] != "trk":
17
+ continue
18
+ points = [(float(node.attrib["lat"]), float(node.attrib["lon"]))
19
+ for node in track.iter() if node.tag.rsplit("}", 1)[-1] == "trkpt"]
20
+ try:
21
+ outline = normalized_outline_from_track(points, f"{source.name}:{index}")
22
+ except ValueError:
23
+ continue
24
+ signature = tuple(map(tuple, outline))
25
+ if signature not in seen:
26
+ seen.add(signature)
27
+ outlines.append(outline)
28
+ if not outlines:
29
+ raise ValueError("No valid heart GPX tracks found")
30
+ return {"heart": outlines}
31
+
32
+
33
+ if __name__ == "__main__":
34
+ if len(sys.argv) != 3:
35
+ raise SystemExit("Usage: build_heart_shape_templates.py heart_1000_all.gpx OUTPUT_JSON")
36
+ output = Path(sys.argv[2])
37
+ payload = build(Path(sys.argv[1]))
38
+ output.parent.mkdir(parents=True, exist_ok=True)
39
+ output.write_text(json.dumps(payload, separators=(",", ":")) + "\n", encoding="utf-8")
40
+ print(len(payload["heart"]))
router/ai/scripts/clip_osm_region_test.py CHANGED
@@ -148,7 +148,7 @@ def _load_gpx_shape_templates() -> dict[str, list[list[tuple[float, float]]]]:
148
  data_dir = Path(__file__).resolve().parents[1] / "data"
149
  templates: dict[str, list[list[tuple[float, float]]]] = {"dog": [], "symbol_star": [], "t_shirt": [], "heart": []}
150
  seen: dict[str, set[tuple[tuple[float, float], ...]]] = {label: set() for label in templates}
151
- for filename in ("gpx_shape_templates.json", "approved_road_shape_templates.json", "tshirt_shape_templates.json", "tshirt_shape_templates_all.json", "star_shape_templates.json", "star_shape_templates_all.json", "dog_shape_templates_all.json", "multiregion_shape_templates_all.json"):
152
  try:
153
  payload = json.loads((data_dir / filename).read_text(encoding="utf-8"))
154
  except (OSError, ValueError, TypeError):
 
148
  data_dir = Path(__file__).resolve().parents[1] / "data"
149
  templates: dict[str, list[list[tuple[float, float]]]] = {"dog": [], "symbol_star": [], "t_shirt": [], "heart": []}
150
  seen: dict[str, set[tuple[tuple[float, float], ...]]] = {label: set() for label in templates}
151
+ for filename in ("gpx_shape_templates.json", "approved_road_shape_templates.json", "tshirt_shape_templates.json", "tshirt_shape_templates_all.json", "star_shape_templates.json", "star_shape_templates_all.json", "dog_shape_templates_all.json", "multiregion_shape_templates_all.json", "heart_shape_templates_all.json"):
152
  try:
153
  payload = json.loads((data_dir / filename).read_text(encoding="utf-8"))
154
  except (OSError, ValueError, TypeError):
router/ai/scripts/experimental_next_edge_service.py CHANGED
@@ -220,7 +220,9 @@ def discover_shape_paths(graph, outlines_by_label, latitude, longitude, *,
220
  candidates = []
221
  screened = screen_variants(road, start, outlines, label, snap_limit=snap_limit)
222
  if prefilter_model is not None:
223
- screened = choose_variants(screened, prefilter_model, limit=prefilter_limit)
 
 
224
  selected = []
225
  per_outline = Counter()
226
  for _, outline_index, anchors, _ in sorted(screened, key=lambda row: row[0]):
 
220
  candidates = []
221
  screened = screen_variants(road, start, outlines, label, snap_limit=snap_limit)
222
  if prefilter_model is not None:
223
+ model = prefilter_model.get(label) if isinstance(prefilter_model, dict) else prefilter_model
224
+ if model is not None:
225
+ screened = choose_variants(screened, model, limit=prefilter_limit)
226
  selected = []
227
  per_outline = Counter()
228
  for _, outline_index, anchors, _ in sorted(screened, key=lambda row: row[0]):
router/ai/scripts/train_gpx_next_edge_full.py CHANGED
@@ -94,11 +94,17 @@ def batched_logits(model: NextEdgeGATv2, batch: Batch):
94
  return nn.utils.rnn.pad_sequence(rows, batch_first=True, padding_value=-1e9)
95
 
96
 
97
- def train_batched(examples, *, epochs: int, seed: int, batch_size: int):
 
98
  torch.manual_seed(seed)
99
  torch.set_num_threads(min(4, torch.get_num_threads()))
100
  model = NextEdgeGATv2()
101
- optimizer = torch.optim.AdamW(model.parameters(), lr=.002, weight_decay=.0005)
 
 
 
 
 
102
  rng = random.Random(seed)
103
  data = [Data(x=x, edge_index=edges, y=torch.tensor(answer, dtype=torch.long))
104
  for x, edges, answer in examples]
@@ -124,18 +130,21 @@ def main():
124
  parser.add_argument("--holdout-graph", type=Path, required=True)
125
  for name in ("dog", "star", "tshirt"):
126
  parser.add_argument(f"--{name}-all", type=Path, required=True)
 
127
  parser.add_argument("--supplemental-all", type=Path, required=True)
128
  parser.add_argument("--output", type=Path, required=True)
129
  parser.add_argument("--max-tracks", type=int, default=0, help="0 means every track")
130
  parser.add_argument("--epochs", type=int, default=4)
131
  parser.add_argument("--batch-size", type=int, default=128)
132
  parser.add_argument("--examples-per-track", type=int, default=20)
 
 
133
  args = parser.parse_args()
134
  started = time.monotonic()
135
  road = strongest_walk_component(ox.load_graphml(args.graph))
136
  holdout = strongest_walk_component(ox.load_graphml(args.holdout_graph))
137
  sources = {"dog": args.dog_all, "symbol_star": args.star_all,
138
- "t_shirt": args.tshirt_all, "heart": None}
139
  additional = supplemental_tracks(args.supplemental_all)
140
  examples, report_samples = [], []
141
  counts = Counter()
@@ -169,11 +178,14 @@ def main():
169
  print(f"{label}: {index + 1} tracks, {len(examples)} decisions, {time.monotonic() - started:.0f}s", flush=True)
170
  if any(counts[f"{label}:seen"] == 0 or counts[f"{label}:matched"] + counts[f"{label}:transferred"] == 0 for label in LABELS):
171
  raise RuntimeError("Every label needs usable GPX routes")
172
- model = train_batched(examples, epochs=args.epochs, seed=42, batch_size=args.batch_size)
 
173
  comparison = evaluate(holdout, report_samples, model)
174
  report = {"sources": dict(counts), "decisions": len(examples),
175
  "train_graph_nodes": len(road.ids), "holdout_graph_nodes": len(holdout.ids),
176
  "epochs": args.epochs, "comparison": comparison,
 
 
177
  "elapsed_seconds": round(time.monotonic() - started, 1)}
178
  args.output.parent.mkdir(parents=True, exist_ok=True)
179
  torch.save({"architecture": "NextEdgeGATv2", "model": model.state_dict(),
 
94
  return nn.utils.rnn.pad_sequence(rows, batch_first=True, padding_value=-1e9)
95
 
96
 
97
+ def train_batched(examples, *, epochs: int, seed: int, batch_size: int,
98
+ initial_checkpoint: Path | None = None, learning_rate: float = .002):
99
  torch.manual_seed(seed)
100
  torch.set_num_threads(min(4, torch.get_num_threads()))
101
  model = NextEdgeGATv2()
102
+ if initial_checkpoint is not None:
103
+ checkpoint = torch.load(initial_checkpoint, map_location="cpu", weights_only=True)
104
+ if checkpoint.get("architecture") != "NextEdgeGATv2":
105
+ raise ValueError("Unexpected initial checkpoint")
106
+ model.load_state_dict(checkpoint["model"])
107
+ optimizer = torch.optim.AdamW(model.parameters(), lr=learning_rate, weight_decay=.0005)
108
  rng = random.Random(seed)
109
  data = [Data(x=x, edge_index=edges, y=torch.tensor(answer, dtype=torch.long))
110
  for x, edges, answer in examples]
 
130
  parser.add_argument("--holdout-graph", type=Path, required=True)
131
  for name in ("dog", "star", "tshirt"):
132
  parser.add_argument(f"--{name}-all", type=Path, required=True)
133
+ parser.add_argument("--heart-all", type=Path, required=True)
134
  parser.add_argument("--supplemental-all", type=Path, required=True)
135
  parser.add_argument("--output", type=Path, required=True)
136
  parser.add_argument("--max-tracks", type=int, default=0, help="0 means every track")
137
  parser.add_argument("--epochs", type=int, default=4)
138
  parser.add_argument("--batch-size", type=int, default=128)
139
  parser.add_argument("--examples-per-track", type=int, default=20)
140
+ parser.add_argument("--init-checkpoint", type=Path)
141
+ parser.add_argument("--learning-rate", type=float, default=.002)
142
  args = parser.parse_args()
143
  started = time.monotonic()
144
  road = strongest_walk_component(ox.load_graphml(args.graph))
145
  holdout = strongest_walk_component(ox.load_graphml(args.holdout_graph))
146
  sources = {"dog": args.dog_all, "symbol_star": args.star_all,
147
+ "t_shirt": args.tshirt_all, "heart": args.heart_all}
148
  additional = supplemental_tracks(args.supplemental_all)
149
  examples, report_samples = [], []
150
  counts = Counter()
 
178
  print(f"{label}: {index + 1} tracks, {len(examples)} decisions, {time.monotonic() - started:.0f}s", flush=True)
179
  if any(counts[f"{label}:seen"] == 0 or counts[f"{label}:matched"] + counts[f"{label}:transferred"] == 0 for label in LABELS):
180
  raise RuntimeError("Every label needs usable GPX routes")
181
+ model = train_batched(examples, epochs=args.epochs, seed=42, batch_size=args.batch_size,
182
+ initial_checkpoint=args.init_checkpoint, learning_rate=args.learning_rate)
183
  comparison = evaluate(holdout, report_samples, model)
184
  report = {"sources": dict(counts), "decisions": len(examples),
185
  "train_graph_nodes": len(road.ids), "holdout_graph_nodes": len(holdout.ids),
186
  "epochs": args.epochs, "comparison": comparison,
187
+ "initial_checkpoint": args.init_checkpoint.name if args.init_checkpoint else None,
188
+ "learning_rate": args.learning_rate,
189
  "elapsed_seconds": round(time.monotonic() - started, 1)}
190
  args.output.parent.mkdir(parents=True, exist_ok=True)
191
  torch.save({"architecture": "NextEdgeGATv2", "model": model.state_dict(),
router/ai/scripts/train_gpx_outline_prefilter.py CHANGED
@@ -36,7 +36,8 @@ def load_templates(directory):
36
  filenames = ("gpx_shape_templates.json", "approved_road_shape_templates.json",
37
  "tshirt_shape_templates.json", "tshirt_shape_templates_all.json",
38
  "star_shape_templates.json", "star_shape_templates_all.json",
39
- "dog_shape_templates_all.json", "multiregion_shape_templates_all.json")
 
40
  for name in filenames:
41
  payload = json.loads((directory / name).read_text(encoding="utf-8"))
42
  for label in LABELS:
 
36
  filenames = ("gpx_shape_templates.json", "approved_road_shape_templates.json",
37
  "tshirt_shape_templates.json", "tshirt_shape_templates_all.json",
38
  "star_shape_templates.json", "star_shape_templates_all.json",
39
+ "dog_shape_templates_all.json", "multiregion_shape_templates_all.json",
40
+ "heart_shape_templates_all.json")
41
  for name in filenames:
42
  payload = json.loads((directory / name).read_text(encoding="utf-8"))
43
  for label in LABELS: