为什么 AutoencoderKL 的编码器输出潜在变量形状与解码器输入潜在变量形状不同?

问题描述 投票:0回答:1
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部分。

autoencoder huggingface
1个回答
0
投票

我应该使用

vae.encode
vae.decode
而不是
vae.encoder
vae.decoder

© www.soinside.com 2019 - 2024. All rights reserved.