0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PythonでAI生成してみた【Stable Diffusion × Diffusers入門】

Posted at

はじめに

AIによる画像生成技術が進化し、誰でもPythonを使ってアート作品を創れる時代になりました。
この記事では、DiffusersライブラリStable Diffusionを使って、

Pythonだけで生成してみます。


使用するツール

  • Python 3.8以上
  • Diffusers ライブラリ(Hugging Face製)
  • Stable Diffusion v1.5(学習済みテキスト→画像変換モデル)
  • torch(PyTorch)
  • PIL(画像表示・保存)

コード全体

以下のコードをコピペするだけで、アート生成ができます。

from diffusers import StableDiffusionPipeline
import torch

# モデルをCPUで読み込む(GPUがない環境用)
pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5"
).to("cpu")  # ← ここを "cuda" にするとGPU対応

# プロンプト指定(生成したいイメージ)
prompt = "a Japanese ukiyo-e style painting of a dragon flying in the clouds"

# 画像生成(時間がかかる可能性あり)
image = pipe(prompt).images[0]

# 表示と保存
image.show()
image.save("generated_art.png")

GPUを使わないとシミュレーション時間が長すぎます。

image.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?