计算 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)