common update
This commit is contained in:
102
examples/generate_sample_data.py
Normal file
102
examples/generate_sample_data.py
Normal file
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
生成示例数据的脚本
|
||||
- 创建一个简单的 GDS 文件
|
||||
- 使用 preprocess_gds.py 处理它,生成示例数据集
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import gdstk
|
||||
import numpy as np
|
||||
|
||||
# 添加项目根目录到 Python 路径
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
def create_simple_gds(output_file):
|
||||
"""创建一个简单的 GDS 文件,包含几个矩形"""
|
||||
# 创建一个新的库
|
||||
lib = gdstk.Library("simple_layout")
|
||||
|
||||
# 创建一个新的单元
|
||||
top_cell = lib.new_cell("TOP")
|
||||
|
||||
# 在不同层上添加几个矩形
|
||||
# 层 1: 金属层 1
|
||||
rect1 = gdstk.rectangle((0, 0), (10, 10), layer=1, datatype=0)
|
||||
top_cell.add(rect1)
|
||||
|
||||
# 层 2: 过孔层
|
||||
via = gdstk.rectangle((4, 4), (6, 6), layer=2, datatype=0)
|
||||
top_cell.add(via)
|
||||
|
||||
# 层 3: 金属层 2
|
||||
rect2 = gdstk.rectangle((2, 2), (8, 8), layer=3, datatype=0)
|
||||
top_cell.add(rect2)
|
||||
|
||||
# 保存 GDS 文件
|
||||
lib.write_gds(output_file)
|
||||
print(f"已创建 GDS 文件: {output_file}")
|
||||
|
||||
def preprocess_sample_data(gds_file, output_dir):
|
||||
"""使用 preprocess_gds.py 处理 GDS 文件,生成示例数据集"""
|
||||
import subprocess
|
||||
|
||||
# 确保输出目录存在
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
# 运行 preprocess_gds.py 脚本
|
||||
script_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "scripts", "preprocess_gds.py")
|
||||
|
||||
# 创建层映射配置
|
||||
layer_mapping = {
|
||||
"1/0": 0, # 金属层 1
|
||||
"2/0": 1, # 过孔层
|
||||
"3/0": 2 # 金属层 2
|
||||
}
|
||||
|
||||
# 构建命令
|
||||
cmd = [
|
||||
sys.executable, script_path,
|
||||
"--gds-file", gds_file,
|
||||
"--output-dir", output_dir,
|
||||
"--patch-size", "5.0",
|
||||
"--patch-stride", "2.5"
|
||||
]
|
||||
|
||||
# 添加层映射参数
|
||||
for layer_str, idx in layer_mapping.items():
|
||||
cmd.extend(["--layer-mapping", f"{layer_str}:{idx}"])
|
||||
|
||||
print(f"运行预处理命令: {' '.join(cmd)}")
|
||||
|
||||
# 执行命令
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
|
||||
if result.returncode == 0:
|
||||
print("预处理成功完成!")
|
||||
print("输出:")
|
||||
print(result.stdout)
|
||||
else:
|
||||
print("预处理失败!")
|
||||
print("错误:")
|
||||
print(result.stderr)
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
# 定义路径
|
||||
examples_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
gds_file = os.path.join(examples_dir, "simple_layout.gds")
|
||||
output_dir = os.path.join(examples_dir, "processed_data")
|
||||
|
||||
# 创建 GDS 文件
|
||||
create_simple_gds(gds_file)
|
||||
|
||||
# 预处理数据
|
||||
preprocess_sample_data(gds_file, output_dir)
|
||||
|
||||
print("\n示例数据生成完成!")
|
||||
print(f"GDS 文件: {gds_file}")
|
||||
print(f"处理后的数据: {output_dir}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
89
examples/run_sample_flow.py
Normal file
89
examples/run_sample_flow.py
Normal file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
一键运行的小样流程脚本
|
||||
- 生成示例数据
|
||||
- 训练模型
|
||||
- 评估模型
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
# 添加项目根目录到 Python 路径
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
def run_command(cmd, cwd=None):
|
||||
"""运行命令并打印输出"""
|
||||
print(f"\n运行命令: {' '.join(cmd)}")
|
||||
result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
|
||||
print("输出:")
|
||||
print(result.stdout)
|
||||
if result.stderr:
|
||||
print("错误:")
|
||||
print(result.stderr)
|
||||
if result.returncode != 0:
|
||||
print(f"命令执行失败,返回码: {result.returncode}")
|
||||
sys.exit(1)
|
||||
return result
|
||||
|
||||
def generate_sample_data():
|
||||
"""生成示例数据"""
|
||||
print("\n=== 步骤 1: 生成示例数据 ===")
|
||||
script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "generate_sample_data.py")
|
||||
run_command([sys.executable, script_path])
|
||||
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "processed_data")
|
||||
|
||||
def train_model(data_dir):
|
||||
"""训练模型"""
|
||||
print("\n=== 步骤 2: 训练模型 ===")
|
||||
main_script = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "main.py")
|
||||
config_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "configs", "hotspot_detection.yaml")
|
||||
|
||||
# 运行训练命令
|
||||
cmd = [
|
||||
sys.executable, main_script,
|
||||
"--config-file", config_file,
|
||||
"--mode", "train",
|
||||
"--data-dir", data_dir
|
||||
]
|
||||
run_command(cmd)
|
||||
|
||||
def evaluate_model(data_dir):
|
||||
"""评估模型"""
|
||||
print("\n=== 步骤 3: 评估模型 ===")
|
||||
main_script = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "main.py")
|
||||
config_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "configs", "hotspot_detection.yaml")
|
||||
|
||||
# 运行评估命令
|
||||
cmd = [
|
||||
sys.executable, main_script,
|
||||
"--config-file", config_file,
|
||||
"--mode", "eval",
|
||||
"--data-dir", data_dir
|
||||
]
|
||||
run_command(cmd)
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
start_time = time.time()
|
||||
|
||||
print("Geo-Layout Transformer 小样流程")
|
||||
print("==============================")
|
||||
|
||||
# 步骤 1: 生成示例数据
|
||||
data_dir = generate_sample_data()
|
||||
|
||||
# 步骤 2: 训练模型
|
||||
train_model(data_dir)
|
||||
|
||||
# 步骤 3: 评估模型
|
||||
evaluate_model(data_dir)
|
||||
|
||||
total_time = time.time() - start_time
|
||||
print(f"\n=== 流程完成 ===")
|
||||
print(f"总耗时: {total_time:.2f} 秒")
|
||||
print("示例流程已成功运行!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1
examples/simple_layout.gds
Normal file
1
examples/simple_layout.gds
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user