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

| 2023/04/08 20:07:43 | 287 | 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
ぜろ
322 回視聴   2023/04/20 21:45:23
その他
sonya4327JE(sonyakun)
642 回視聴   2022/03/30 16:06:42
sonya4327JE(sonyakun)
410 回視聴   2022/06/14 15:53:53
sonya4327JE(sonyakun)
688 回視聴   2022/08/25 11:37:52
その他
よー
1323 回視聴   2022/05/28 12:03:31
その他
NEPTARUNE
567 回視聴   2022/02/24 16:53:34
Mod
TASTER
2068 回視聴   2022/02/25 22:47:54
pikachu_predator
399 回視聴   2022/07/17 17:02:51
ニュース
あけっちゃん
185 回視聴   2024/01/23 22:34:49