eval: add eval_results.json, model-index, fix evaluate.py NaN→null
Browse files- evaluate.py +19 -3
evaluate.py
CHANGED
|
@@ -331,6 +331,17 @@ def evaluate_dataset(
|
|
| 331 |
# HF output helpers
|
| 332 |
# ---------------------------------------------------------------------------
|
| 333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
def build_eval_json(rows: list) -> dict:
|
| 335 |
"""Build eval_results.json dict from accumulated CSV rows."""
|
| 336 |
from collections import defaultdict
|
|
@@ -384,7 +395,7 @@ def push_to_hf(
|
|
| 384 |
repo_id = "WEO-SAS/sen2sr"
|
| 385 |
|
| 386 |
# Push eval_results.json
|
| 387 |
-
eval_str = json.dumps(eval_json, indent=2)
|
| 388 |
api.upload_file(
|
| 389 |
path_or_fileobj=eval_str.encode(),
|
| 390 |
path_in_repo="eval_results.json",
|
|
@@ -500,7 +511,7 @@ def main():
|
|
| 500 |
arrow = "↑" if m in ("synthesis", "improvement") else "↓"
|
| 501 |
print(f" {m:<16} {metrics.get(m, float('nan')):>9.4f} {arrow}")
|
| 502 |
|
| 503 |
-
# Save CSV
|
| 504 |
if rows:
|
| 505 |
fieldnames = ["variant", "dataset"] + METRIC_COLS
|
| 506 |
with open(args.output, "w", newline="") as f:
|
|
@@ -508,6 +519,12 @@ def main():
|
|
| 508 |
writer.writeheader()
|
| 509 |
writer.writerows(rows)
|
| 510 |
print(f"\nResults saved to: {args.output}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
else:
|
| 512 |
print("\nNo results to save.")
|
| 513 |
|
|
@@ -542,7 +559,6 @@ def main():
|
|
| 542 |
print("\n[WARN] No HF token — skipping push. Pass --hf-token or set HF_TOKEN.")
|
| 543 |
else:
|
| 544 |
print("\nPushing results to HuggingFace...")
|
| 545 |
-
eval_json = build_eval_json(rows)
|
| 546 |
push_to_hf(eval_json, images_dir, args.output, hf_token)
|
| 547 |
print("Done.")
|
| 548 |
|
|
|
|
| 331 |
# HF output helpers
|
| 332 |
# ---------------------------------------------------------------------------
|
| 333 |
|
| 334 |
+
def _nan_to_null(obj):
|
| 335 |
+
"""Recursively replace float NaN with None so json.dump produces valid JSON."""
|
| 336 |
+
if isinstance(obj, float) and np.isnan(obj):
|
| 337 |
+
return None
|
| 338 |
+
if isinstance(obj, dict):
|
| 339 |
+
return {k: _nan_to_null(v) for k, v in obj.items()}
|
| 340 |
+
if isinstance(obj, list):
|
| 341 |
+
return [_nan_to_null(v) for v in obj]
|
| 342 |
+
return obj
|
| 343 |
+
|
| 344 |
+
|
| 345 |
def build_eval_json(rows: list) -> dict:
|
| 346 |
"""Build eval_results.json dict from accumulated CSV rows."""
|
| 347 |
from collections import defaultdict
|
|
|
|
| 395 |
repo_id = "WEO-SAS/sen2sr"
|
| 396 |
|
| 397 |
# Push eval_results.json
|
| 398 |
+
eval_str = json.dumps(_nan_to_null(eval_json), indent=2)
|
| 399 |
api.upload_file(
|
| 400 |
path_or_fileobj=eval_str.encode(),
|
| 401 |
path_in_repo="eval_results.json",
|
|
|
|
| 511 |
arrow = "↑" if m in ("synthesis", "improvement") else "↓"
|
| 512 |
print(f" {m:<16} {metrics.get(m, float('nan')):>9.4f} {arrow}")
|
| 513 |
|
| 514 |
+
# Save CSV + eval_results.json
|
| 515 |
if rows:
|
| 516 |
fieldnames = ["variant", "dataset"] + METRIC_COLS
|
| 517 |
with open(args.output, "w", newline="") as f:
|
|
|
|
| 519 |
writer.writeheader()
|
| 520 |
writer.writerows(rows)
|
| 521 |
print(f"\nResults saved to: {args.output}")
|
| 522 |
+
|
| 523 |
+
eval_json = build_eval_json(rows)
|
| 524 |
+
json_path = Path(args.output).parent / "eval_results.json"
|
| 525 |
+
with open(json_path, "w") as f:
|
| 526 |
+
json.dump(_nan_to_null(eval_json), f, indent=2)
|
| 527 |
+
print(f"Results saved to: {json_path}")
|
| 528 |
else:
|
| 529 |
print("\nNo results to save.")
|
| 530 |
|
|
|
|
| 559 |
print("\n[WARN] No HF token — skipping push. Pass --hf-token or set HF_TOKEN.")
|
| 560 |
else:
|
| 561 |
print("\nPushing results to HuggingFace...")
|
|
|
|
| 562 |
push_to_hf(eval_json, images_dir, args.output, hf_token)
|
| 563 |
print("Done.")
|
| 564 |
|