BaşlayınÜcretsiz Başlayın

Image tensors

A coffee company has an object detection project where they need to annotate objects of interest, in this case, espresso shots. You have created a list with the bounding box coordinates for an espresso shot image. Now, you need to convert the image and the coordinates into tensors.

torch and torchvision have been imported. torchvision.transforms is imported as transforms. The image has been loaded as image using Image.open() from PIL library. The bounding box coordinates are stored in the variable bbox.

espresso

Bu egzersiz

Deep Learning for Images with PyTorch

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Convert the bbox into tensors using torch.tensor().
  • Reshape bbox_tensor by adding a batch dimension using unsqueeze(0).
  • Create a transform to resize image to (224) and transform to an unscaled image tensor.
  • Apply transform to image.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Convert bbox into tensors
bbox_tensor = ____

# Add a new batch dimension
bbox_tensor = bbox_tensor.____

# Resize image and transform tensor
transform = transforms.Compose([
  transforms.____,
  transforms.____
])

# Apply transform to image
image_tensor = ____
print(image_tensor)
Kodu Düzenle ve Çalıştır