開始使用免費開始

繪製邊界框

已經準備好影像與邊界框的張量,現在你可以把方框畫在影像上,並以視覺方式檢查其準確度。

已匯入 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()
編輯並執行程式碼