File size: 522 Bytes
f8e5b66 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import numpy as np
import torchvision
import PIL
def web_input(image):
image_transforms = torchvision.transforms.Compose([torchvision.transforms.ToTensor()])
input_img = PIL.Image.fromarray(image)
input_img = input_img.resize((100, 100), PIL.Image.LANCZOS)
wd_new, ht_new = input_img.size
wd_new = int(16 * np.ceil(wd_new / 16.0))
ht_new = int(16 * np.ceil(ht_new / 16.0))
input_img = input_img.resize((wd_new, ht_new), PIL.Image.LANCZOS)
return image_transforms(input_img).unsqueeze(0)
|