計算 NMS
在你從物件辨識模型中擷取出預測的邊界框與分數之後,下一步是使用非極大值抑制(non-max suppression)技術,確保只保留最精準且彼此不重疊的預測邊界框。
你在上一個練習中建立的 boxes 與 scores 已可在你的工作區使用,且已匯入 torch 與 torchvision。
本練習屬於課程
使用 PyTorch 進行影像深度學習
練習說明
- 從
torchvision.ops匯入nms。 - 將 IoU 閥值設為
0.5。 - 對
boxes、confidence_scores與iou_threshold套用非極大值抑制,傳入對應的函式。 - 使用輸出的索引來篩選預測框。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import nms
____
# Set the IoU threshold
iou_threshold = ____
# Apply non-max suppression
box_indices = ____
# Filter boxes
filtered_boxes = ____
print("Filtered Boxes:", filtered_boxes)