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) | |