Spaces:
Runtime error
Runtime error
Download preprocess.py from AppleHarem/anime_image_classification: direct link, hf CLI and curl.
- Browser
- Download file 592 Bytes
-
https://huggingface.co/spaces/AppleHarem/anime_image_classification/resolve/main/preprocess.py
- Command line
-
hf download hf://spaces/AppleHarem/anime_image_classification/preprocess.py
-
curl -L -o preprocess.py https://huggingface.co/spaces/AppleHarem/anime_image_classification/resolve/main/preprocess.py
592 Bytes
| 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) | |