開始使用免費開始

計算 NMS

在你從物件辨識模型中擷取出預測的邊界框與分數之後,下一步是使用非極大值抑制(non-max suppression)技術,確保只保留最精準且彼此不重疊的預測邊界框。

你在上一個練習中建立的 boxesscores 已可在你的工作區使用,且已匯入 torchtorchvision

本練習屬於課程

使用 PyTorch 進行影像深度學習

檢視課程

練習說明

  • torchvision.ops 匯入 nms
  • 將 IoU 閥值設為 0.5
  • boxesconfidence_scoresiou_threshold 套用非極大值抑制,傳入對應的函式。
  • 使用輸出的索引來篩選預測框。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import nms
____

# Set the IoU threshold
iou_threshold = ____

# Apply non-max suppression
box_indices = ____

# Filter boxes
filtered_boxes = ____

print("Filtered Boxes:", filtered_boxes)
編輯並執行程式碼