ZoneMaestro_code / eval /LayoutGPT /batch_render_bench.py
kkkkiiii's picture
Add files using upload-large-folder tool
8a68981 verified
Raw
History Blame Contribute Delete
2.28 kB
#!/usr/bin/env python3
"""批量渲染bench_vs_baselines的各个case"""
import os
import subprocess
import glob
CASES_DIR = "/home/v-meiszhang/amlt-project/acl-style-files/img/bench_vs_baselines"
LAYOUTS_DIR = "/home/v-meiszhang/amlt-project/LayoutGPT/output_instr_bench/layouts"
RENDER_SCRIPT = "/home/v-meiszhang/amlt-project/LayoutGPT/visualize_zones_blender.py"
# Case搜索关键词
case_queries = {
"case1": "six chairs",
"case2": "two facing sofas",
"case3": "large bed centered",
"case4": "L-shaped sectional",
"case5": "four main workstation",
"case6": "irregular polygonal bedroom",
"case7": "pentagonal living",
"case8": "polygonal shell",
}
def find_layout(query):
"""在layouts目录中查找匹配的layout文件"""
for layout_file in glob.glob(f"{LAYOUTS_DIR}/*.json"):
try:
with open(layout_file, 'r') as f:
content = f.read()
if query.lower() in content.lower():
return layout_file
except:
continue
return None
def render_case(case_name, layout_file, output_dir):
"""渲染单个case"""
output_file = os.path.join(output_dir, "layoutgpt_render.png")
cmd = [
"python", RENDER_SCRIPT,
"--layout_json", layout_file,
"--output", output_file,
"--render",
"--view", "diagonal"
]
print(f"渲染 {case_name}: {os.path.basename(layout_file)}")
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
print(f" 错误: {result.stderr[-300:] if result.stderr else 'unknown'}")
return result.returncode == 0
def main():
for case_name, query in case_queries.items():
case_dir = os.path.join(CASES_DIR, case_name)
if not os.path.exists(case_dir):
print(f"跳过 {case_name}: 目录不存在")
continue
layout_file = find_layout(query)
if not layout_file:
print(f"跳过 {case_name}: 找不到layout (query: {query})")
continue
if render_case(case_name, layout_file, case_dir):
print(f"完成 {case_name}")
else:
print(f"失败 {case_name}")
if __name__ == "__main__":
main()