1/23/2023

PIL image to tensor

 refer to code

key is "transforms.PILToTensor"

..

import torch
from PIL import Image
import torchvision.transforms as transforms
pil_image = Image.open('input.jpg')
transform = transforms.Compose([
transforms.PILToTensor()
])
tensor_img = transform(pil_image)
print(tensor_img)

..


Thx. πŸ™‡πŸ»‍♂️

No comments:

Post a Comment