请问我用和这个代码运行,报错如下,是什么问题呢?ValueError: Cannot load <class 'diffusers.models.autoencoder_kl.AutoencoderKL'>

#5
by Stephen2022 - opened
from diffusers import DiffusionPipeline
pipeline = DiffusionPipeline.from_pretrained("digiplay/majicMIX_realistic_v6")

报错:
ValueError: Cannot load <class 'diffusers.models.autoencoder_kl.AutoencoderKL'> from /data2/huggingface/majicMIX_realistic_v6_1/vae
because the following keys are missing:
decoder.mid_block.attentions.0.query.weight, encoder.mid_block.attentions.0.key.weight, decoder.mid_block.attentions.0.key.bias,
encoder.mid_block.attentions.0.key.bias, encoder.mid_block.attentions.0.proj_attn.weight, encoder.mid_block.attentions.0.query.weight,
decoder.mid_block.attentions.0.value.weight, decoder.mid_block.attentions.0.proj_attn.bias,
decoder.mid_block.attentions.0.proj_attn.weight, encoder.mid_block.attentions.0.proj_attn.bias,
encoder.mid_block.attentions.0.value.bias, decoder.mid_block.attentions.0.value.bias, encoder.mid_block.attentions.0.value.weight,
decoder.mid_block.attentions.0.key.weight, decoder.mid_block.attentions.0.query.bias, encoder.mid_block.attentions.0.query.bias.
Please make sure to pass low_cpu_mem_usage=False and device_map=None if you want to randomly initialize those weights or else

您好,您是用Google Colab 的嗎?可以用以下的程式碼試試看

!pip install diffusers==0.11.1 #如果要用新版 0.20.0 也可以 但我覺得舊版比較不會有問題
!pip install transformers scipy ftfy accelerate

import torch
from diffusers import DiffusionPipeline

modelid="digiplay/majicMIX_realistic_v6"

from diffusers.models import AutoencoderKL

#看您需求選擇喜歡的VAE 把前面的井字號移掉就可以
#560001
vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-ema")
#840001
#vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse")

pipe = DiffusionPipeline.from_pretrained(modelid,vae=vae)
pipe = pipe.to("cuda")

#建議以下程式碼放到另一個儲存格,這樣cuda就不用重複執行
#依自己的需求改 pro 或neg 就可以,步數也可以依需求做更改

editstep=19

pro="1girl,4k,masterpiece"
neg="(worst quality: 1.3),(low quality: 1.3),normal quality"

image = pipe(prompt=pro,
negative_prompt=neg,
num_inference_steps=editstep,guidance_scale=7.5,height=512, width=512).images[0]
image

(最後一程式碼貼過去可以要重新對齊一下, 您再自行更改唷,
有成功的話也可以再跟我說唷 😄 )

補充, 如果是會跳出黑色框的安全警告, 是加入以下這段執行就可以:
(只需要執行一次,可以放在cuda之後執行)

pipe.safety_checker = None
pipe.requires_safety_checker = False

Sign up or log in to comment