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

| 2023/04/08 20:07:43 | 303 | 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
ぜろ
336 回視聴   2023/04/20 21:45:23
ニュース
sonya4327JE(sonyakun)
474 回視聴   2022/05/19 06:57:45
その他
sonya4327JE(sonyakun)
830 回視聴   2022/02/25 21:05:48
ぜろ
284 回視聴   2023/04/08 23:01:24
しゅとく(shuuucream)
359 回視聴   2022/08/09 18:51:05
ニュース
nennneko5787 ◆NOrufLSRl.
821 回視聴   2022/04/16 08:58:49
nennneko5787 ◆NOrufLSRl.
599 回視聴   2022/04/16 09:46:24
ニュース
cba8b0b4-3314-4626-a604-78bd3569e3f0
331 回視聴   2022/08/18 07:48:05
その他
あけっちゃん
1110 回視聴   2022/04/11 21:12:19
サーバー
solo-thudner
515 回視聴   2022/06/15 10:33:53