Spaces:
Sleeping
Sleeping
Download models/image/effort/preprocess.py from SMSD75/SynthScope: direct link, hf CLI and curl.
- Browser
- Download file 670 Bytes
-
https://huggingface.co/spaces/SMSD75/SynthScope/resolve/main/models/image/effort/preprocess.py
- Command line
-
hf download hf://spaces/SMSD75/SynthScope/models/image/effort/preprocess.py
-
curl -L -o preprocess.py https://huggingface.co/spaces/SMSD75/SynthScope/resolve/main/models/image/effort/preprocess.py
670 Bytes
| import cv2 | |
| import numpy as np | |
| from PIL import Image | |
| class Cv2SquareResize: | |
| """DeepfakeBench's test loader (``abstract_dataset.load_rgb``): the whole image squashed to ``size`` x ``size`` with | |
| cv2's bicubic interpolation (not PIL's, whose bicubic differs), then returned as a PIL image for ToTensor.""" | |
| def __init__(self, size: int = 224): | |
| self.size = size | |
| def __call__(self, img: Image.Image) -> Image.Image: | |
| arr = cv2.resize(np.asarray(img.convert("RGB")), (self.size, self.size), interpolation=cv2.INTER_CUBIC) | |
| return Image.fromarray(arr) | |
| def __repr__(self): | |
| return f"Cv2SquareResize({self.size}, INTER_CUBIC)" | |