今天是第二十一天我們可以寫一個lstm去預測晶圓的良率並且結合yolo去辨識淘汰不良的晶圓,以下是程式碼
可以分成兩個主要步驟來完成:
這裡假設我有一組歷史數據,包括製造過程中的各項參數(如溫度、壓力、時間等)以及最終的良率。
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense
# 假設我們有一個包含製造過程數據的CSV文件
data = pd.read_csv('chip_yield_data.csv')
# 選擇特徵與標籤
features = data[['temperature', 'pressure', 'time', 'other_params']].values
labels = data['yield'].values
# 標準化數據
scaler = MinMaxScaler()
features_scaled = scaler.fit_transform(features)
# 重塑數據為LSTM需要的形狀 [samples, time_steps, features]
time_steps = 10
X = []
y = []
for i in range(time_steps, len(features_scaled)):
X.append(features_scaled[i-time_steps:i])
y.append(labels[i])
X, y = np.array(X), np.array(y)
# 分割數據為訓練集和測試集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# 建立LSTM模型
model = Sequential()
model.add(LSTM(units=50, return_sequences=True, input_shape=(X_train.shape[1], X_train.shape[2])))
model.add(LSTM(units=50))
model.add(Dense(units=1, activation='sigmoid')) # 用於預測良率,範圍0-1
# 編譯模型
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
# 訓練模型
model.fit(X_train, y_train, epochs=20, batch_size=32, validation_data=(X_test, y_test))
這裡假設我有一個預訓練的YOLO模型,能夠辨識晶圓上的缺陷。
import cv2
import numpy as np
# 假設我們有預訓練好的YOLOv8模型
# 從weights檔案中載入模型
net = cv2.dnn.readNet('yolov8.weights', 'yolov8.cfg')
layer_names = net.getLayerNames()
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
def detect_defects(image_path):
image = cv2.imread(image_path)
height, width = image.shape[:2]
# 準備YOLO輸入
blob = cv2.dnn.blobFromImage(image, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
net.setInput(blob)
outputs = net.forward(output_layers)
# 處理YOLO輸出
for output in outputs:
for detection in output:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
if confidence > 0.5: # 設定置信度閾值
center_x = int(detection[0] * width)
center_y = int(detection[1] * height)
w = int(detection[2] * width)
h = int(detection[3] * height)
x = int(center_x - w / 2)
y = int(center_y - h / 2)
# 框選缺陷部分
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.putText(image, "Defect", (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
return image
假設LSTM模型預測的良率低於某個閾值,則使用YOLO進行進一步檢查。
def evaluate_chip(image_path, process_data):
# 使用LSTM模型預測良率
process_data_scaled = scaler.transform([process_data])
process_data_reshaped = np.reshape(process_data_scaled, (1, time_steps, len(process_data)))
yield_prediction = model.predict(process_data_reshaped)[0][0]
if yield_prediction < 0.8: # 假設良率閾值為80%
# 使用YOLO辨識晶圓上的缺陷
defect_image = detect_defects(image_path)
cv2.imshow('Detected Defects', defect_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
return "Defects Detected"
return "Yield is acceptable"
這樣的系統可以大大提高晶片生產的效率和質量控制,透過LSTM預測來篩選可能有問題的晶圓,並通過YOLO進行詳細的檢查和淘汰。