mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-22 10:06:59 +08:00
Force uint8 and check if device supports non-blocking
This commit is contained in:
parent
ffc4b7c30e
commit
85ed1fb7b8
@ -24,12 +24,17 @@ class TAESDPreviewerImpl(LatentPreviewer):
|
|||||||
self.taesd = taesd
|
self.taesd = taesd
|
||||||
|
|
||||||
def decode_latent_to_preview(self, x0):
|
def decode_latent_to_preview(self, x0):
|
||||||
x_sample = self.taesd.decode(x0[:1])[0].detach()
|
self.latent_rgb_factors = self.latent_rgb_factors.to(dtype=x0.dtype, device=x0.device)
|
||||||
x_sample = 255. * torch.clamp((x_sample + 1.0) / 2.0, min=0.0, max=1.0)
|
latent_image = x0[0].permute(1, 2, 0) @ self.latent_rgb_factors
|
||||||
x_sample = np.moveaxis(x_sample.to(device="cpu", dtype=torch.uint8, non_blocking=comfy.model_management.device_supports_non_blocking(x_sample.device)).numpy(), 0, 2)
|
|
||||||
|
|
||||||
preview_image = Image.fromarray(x_sample)
|
latents_ubyte = (((latent_image + 1) / 2)
|
||||||
return preview_image
|
.clamp(0, 1) # change scale from -1..1 to 0..1
|
||||||
|
.mul(0xFF) # to 0..255
|
||||||
|
)
|
||||||
|
latents_ubyte = latents_ubyte.to(dtype=torch.uint8)
|
||||||
|
latents_ubyte = latents_ubyte.to(device="cpu", dtype=torch.uint8, non_blocking=comfy.model_management.device_supports_non_blocking(latent_image.device))
|
||||||
|
|
||||||
|
return Image.fromarray(latents_ubyte.numpy())
|
||||||
|
|
||||||
|
|
||||||
class Latent2RGBPreviewer(LatentPreviewer):
|
class Latent2RGBPreviewer(LatentPreviewer):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user