LoginSignup
3
3

1秒画像生成

テキストから画像を生成するAI、Stable Diffusion は画像を生成するのにけっこう時間がかかってまあそれで使うにはちょっと気が重かったりするが、
こちらは速くて高品質
A100GPUで試すと1秒台で生成。
(漸進的敵対的拡散蒸留法というのを使っているらしい。)

person disassembling a computer

e612329b-5398-47fc-9ad0-b3b9e6d306b2 (1).png

テキストを入力するだけでデモを試せる。
が、デモはGPU割り当てに時間がかかるので、せっかくならコードで爆速を実感してほしい。

使い方

以下のコードをColabで実行できる。

pip install diffusers

インストール

import torch
from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file

base = "stabilityai/stable-diffusion-xl-base-1.0"
repo = "ByteDance/SDXL-Lightning"
ckpt = "sdxl_lightning_4step_unet.safetensors" # Use the correct ckpt for your step setting!

# Load model.
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")

# Ensure sampler uses "trailing" timesteps.
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")

Run

pipe("person disassembling a computer",negative_prompt="anime, illustration", num_inference_steps=4, guidance_scale=0).images[0].save("output.png")

RPG characters

396ca61f-0e3c-4ffe-b56e-9bcc75fd960e.png

a person drinking coffe

output (1).png

すぐ画像が見れるので楽しい。

🐣


フリーランスエンジニアです。
AIについて色々記事を書いていますのでよかったらプロフィールを見てみてください。

もし以下のようなご要望をお持ちでしたらお気軽にご相談ください。
AIサービスを開発したい、ビジネスにAIを組み込んで効率化したい、AIを使ったスマホアプリを開発したい、
ARを使ったアプリケーションを作りたい、スマホアプリを作りたいけどどこに相談したらいいかわからない…

いずれも中間コストを省いたリーズナブルな価格でお請けできます。

お仕事のご相談はこちらまで
rockyshikoku@gmail.com

機械学習やAR技術を使ったアプリケーションを作っています。
機械学習/AR関連の情報を発信しています。

X
Medium
GitHub

3
3
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
3
3