# 生成图片# Define how many steps and what % of steps to be run on each experts (80/20) here
n_steps =40
high_noise_frac =0.8
prompt ="A charming Korean woman wearing pink dress"# run both experts
image = base(
prompt=prompt,
num_inference_steps=n_steps,
denoising_end=high_noise_frac,
output_type="latent",).images[0]
image = refiner(
prompt=prompt,
num_inference_steps=n_steps,
denoising_start=high_noise_frac,
image=image,).images[0]
# 查看结果
image
三、图生图
# 加载模型from diffusers.utils import load_image
from diffusers import StableDiffusionXLImg2ImgPipeline
import torch
# load both base & refiner
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("/kaggle/input/stable-diffusion-xl/pytorch/base-1-0/1",
torch_dtype=torch.float16,
variant="fp16",
use_safetensors=True)
refiner.to("cuda")
image = load_image("/kaggle/input/examples/download1.png")
prompt="a pretty Korean woman wearing green dress"
num_inference_steps=50
strength=0.8
guidance_scale=7
image=refiner(
prompt=prompt,
num_inference_steps=num_inference_steps,
strength=strength,
guidance_scale=guidance_scale,
image=image
).images[0]