开始使用免费开始使用

绘制边界框

在准备好图像和边界框张量后,您现在可以把框绘制到图像上,并直观检查其准确性。

已导入 torchtorchvisiontorchvision.transforms。图像已转换为名为 image_tensor 的张量。坐标已赋值给变量:x_miny_minx_maxy_max

本练习是课程的一部分

使用 PyTorch 进行图像深度学习

查看课程

练习说明

  • torchvision.utils 导入 draw_bounding_boxes
  • 将边界框 bbox 定义为由 x_miny_minx_maxy_max 组成的列表。
  • image_tensorbbox_tensor 传入 draw_bounding_boxes,将框绘制到图像上,并把输出赋给 img_bbox
  • img_bbox 张量转换为图像。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import draw_bounding_boxes
____

# Define the bounding box coordinates
bbox = ____
bbox_tensor = torch.tensor(bbox).unsqueeze(0)

# Implement draw_bounding_boxes
img_bbox = ____(____, ____, width=3, colors="red")

# Tranform tensors to image
transform = transforms.Compose([
    ____
])
plt.imshow(transform(img_bbox))
plt.show()
编辑并运行代码