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

| 2023/04/08 20:07:43 | 592 | 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
ぜろ
632 回視聴   2023/04/20 21:45:23
その他
sonya4327JE(sonyakun)
1188 回視聴   2022/02/25 21:05:48
ニュース
sonya4327JE(sonyakun)
789 回視聴   2022/05/16 07:40:34
sonya4327JE(sonyakun)
1434 回視聴   2022/06/05 07:43:10
nennneko5787 ◆NOrufLSRl.
623 回視聴   2022/08/20 11:39:16
solo-thudner
524 回視聴   2024/04/03 08:41:47
sonya4327JE(sonyakun)
1434 回視聴   2022/06/05 07:43:10
ニュース
赤銅峰煉次
734 回視聴   2022/11/19 23:33:37
ゲーム
85637404-18bb-425e-93f2-7a8c105af5d6
687 回視聴   2022/06/05 10:36:15
プラグイン
chikokunn
2075 回視聴   2022/05/15 10:07:08
ニュース
こっしー
679 回視聴   2022/08/05 01:58:08
その他
NEPTARUNE
573 回視聴   2023/04/25 18:32:14