Stable DiffusionをWSL上のUbuntu22.04で動かす

環境

Windows 11
WLS2
Ubuntu 22.04
Python 3.10.4

Hugging Faceのアカウント作成

Hugging Faceのアカウント作成し、Tokenを取得する。ユーザーの設定画面のAccess Tokenを開き、New tokenをクリックしてTokenを作成する。後で使用するためコピーしておく。※Email認証がまだの場合はボタンが非活性になっているので注意

作成時の名前は適当で良い。

インストール

pip install diffusers==0.2.4 transformers scipy ftfy

実行

下記の通り実行し、Tokenを入力する。

$ huggingface-cli login

        _|    _|  _|    _|    _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|_|_|_|    _|_|      _|_|_|  _|_|_|_|
        _|    _|  _|    _|  _|        _|          _|    _|_|    _|  _|            _|        _|    _|  _|        _|
        _|_|_|_|  _|    _|  _|  _|_|  _|  _|_|    _|    _|  _|  _|  _|  _|_|      _|_|_|    _|_|_|_|  _|        _|_|_|
        _|    _|  _|    _|  _|    _|  _|    _|    _|    _|    _|_|  _|    _|      _|        _|    _|  _|        _|
        _|    _|    _|_|      _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|        _|    _|    _|_|_|  _|_|_|_|

        To login, `huggingface_hub` now requires a token generated from https://huggingface.co/settings/tokens .
        
Token: 
Login successful
Your token has been saved to /home/ユーザーID/.huggingface/token

Hugging Faceにログインし、以下のページにアクセスして、Access repositoryをクリックする。
https://huggingface.co/CompVis/stable-diffusion-v1-4

cudaの設定が面倒なので、今回はcudaなしで実行する。

from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=True)

prompt = "a photograph of an astronaut riding a horse"

image = pipe(prompt)["sample"][0]

image.save("horse.png")

image

実行結果

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください