边界框预测
您已经训练了一个目标识别模型。现在,您希望用它为一张测试图像生成边界框和类别预测。
模型以 model 提供,且已处于评估模式。test_image 也已可用,并且已导入 torch 和 torch.nn(作为 nn)。
本练习是课程的一部分
使用 PyTorch 进行图像深度学习
练习说明
- 获取
test_image的模型输出,并将其赋给output。 - 从输出中提取预测的边界框,并将其赋给
boxes。 - 从输出中提取预测的分数,并将其赋给
scores。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Get model's prediction
with torch.no_grad():
output = ____
# Extract boxes from the output
boxes = ____
# Extract scores from the output
scores = ____
print(boxes, scores)