File size: 2,470 Bytes
231562a | 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 | #!/usr/bin/env python3
"""批量渲染test_vs_baselines的各个case"""
import os
import subprocess
import json
CASES_DIR = "/home/v-meiszhang/amlt-project/acl-style-files/img/test_vs_baselines"
LAYOUTS_DIR = "/home/v-meiszhang/amlt-project/LayoutGPT/output_zones_1k/layouts"
RENDER_SCRIPT = "/home/v-meiszhang/amlt-project/LayoutGPT/visualize_zones_blender.py"
# Case文本到layout文件的映射(通过grep搜索)
case_queries = {
"case1": "multiuse living space",
"case2": "open-plan room in an irregular L-shaped",
"case3": "slightly industrial",
"case4": "entry storage area with a wardrobe",
"case5": "living and dining room that combines",
"case6": "Compact home kitchen",
"case7": "storage-focused right wall",
"case8": "three-seat sofa facing a media storage",
}
def find_layout_for_case(case_name, query):
"""在layouts目录中查找匹配的layout文件"""
import glob
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}: {layout_file} -> {output_file}")
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
print(f" 错误: {result.stderr[-500:]}")
return result.returncode == 0
def main():
# 激活conda环境已在外部完成
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文件
layout_file = find_layout_for_case(case_name, query)
if not layout_file:
print(f"跳过 {case_name}: 找不到匹配的layout文件 (query: {query})")
continue
# 渲染
render_case(case_name, layout_file, case_dir)
print(f"完成 {case_name}")
if __name__ == "__main__":
main()
|