How to crop an image at center in PyTorch?
www.tutorialspoint.com › how-to-crop-an-image-atJan 06, 2022 · This Python program crops the image at the center with a given size of height and width. In this program, we read the input image as a PIL image. import torch import torchvision. transforms as transforms from PIL import Image img = Image.open('waves.png') transform = transforms. CenterCrop ((150,500)) img = transform ( img) img. show () Output
torchvision.transforms — Torchvision 0.8.1 documentation
pytorch.org › vision › 0class torchvision.transforms.CenterCrop(size) [source] Crops the given image at the center. The image can be a PIL Image or a torch Tensor, in which case it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions Parameters: size ( sequence or int) – Desired output size of the crop.