Spaces:
Runtime error
Runtime error
from typing import Tuple, Optional | |
import numpy as np | |
from PIL import Image | |
from imgutils.data import rgb_encode | |
def _img_encode(image: Image.Image, size: Tuple[int, int] = (384, 384), | |
normalize: Optional[Tuple[float, float]] = (0.5, 0.5)): | |
image = image.resize(size, Image.BILINEAR) | |
data = rgb_encode(image, order_='CHW') | |
if normalize is not None: | |
mean_, std_ = normalize | |
mean = np.asarray([mean_]).reshape((-1, 1, 1)) | |
std = np.asarray([std_]).reshape((-1, 1, 1)) | |
data = (data - mean) / std | |
return data.astype(np.float32) | |