Deep Learning for Images with PyTorch
Michal Oleszak
Machine Learning Engineer
Object recognition identifies objects in images:
Location of each object in an image (bounding box)
Class label of each object
Applications: surveillance, medical diagnosis, traffic management, sports analytics
Transforming with ToTensor()
import torchvision.transforms as transforms
transform = transforms.Compose([ transforms.Resize(224), transforms.ToTensor() ]) image_tensor = transform(image)
Tranforming with PILToTensor()
import torchvision.transforms as transforms
transform = transforms.Compose([
transforms.Resize(224),
transforms.PILToTensor()
])
image_tensor = transform(image)
from torchvision.utils import draw_bounding_boxes
bbox = torch.tensor([x_min, y_min, x_max, y_max]) bbox = bbox.unsqueeze(0)
bbox_image = draw_bounding_boxes( image_tensor, bbox, width=3, colors="red" )
transform = transforms.Compose([ transforms.ToPILImage() ]) pil_image = transform(bbox_image) import matplotlib.pyplot as plt plt.imshow(pil_image)
draw_bounding_boxes
Deep Learning for Images with PyTorch