mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-02-25 09:13:59 +00:00
Update forge_util.py
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import torch
|
||||
import numpy as np
|
||||
|
||||
from ldm_patched.modules.conds import CONDRegular, CONDCrossAttn
|
||||
|
||||
|
||||
@@ -25,3 +27,19 @@ def cond_from_a1111_to_patched_ldm(cond):
|
||||
)
|
||||
|
||||
return [result, ]
|
||||
|
||||
|
||||
@torch.no_grad()
|
||||
@torch.inference_mode()
|
||||
def pytorch_to_numpy(x):
|
||||
return [np.clip(255. * y.cpu().numpy(), 0, 255).astype(np.uint8) for y in x]
|
||||
|
||||
|
||||
@torch.no_grad()
|
||||
@torch.inference_mode()
|
||||
def numpy_to_pytorch(x):
|
||||
y = x.astype(np.float32) / 255.0
|
||||
y = y[None]
|
||||
y = np.ascontiguousarray(y.copy())
|
||||
y = torch.from_numpy(y).float()
|
||||
return y
|
||||
|
||||
Reference in New Issue
Block a user