Files
LayoutMatch/data_units.py
2025-03-25 01:42:26 +08:00

31 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import numpy as np
from PIL import Image
import torchvision.transforms as transforms
def layout_transforms():
"""定义数据增强和预处理"""
return transforms.Compose([
transforms.Resize((256, 256)), # 调整尺寸到固定大小
transforms.RandomRotation(30), # 随机旋转(增强方向不变性)
transforms.ColorJitter(brightness=0.2, contrast=0.2), # 彩色抖动(如果使用图像数据)
transforms.ToTensor(), # 转换为张量
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) # 标准化如ImageNet均值和方差
])
def layout_to_tensor(layout_path, target_size=(256, 256)):
"""将版图转换为标准化张量"""
# 实际应用中可能需要解析GDSII/LEF格式此处简化处理
img = Image.open(layout_path).convert('L') # 灰度化
img = img.resize(target_size, resample=Image.BILINEAR)
return np.array(img) / 255.0 # 归一化到[0,1]
def tile_layout(large_layout, block_size=64):
"""将大版图分割为小块(滑动窗口方式)"""
height, width = large_layout.shape
stride = block_size // 2 # 步长设置重叠区域
tiles = []
for y in range(0, height - block_size +1, stride):
for x in range(0, width - block_size +1, stride):
tile = large_layout[y:y+block_size, x:x+block_size]
tiles.append((x, y, tile))
return tiles