from diffusers import AutoencoderKL
import torch
from PIL import Image
from torchvision import transforms
vae = AutoencoderKL.from_pretrained("../model")
image = Image.open("../2304_10752.png").resize((512, 512))
image = transforms.ToTensor()(image).unsqueeze(0)
print(image.shape)
out = vae.encoder(image*2-1)
print(out.shape)
out = vae.decoder(out)
print(out[0].shape)
out = out[0].permute(1, 2, 0).detach().numpy()
out = (out * 255).astype("uint8")
out = Image.fromarray(out)
out.show()
运行时错误:给定组=1,权重大小为[512,4,3,3],预期输入[1,8,64,64]有4个通道,但得到了8个通道
我在huggingface中单独下载并加载了稳定扩散模型的vae部分。
我应该使用
vae.encode
和 vae.decode
而不是 vae.encoder
或 vae.decoder