mirror of
https://github.com/vladmandic/automatic
synced 2026-08-26 06:30:44 +02:00
da1cf2f996
Signed-off-by: vladmandic <mandic00@live.com>
22 lines
557 B
Python
22 lines
557 B
Python
import numpy as np
|
|
import torch
|
|
import PIL
|
|
from modules.image import convert
|
|
|
|
|
|
JPEG_QUALITY = 95
|
|
|
|
|
|
def preprocess(image, processor, **kwargs):
|
|
if isinstance(image, PIL.Image.Image):
|
|
pass
|
|
elif isinstance(image, np.ndarray):
|
|
image = PIL.Image.fromarray(image)
|
|
elif isinstance(image, torch.Tensor):
|
|
image = convert.to_pil(image)
|
|
else:
|
|
raise TypeError(f"Image must be of type PIL.Image, np.ndarray, or torch.Tensor, got {type(image)} instead.")
|
|
|
|
image = processor.preprocess(image, **kwargs)
|
|
return image
|