| import json |
| import glob |
| import os |
| import pandas as pd |
| import numpy as np |
|
|
| |
| methods = [ |
| "vanilla_3dgs", "analyticsplatting", "erankgs", "ges", |
| "lightgaussian", "minisplatting", "opti3dgs", "pgsr", |
| "steepgs", "3dgsmcmc" |
| ] |
| scene_mapping = {"bonsai": "bonsai", "lego": "Lego"} |
| seeds = {"seed0": "", "seed1": "_seed1", "seed2": "_seed2"} |
|
|
| raw_records = [] |
|
|
| |
| print("========================================================") |
| print("开始扫描 Seed 目录...") |
| for method in methods: |
| for norm_scene, dir_scene in scene_mapping.items(): |
| for seed_id, seed_suffix in seeds.items(): |
| dir_name = f"{method}{seed_suffix}_{dir_scene}" |
| search_dir = f"outputs/{dir_name}" |
|
|
| |
| if method == "vanilla_3dgs" and seed_id == "seed0": |
| if not os.path.exists(search_dir) or not glob.glob(f"{search_dir}/metrics_test_iter*.json"): |
| search_dir = f"outputs/{method}_{dir_scene}_bak" |
|
|
| json_files = sorted(glob.glob(f"{search_dir}/metrics_test_iter*.json")) |
| psnr, ssim, lpips = np.nan, np.nan, np.nan |
| source_file = "MISSING" |
| status = "MISSING" |
|
|
| if json_files: |
| target_file = json_files[-1] |
| for jf in json_files: |
| if "30000" in jf: |
| target_file = jf |
| break |
|
|
| source_file = target_file |
| try: |
| with open(target_file, 'r') as f: |
| data = json.load(f) |
| |
| photo = data.get("photometric", data) |
| psnr = photo.get("PSNR", photo.get("psnr", np.nan)) |
| ssim = photo.get("SSIM", photo.get("ssim", np.nan)) |
| lpips = photo.get("LPIPS", photo.get("lpips", np.nan)) |
| status = "OK" |
| except Exception: |
| pass |
|
|
| |
| if method == "erankgs" and norm_scene == "lego" and psnr < 20: |
| status = "METHOD_FAILURE" |
|
|
| raw_records.append({ |
| "SceneNormalized": norm_scene, |
| "SceneDirName": dir_scene, |
| "Method": method, |
| "Seed": seed_id, |
| "PSNR": psnr, |
| "SSIM": ssim, |
| "LPIPS": lpips, |
| "Status": status, |
| "SourceFile": source_file |
| }) |
|
|
| |
| os.makedirs("outputs/phase4", exist_ok=True) |
| df_raw = pd.DataFrame(raw_records) |
| raw_path = "outputs/phase4/task_4_1_seed_variance_raw_reconstructed.csv" |
| df_raw.to_csv(raw_path, index=False) |
|
|
| |
| summary_records = [] |
| for (norm_scene, method), group in df_raw.groupby(["SceneNormalized", "Method"]): |
| psnrs = group["PSNR"].dropna() |
| n_seeds = len(psnrs) |
| psnr_mean = psnrs.mean() if n_seeds > 0 else np.nan |
| psnr_std = psnrs.std(ddof=1) if n_seeds > 1 else np.nan |
| psnr_min = psnrs.min() if n_seeds > 0 else np.nan |
| psnr_max = psnrs.max() if n_seeds > 0 else np.nan |
| psnr_range = (psnr_max - psnr_min) if n_seeds > 0 else np.nan |
|
|
| statuses = group["Status"].tolist() |
| if "METHOD_FAILURE" in statuses: |
| final_status = "METHOD_FAILURE" |
| elif method == "analyticsplatting" and norm_scene == "lego" and psnr_std > 1.0: |
| final_status = "OUTLIER" |
| elif "MISSING" in statuses and n_seeds < 3: |
| final_status = "MISSING_SEEDS" |
| else: |
| final_status = "OK" |
|
|
| summary_records.append({ |
| "Scene": norm_scene, |
| "Method": method, |
| "NSeeds": n_seeds, |
| "PSNR_mean": psnr_mean, |
| "PSNR_std": psnr_std, |
| "PSNR_min": psnr_min, |
| "PSNR_max": psnr_max, |
| "PSNR_range": psnr_range, |
| "Status": final_status |
| }) |
|
|
| df_summary = pd.DataFrame(summary_records) |
| sum_path = "outputs/phase4/task_4_1_seed_variance_summary_reconstructed.csv" |
| df_summary.to_csv(sum_path, index=False) |
|
|
| |
| tau_file = "outputs/phase4/task_4_2_kendall_tau.json" |
| tau_path = "outputs/phase4/task_4_2_kendall_tau_checked.csv" |
| if os.path.exists(tau_file): |
| with open(tau_file, 'r') as f: |
| tau_data = json.load(f) |
| tau_records = [] |
| for scene in ["bonsai", "Lego"]: |
| if scene in tau_data: |
| sc_data = tau_data[scene] |
| tau_records.append({ |
| "Scene": "lego" if scene == "Lego" else "bonsai", |
| "default_vs_seed1_tau": sc_data.get("default_vs_seed1", {}).get("tau"), |
| "default_vs_seed1_pval": sc_data.get("default_vs_seed1", {}).get("pval"), |
| "default_vs_seed2_tau": sc_data.get("default_vs_seed2", {}).get("tau"), |
| "default_vs_seed2_pval": sc_data.get("default_vs_seed2", {}).get("pval"), |
| "seed1_vs_seed2_tau": sc_data.get("seed1_vs_seed2", {}).get("tau"), |
| "seed1_vs_seed2_pval": sc_data.get("seed1_vs_seed2", {}).get("pval"), |
| "median_tau": sc_data.get("median_tau"), |
| "min_tau": sc_data.get("min_tau"), |
| "valid_methods_count": len(sc_data.get("valid_methods", [])) |
| }) |
| df_tau = pd.DataFrame(tau_records) |
| df_tau.to_csv(tau_path, index=False) |
| else: |
| print(f"⚠️ 警告: Kendall Tau 源文件缺失 {tau_file}") |
|
|
|
|
| |
| print("\n========================================================") |
| print("SANITY CHECKS") |
| print("========================================================") |
|
|
| |
| print(f"每个 scene 找到的 method 数量: bonsai = {len(df_summary[df_summary['Scene'] == 'bonsai'])}, lego = {len(df_summary[df_summary['Scene'] == 'lego'])}") |
| print(f"每个 scene 找到的 raw seed rows: bonsai = {len(df_raw[df_raw['SceneNormalized'] == 'bonsai'])}, lego = {len(df_raw[df_raw['SceneNormalized'] == 'lego'])}") |
|
|
| |
| try: |
| ana_lego = df_summary[(df_summary['Method'] == 'analyticsplatting') & (df_summary['Scene'] == 'lego')].iloc[0] |
| print(f"\n[验证] analyticsplatting x Lego") |
| print(f" - PSNR_mean: {ana_lego['PSNR_mean']:.3f}") |
| print(f" - PSNR_std: {ana_lego['PSNR_std']:.3f} (预期 ~1.33)") |
| print(f" - PSNR_range: {ana_lego['PSNR_range']:.3f} (预期 ~2.34)") |
| print(f" - Status: {ana_lego['Status']} (预期 OUTLIER)") |
| except Exception as e: |
| print("\n[错误] 未能定位 analyticsplatting x Lego 的聚合数据") |
|
|
| try: |
| era_lego = df_summary[(df_summary['Method'] == 'erankgs') & (df_summary['Scene'] == 'lego')].iloc[0] |
| print(f"\n[验证] erankgs x Lego") |
| print(f" - PSNR_mean: {era_lego['PSNR_mean']:.3f} (预期 ~17)") |
| print(f" - PSNR_std: {era_lego['PSNR_std']:.3f}") |
| print(f" - PSNR_range: {era_lego['PSNR_range']:.3f}") |
| print(f" - Status: {era_lego['Status']} (预期 METHOD_FAILURE)") |
| except Exception as e: |
| print("\n[错误] 未能定位 erankgs x Lego 的聚合数据") |
|
|
| |
| valid_stds_incl = df_summary[df_summary["Status"].isin(["OK", "OUTLIER"])]["PSNR_std"].dropna() |
| valid_stds_excl = df_summary[df_summary["Status"] == "OK"]["PSNR_std"].dropna() |
|
|
| med_incl = valid_stds_incl.median() |
| p95_incl = valid_stds_incl.quantile(0.95) |
| med_excl = valid_stds_excl.median() |
| p95_excl = valid_stds_excl.quantile(0.95) |
|
|
| print("\n[验证] Cohort PSNR Std 统计") |
| print(f" - Median (including outlier): {med_incl:.4f}") |
| print(f" - P95 (including outlier): {p95_incl:.4f}") |
| print(f" - Median (excluding outlier): {med_excl:.4f}") |
| print(f" - P95 (excluding outlier): {p95_excl:.4f}") |
|
|
| if abs(p95_incl - 0.384) > 0.005 and abs(p95_excl - 0.384) > 0.005: |
| print(f"\n⚠️ 论文一致性警告:") |
| print(f"不一致:论文中声明 P95=0.384 dB,但重算结果为包含Outlier: {p95_incl:.3f}, 排除Outlier: {p95_excl:.3f}") |
| else: |
| print(f"\n✅ P95=0.384 dB 与论文声明一致") |
|
|
| |
| if 'df_tau' in locals(): |
| print("\n[验证] Kendall Tau 值") |
| b_tau = df_tau[df_tau["Scene"] == "bonsai"]["median_tau"].iloc[0] |
| l_tau = df_tau[df_tau["Scene"] == "lego"]["median_tau"].iloc[0] |
| print(f" - bonsai median_tau: {b_tau:.4f} (预期: 0.7778)") |
| print(f" - Lego median_tau: {l_tau:.4f} (预期: 0.8571)") |
|
|
| print("\n========================================================") |
| print("生成的文件清单:") |
| print(f"1. {raw_path}") |
| print(f"2. {sum_path}") |
| print(f"3. {tau_path}") |
| print("========================================================") |
|
|