File size: 9,274 Bytes
9affda1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import pandas as pd
import os
import json
import glob
import re
import math

# 1. 基础配置
input_csv = "outputs/phase5a/appendix_B_scene_inventory_submission_ready.csv"
output_submission = "outputs/phase5a/appendix_B_scene_inventory_submission_ready_v2.csv"
output_audit = "outputs/phase5a/appendix_B_scene_inventory_audit_v2.csv"

if not os.path.exists(input_csv):
    print(f"Error: 找不到基础文件 {input_csv}")
    exit(1)

df = pd.read_csv(input_csv)
if 'Resolution' in df.columns:
    df.rename(columns={'Resolution': 'ResolutionSetting'}, inplace=True)

# 尝试探测项目中的评估配置
eval_holdout_rule = None
eval_evidence = "unknown_from_files"

# 检查配置或脚本中是否存在 --eval 或 holdout
config_paths = glob.glob("configs/*.yaml") + glob.glob("scripts/*.py")
for cp in config_paths:
    if not os.path.exists(cp): continue
    with open(cp, 'r', encoding='utf-8') as f:
        content = f.read()
        if '--eval' in content or 'test_every' in content or 'hold' in content:
            # 3DGS 默认 COLMAP holdout 是 8
            eval_holdout_rule = 8 
            eval_evidence = f"holdout_every_8_inferred_from_project_scripts"
            break

# 2. 辅助函数:统计图片数
def count_images(dir_path):
    if not os.path.exists(dir_path): return 0
    exts = ['*.png', '*.jpg', '*.jpeg', '*.PNG', '*.JPG', '*.JPEG']
    count = 0
    for ext in exts:
        count += len(glob.glob(os.path.join(dir_path, ext)))
    return count

def get_colmap_total(base_path):
    # 尝试按 3DGS 常用规范找
    for img_dir in ['images', 'images_2', 'images_4', 'images_8', 'input', 'rgb']:
        p = os.path.join(base_path, img_dir)
        c = count_images(p)
        if c > 0: return c
    return 0

# 3. 提取引擎
records = []
for index, row in df.iterrows():
    s_key = row['SceneKey']
    d_name = row['DisplayName']
    ds = row['Dataset']
    res_set = row['ResolutionSetting']
    s_type = row['SceneType']
    
    data_path = "NOT_FOUND"
    train_views = "NEEDS_SPLIT_RULE"
    test_views = "NEEDS_SPLIT_RULE"
    total_views = "UNKNOWN"
    split_rule = "unknown_from_files"
    source_evidence = ""
    notes = ""

    # 确定物理路径
    possible_paths = []
    if ds == "NeRF-Synthetic":
        base = "/root/autodl-tmp/dataset/Synthetic_NeRF_Verified/Synthetic_NeRF"
        possible_paths = [os.path.join(base, d_name), os.path.join(base, s_key), os.path.join(base, s_key.capitalize())]
    elif ds == "Mip-NeRF 360":
        possible_paths = [f"/root/autodl-tmp/dataset/360/{s_key}"]
    elif ds == "Tanks&Temples":
        possible_paths = [f"/root/autodl-tmp/dataset/tnt/{s_key}"]
    elif ds == "Deep Blending":
        possible_paths = [f"/root/autodl-tmp/dataset/deepblending_clean/{d_name}", f"/root/autodl-tmp/dataset/deepblending_clean/{s_key}"]

    for p in possible_paths:
        if os.path.exists(p):
            data_path = p
            break

    if data_path != "NOT_FOUND":
        # 优先级 A: JSON splits (主要针对 NeRF-Synthetic)
        train_json = os.path.join(data_path, "transforms_train.json")
        test_json = os.path.join(data_path, "transforms_test.json")
        
        if os.path.exists(train_json) and os.path.exists(test_json):
            try:
                with open(train_json, 'r') as f:
                    train_data = json.load(f)
                    train_views = len(train_data['frames'])
                with open(test_json, 'r') as f:
                    test_data = json.load(f)
                    test_views = len(test_data['frames'])
                
                total_views = train_views + test_views
                # 检查是否存在 val,如果有也加进 total 但不一定加进 test
                val_json = os.path.join(data_path, "transforms_val.json")
                if os.path.exists(val_json):
                    with open(val_json, 'r') as f:
                        total_views += len(json.load(f)['frames'])

                split_rule = "transforms_train/test"
                source_evidence = f"parsed_from_{train_json}"
            except Exception as e:
                notes = f"Error parsing JSON: {e}"

        else:
            # 优先级 B/C: 图像目录 / COLMAP 结构
            train_dir_count = count_images(os.path.join(data_path, "train"))
            test_dir_count = count_images(os.path.join(data_path, "test"))
            
            if train_dir_count > 0 and test_dir_count > 0:
                train_views = train_dir_count
                test_views = test_dir_count
                total_views = train_views + test_views
                split_rule = "explicit_train_test_dirs"
                source_evidence = "parsed_from_image_folders"
            else:
                # COLMAP 格式 - 统计 total 然后推断
                total = get_colmap_total(data_path)
                if total > 0:
                    total_views = total
                    
                    # 检查单个 output 目录下是否记录了 metrics
                    metric_file = f"outputs/vanilla_3dgs_{s_key}/metrics_test_iter30000.json"
                    metric_file_bak = f"outputs/vanilla_3dgs_{s_key}_bak/metrics_test_iter30000.json"
                    if not os.path.exists(metric_file) and os.path.exists(metric_file_bak):
                        metric_file = metric_file_bak
                        
                    if eval_holdout_rule:
                        # 3DGS 标准: llffhold=8 means test views are indices % 8 == 0
                        # 0, 8, 16...
                        tst = len([i for i in range(total) if i % eval_holdout_rule == 0])
                        trn = total - tst
                        train_views = trn
                        test_views = tst
                        split_rule = eval_evidence
                        source_evidence = "total_images_and_standard_eval_holdout"
                    else:
                        split_rule = "unknown_from_files"
                        source_evidence = "total_images_only_no_split_rule_found"

    records.append({
        "SceneKey": s_key,
        "DisplayName": d_name,
        "Dataset": ds,
        "TrainViews": train_views,
        "TestViews": test_views,
        "TotalViews": total_views,
        "ResolutionSetting": res_set,
        "SceneType": s_type,
        "SplitRule": split_rule,
        "DataPath": data_path,
        "SourceEvidence": source_evidence,
        "Notes": notes
    })

df_res = pd.DataFrame(records)

# 4. 导出
os.makedirs("outputs/phase5a", exist_ok=True)
sub_cols = ["SceneKey", "DisplayName", "Dataset", "TrainViews", "TestViews", "TotalViews", "ResolutionSetting", "SceneType", "SplitRule"]
audit_cols = ["SceneKey", "DisplayName", "Dataset", "TrainViews", "TestViews", "TotalViews", "ResolutionSetting", "SceneType", "SplitRule", "DataPath", "SourceEvidence", "Notes"]

df_res[sub_cols].to_csv(output_submission, index=False)
df_res[audit_cols].to_csv(output_audit, index=False)

print(f"========================================================")
print(f"Submission 级表格已保存至: {output_submission}")
print(f"Audit 级审计表已保存至: {output_audit}")
print(f"========================================================\n")

# 5. Markdown 预览
print("=== Appendix B: Scene Inventory (Submission Ready v2) ===")
preview_cols = ["SceneKey", "Dataset", "TrainViews", "TestViews", "TotalViews", "ResolutionSetting", "SplitRule"]
print(df_res[preview_cols].to_markdown(index=False))

# 6. Sanity Checks
print("\n========================================================")
print("SANITY CHECKS")
print("========================================================")

print(f"1. Scene 总数是否正好 31: {len(df_res) == 31} ({len(df_res)})")
repro_scenes = pd.read_csv("outputs/phase5a/task_vapre_splatatlas_repro.csv")['scene'].unique().tolist()
print(f"2. SceneKey 是否和 repro CSV 完全一致: {set(df_res['SceneKey']) == set(repro_scenes)}")

dist = df_res['Dataset'].value_counts().to_dict()
print(f"3. Dataset 分布 (预期 12/9/8/2):")
for k, v in dist.items(): print(f"   - {k}: {v}")

nerf_syn = df_res[df_res['Dataset'] == 'NeRF-Synthetic']
syn_check = all(t == 100 for t in nerf_syn['TrainViews']) and all(t == 200 for t in nerf_syn['TestViews'])
print(f"4. NeRF-Synthetic (8 scenes) 是否全部为 100 train / 200 test: {syn_check}")

resolved_count = len(df_res[df_res['TrainViews'] != 'NEEDS_SPLIT_RULE'])
needs_count = len(df_res[df_res['TrainViews'] == 'NEEDS_SPLIT_RULE'])
print(f"5. 得到明确 TrainViews/TestViews 的 scene 数量: {resolved_count}")
print(f"6. 仍是 NEEDS_SPLIT_RULE 的 scene 数量: {needs_count}")

if needs_count > 0:
    print("7. NEEDS_SPLIT_RULE scene 的 TotalViews:")
    for _, r in df_res[df_res['TrainViews'] == 'NEEDS_SPLIT_RULE'].iterrows():
        print(f"   - {r['SceneKey']}: TotalViews = {r['TotalViews']}, Path = {r['DataPath']}")

print(f"\n8. 大小写风险探查 (已自动处理的):")
for s in ["lego", "drjohnson", "playroom"]:
    r = df_res[df_res['SceneKey'] == s].iloc[0]
    print(f"   - Key: {s} -> Found Path: {r['DataPath']}")

res_check = df_res['ResolutionSetting'].notnull().all()
print(f"9. ResolutionSetting 是否全部非空: {res_check}")