StableDiffusionを自分のPCで実行しよう

| 2023/04/08 20:07:43 | 546 | cat:AI |


こんにちは! sonyakunです! 今日は

PythonでStableDiffusionを使う

性能

参考程度に...

  • CPU: Intel Core i7 11700
  • RAM: DDR4 8GBx2(16GB)
  • GPU: NVIDIA GeForce RTX 3060 VRAM 19.8GB これが使ったPCのスペックです

    コード

    まず、ターミナルでpip install diffusers==0.12.1 transformers==4.19.2 ftfy accelerateを実行する必要があります。

import torch
from diffusers import StableDiffusionPipeline

def gen(prompt):
    model_id = "CompVis/stable-diffusion-v1-4"
    device = "cuda"
    pipe = StableDiffusionPipeline.from_pretrained(model_id, revision="fp16", torch_dtype=torch.float16)
    pipe = pipe.to(device)
    generator = torch.Generator(device).manual_seed(42)
    with torch.autocast("cuda"):
        image = pipe(prompt, guidance_scale=7.5, generator=generator).images[0]
        image.save(prompt + ".png")

while True:
    text = input(">")
    gen(prompt=text)

実行すると、>がでてくるはずです。でてきたら、そこに生成したいテキストを入力して送信すると、その名前のpngが生成されます。

>Google
Fetching 16 files: 100%|████████████████████████| 16/16 [00:00

Googleと送信して生成された画像


sonya4327JE(sonyakun)

RANK: VIP

送られたステッカー🎁

🎉

応援ステッカーを送ろう🎉


{まだ未搭載です}

スポンサーリンク

AI
ぜろ
586 回視聴   2023/04/20 21:45:23
ニュース
sonya4327JE(sonyakun)
716 回視聴   2022/05/19 06:57:45
sonya4327JE(sonyakun)
955 回視聴   2022/08/25 11:37:52
MIYUKINNGU3838
780 回視聴   2022/05/20 20:15:44
nennneko5787 ◆NOrufLSRl.
503 回視聴   2023/11/03 17:32:46
その他
cba8b0b4-3314-4626-a604-78bd3569e3f0
605 回視聴   2022/06/20 06:47:17
surnloo(するんるー)【金欠】
700 回視聴   2022/06/01 13:35:52
その他
sonya4327JE(sonyakun)
1140 回視聴   2022/02/25 21:05:48
nennneko5787 ◆NOrufLSRl.
699 回視聴   2022/05/04 16:42:36
その他
ゆっくりいく
1122 回視聴   2022/04/07 12:45:04