26 lines
594 B
Python
26 lines
594 B
Python
from PIL import Image, ImageDraw, ImageFilter
|
|
import torch
|
|
import numpy as np
|
|
|
|
|
|
def pil2tensor(image):
|
|
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)
|
|
|
|
|
|
def empty_pil_tensor(w=64, h=64):
|
|
image = Image.new("RGB", (w, h))
|
|
draw = ImageDraw.Draw(image)
|
|
draw.rectangle((0, 0, w-1, h-1), fill=(0, 0, 0))
|
|
return pil2tensor(image)
|
|
|
|
|
|
def empty_latent():
|
|
return torch.zeros([1, 4, 8, 8])
|
|
|
|
# wildcard trick is taken from pythongossss's
|
|
class AnyType(str):
|
|
def __ne__(self, __value: object) -> bool:
|
|
return False
|
|
|
|
any_typ = AnyType("*")
|