Stable Diffusion 1.4(Google Colab)

# Stable Diffusion 1.4


import torchfrom diffusers import StableDiffusionPipeline
model_id = "CompVis/stable-diffusion-v1-4"device = "cuda"
# プロンプトprompt = "Mt. Fuji in the style of Gauguin"
# パイプラインの作成pipe = StableDiffusionPipeline.from_pretrained(model_id, revision="fp16", torch_dtype=torch.float16)pipe = pipe.to(device)
# パイプラインの実行generator = torch.Generator(device).manual_seed(42) # seedを前回と同じ42にするwith torch.autocast("cuda"): image = pipe(prompt, guidance_scale=7.5, generator=generator).images[0]
# 生成した画像の保存image.save("mt_fuji_gauguin.png")

この記事が気に入ったらサポートをしてみませんか?