[[Stable Diffusion]]を試してみた。
## 前提
- [[Windows 10]]
- [[PowerShell]]
## 環境準備
[[conda]]が必要。公式からインストールする。
<div class="link-card-v2">
<div class="link-card-v2-site">
<img class="link-card-v2-site-icon" src="https://www.anaconda.com/wp-content/uploads/2025/05/cropped-favicon-32x32.png" />
<span class="link-card-v2-site-name">Anaconda</span>
</div>
<div class="link-card-v2-title">
Download Anaconda Distribution | Anaconda
</div>
<div class="link-card-v2-content">
Download Anaconda's open-source Distribution today. Discover the easiest way to perform Python/R data science an ...
</div>
<img class="link-card-v2-image" src="https://www.anaconda.com/wp-content/uploads/2025/06/icon-team-code.svg" />
<a href="https://www.anaconda.com/products/distribution"></a>
</div>
非推奨っぽいけどつけておく。
![[Pasted image 20220823185641.png]]
> [!caution]
> [[Scoop]]からインストールも可能だけど、[[Stable Diffusion]]での環境構築で以下のエラーが発生して解決できなかった。
> ```
> Collecting package metadata (repodata.json): failed
>
> CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/pytorch/win-64/repodata.json>
> Elapsed: -
>
> An HTTP error occurred when trying to retrieve this URL.
> HTTP errors are often intermittent, and a simple retry will get you on your way.
> 'https://conda.anaconda.org/pytorch/win-64'
> ```
## [[Stable Diffusion]]のインストール
https://github.com/CompVis/stable-diffusion#requirements
```console
git clone https://github.com/CompVis/stable-diffusion
cd stable-diffusion
conda env create -f environment.yaml
conda activate ldm
```
## [[ckpt]]ファイルの用意
重みを設定する[[ckpt]]ファイルを用意する。
### [[Hugging Face]]に移動
https://github.com/CompVis/stable-diffusion#stable-diffusion-v1
https://huggingface.co/CompVis にてライセンスを守れば使えるらしい。
> The weights are available via the CompVis organization at Hugging Face under a license which contains specific use-based restrictions to prevent misuse and harm as informed by the model card, but otherwise remains permissive.
[stable-diffusion-v-1-4-original](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original) をダウンロードしようとするも404になる。
### [[Hugging Face]]のアカウント作成
`Sign Up`から作成する。そうすると、404が403に格上げされる。
![[Pasted image 20220823192149.png]]
### 利用許諾を読んで承諾する
チェックしてリポジトリへのアクセスを明示する必要があるそう。
> [!warning]
> 規約はちゃんと読み、理解・承諾した上で使い始めること。
![[Pasted image 20220823192319.png]]
### [[ckpt]]ファイルのダウンロード
これでようやく取得できそう。そして[[Git LFS]]が使われているのだなあと。
![[Pasted image 20220823192500.png]]
クローンする意味はなさそうなので、サイズ右横のダウンロードアイコンをクリックしてダウンロードする。4GBあるので少し時間がかかる。
### [[ckpt]]ファイルの格納
https://github.com/CompVis/stable-diffusion#reference-sampling-script
```console
mkdir -p models/ldm/stable-diffusion-v1/
ln -s C:\Users\syoum\work\sd-v1-4.ckpt models/ldm/stable-diffusion-v1/model.ckpt
```
## 実行
```console
$ conda activate
$ python scripts/txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms
Traceback (most recent call last):
File "C:\Users\syoum\git\github.com\CompVis\stable-diffusion\scripts\txt2img.py", line 2, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
```
`cv2`がない...。[[opencv-python]]がインストールされていないのが原因ぽい。
- [[ANACONDAでNo module named 'cv2'エラー]]
[[opencv-python]]をインストールしても今度は`torch`でエラーになる.
## 環境作り直し
[[ANACONDA環境(base)を最新に]]して、[[ANACONDA環境のパッケージをすべて最新に]]もしたので、もう一度環境を作り直してみる。
```console
conda env remove -n ldm
conda env create -f environment.yaml
```
今度はログを残しておく。
```txt
Collecting package metadata (repodata.json): done
Solving environment: done
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Installing pip dependencies: \ Ran pip subprocess with arguments:
['C:\\Users\\syoum\\anaconda3\\envs\\ldm\\python.exe', '-m', 'pip', 'install', '-U', '-r', 'C:\\Users\\syoum\\git\\github.com\\CompVis\\stable-diffusion\\condaenv.vvvifg7g.requirements.txt']
Pip subprocess output:
Obtaining taming-transformers from git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers (from -r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 17))
Updating c:\users\syoum\git\github.com\compvis\stable-diffusion\src\taming-transformers clone (to revision master)
Obtaining clip from git+https://github.com/openai/CLIP.git@main#egg=clip (from -r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 18))
Updating c:\users\syoum\git\github.com\compvis\stable-diffusion\src\clip clone (to revision main)
Obtaining file:///C:/Users/syoum/git/github.com/CompVis/stable-diffusion (from -r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 19))
Requirement already satisfied: torch in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from clip->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 18)) (1.11.0)
Requirement already satisfied: torchvision in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from clip->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 18)) (0.12.0)
Requirement already satisfied: numpy in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from latent-diffusion==0.0.1->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 19)) (1.19.2)
Collecting albumentations==0.4.3
Using cached albumentations-0.4.3-py3-none-any.whl
Collecting einops==0.3.0
Using cached einops-0.3.0-py2.py3-none-any.whl (25 kB)
Collecting imageio==2.9.0
Using cached imageio-2.9.0-py3-none-any.whl (3.3 MB)
Requirement already satisfied: pillow in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from imageio==2.9.0->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 6)) (9.2.0)
Collecting imageio-ffmpeg==0.4.2
Using cached imageio_ffmpeg-0.4.2-py3-none-win_amd64.whl (22.6 MB)
Collecting kornia==0.6
Using cached kornia-0.6.0-py2.py3-none-any.whl (367 kB)
Collecting omegaconf==2.1.1
Using cached omegaconf-2.1.1-py3-none-any.whl (74 kB)
Collecting opencv-python==4.1.2.30
Using cached opencv_python-4.1.2.30-cp38-cp38-win_amd64.whl (33.0 MB)
Collecting pudb==2019.2
Using cached pudb-2019.2-py3-none-any.whl
Collecting pytorch-lightning==1.4.2
Using cached pytorch_lightning-1.4.2-py3-none-any.whl (916 kB)
Requirement already satisfied: typing-extensions in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from pytorch-lightning==1.4.2->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 8)) (4.3.0)
Collecting torch-fidelity==0.3.0
Using cached torch_fidelity-0.3.0-py3-none-any.whl (37 kB)
Collecting torchmetrics==0.6.0
Using cached torchmetrics-0.6.0-py3-none-any.whl (329 kB)
Collecting transformers==4.19.2
Using cached transformers-4.19.2-py3-none-any.whl (4.2 MB)
Requirement already satisfied: requests in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from transformers==4.19.2->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 14)) (2.28.1)
Collecting antlr4-python3-runtime==4.8
Using cached antlr4_python3_runtime-4.8-py3-none-any.whl
Collecting pyDeprecate==0.3.1
Using cached pyDeprecate-0.3.1-py3-none-any.whl (10 kB)
Collecting streamlit>=0.73.1
Using cached streamlit-1.12.0-py2.py3-none-any.whl (9.1 MB)
Collecting test-tube>=0.7.5
Using cached test_tube-0.7.5-py3-none-any.whl
Collecting altair>=3.2.0
Using cached altair-4.2.0-py3-none-any.whl (812 kB)
Collecting blinker>=1.0.0
Using cached blinker-1.5-py2.py3-none-any.whl (12 kB)
Collecting cachetools>=4.0
Using cached cachetools-5.2.0-py3-none-any.whl (9.3 kB)
Collecting click>=7.0
Using cached click-8.1.3-py3-none-any.whl (96 kB)
Collecting fsspec[http]!=2021.06.0,>=2021.05.0
Using cached fsspec-2022.7.1-py3-none-any.whl (141 kB)
Collecting future>=0.17.1
Using cached future-0.18.2-py3-none-any.whl
Collecting gitpython!=3.1.19
Using cached GitPython-3.1.27-py3-none-any.whl (181 kB)
Collecting gitdb<5,>=4.0.1
Using cached gitdb-4.0.9-py3-none-any.whl (63 kB)
Collecting huggingface-hub<1.0,>=0.1.0
Using cached huggingface_hub-0.8.1-py3-none-any.whl (101 kB)
Collecting imgaug<0.2.7,>=0.2.5
Using cached imgaug-0.2.6-py3-none-any.whl
Requirement already satisfied: six in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from imgaug<0.2.7,>=0.2.5->albumentations==0.4.3->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 1)) (1.16.0)
Collecting importlib-metadata>=1.4
Using cached importlib_metadata-4.12.0-py3-none-any.whl (21 kB)
Collecting jsonschema>=3.0
Using cached jsonschema-4.14.0-py3-none-any.whl (82 kB)
Collecting attrs>=17.4.0
Using cached attrs-22.1.0-py2.py3-none-any.whl (58 kB)
Collecting importlib-resources>=1.4.0
Using cached importlib_resources-5.9.0-py3-none-any.whl (33 kB)
Collecting opencv-python-headless>=4.1.1
Using cached opencv_python_headless-4.6.0.66-cp36-abi3-win_amd64.whl (35.5 MB)
Collecting packaging
Using cached packaging-21.3-py3-none-any.whl (40 kB)
Collecting pandas>=0.21.0
Using cached pandas-1.4.3-cp38-cp38-win_amd64.whl (10.6 MB)
Collecting pkgutil-resolve-name>=1.3.10
Using cached pkgutil_resolve_name-1.3.10-py3-none-any.whl (4.7 kB)
Collecting protobuf<4,>=3.12
Using cached protobuf-3.20.1-cp38-cp38-win_amd64.whl (904 kB)
Collecting pyarrow>=4.0
Using cached pyarrow-9.0.0-cp38-cp38-win_amd64.whl (19.6 MB)
Collecting pydeck>=0.1.dev5
Using cached pydeck-0.7.1-py2.py3-none-any.whl (4.3 MB)
Collecting ipykernel>=5.1.2
Using cached ipykernel-6.15.1-py3-none-any.whl (132 kB)
Collecting debugpy>=1.0
Using cached debugpy-1.6.3-cp38-cp38-win_amd64.whl (4.6 MB)
Collecting ipython>=7.23.1
Using cached ipython-8.4.0-py3-none-any.whl (750 kB)
Requirement already satisfied: setuptools>=18.5 in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit>=0.73.1->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 11)) (63.4.1)
Collecting ipywidgets>=7.0.0
Using cached ipywidgets-8.0.1-py3-none-any.whl (133 kB)
Collecting jedi>=0.16
Using cached jedi-0.18.1-py2.py3-none-any.whl (1.6 MB)
Collecting jinja2
Using cached Jinja2-3.1.2-py3-none-any.whl (133 kB)
Collecting jupyter-client>=6.1.12
Using cached jupyter_client-7.3.4-py3-none-any.whl (132 kB)
Collecting jupyter-core>=4.9.2
Using cached jupyter_core-4.11.1-py3-none-any.whl (88 kB)
Collecting jupyterlab-widgets~=3.0
Using cached jupyterlab_widgets-3.0.2-py3-none-any.whl (383 kB)
Collecting MarkupSafe>=2.0
Using cached MarkupSafe-2.1.1-cp38-cp38-win_amd64.whl (17 kB)
Collecting matplotlib-inline>=0.1
Using cached matplotlib_inline-0.1.6-py3-none-any.whl (9.4 kB)
Collecting nest-asyncio
Using cached nest_asyncio-1.5.5-py3-none-any.whl (5.2 kB)
Collecting parso<0.9.0,>=0.8.0
Using cached parso-0.8.3-py2.py3-none-any.whl (100 kB)
Collecting prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0
Using cached prompt_toolkit-3.0.30-py3-none-any.whl (381 kB)
Collecting pygments>=1.0
Using cached Pygments-2.13.0-py3-none-any.whl (1.1 MB)
Collecting pympler>=0.9
Using cached Pympler-1.0.1-py3-none-any.whl (164 kB)
Collecting pyparsing!=3.0.5,>=2.0.2
Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
Collecting pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0
Using cached pyrsistent-0.18.1-cp38-cp38-win_amd64.whl (61 kB)
Collecting python-dateutil
Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting pytz>=2020.1
Using cached pytz-2022.2.1-py2.py3-none-any.whl (500 kB)
Collecting pywin32>=1.0
Using cached pywin32-304-cp38-cp38-win_amd64.whl (12.3 MB)
Collecting PyYAML
Using cached PyYAML-6.0-cp38-cp38-win_amd64.whl (155 kB)
Collecting pyzmq>=17
Using cached pyzmq-23.2.1-cp38-cp38-win_amd64.whl (1.1 MB)
Collecting regex
Using cached regex-2022.8.17-cp38-cp38-win_amd64.whl (263 kB)
Requirement already satisfied: charset-normalizer<3,>=2 in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from requests->transformers==4.19.2->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 14)) (2.0.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from requests->transformers==4.19.2->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 14)) (1.26.11)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from requests->transformers==4.19.2->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 14)) (2022.6.15)
Requirement already satisfied: idna<4,>=2.5 in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from requests->transformers==4.19.2->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 14)) (3.3)
Collecting rich>=10.11.0
Using cached rich-12.5.1-py3-none-any.whl (235 kB)
Collecting commonmark<0.10.0,>=0.9.0
Using cached commonmark-0.9.1-py2.py3-none-any.whl (51 kB)
Collecting scikit-image>=0.11.0
Using cached scikit_image-0.19.3-cp38-cp38-win_amd64.whl (12.2 MB)
Collecting networkx>=2.2
Using cached networkx-2.8.6-py3-none-any.whl (2.0 MB)
Collecting PyWavelets>=1.1.1
Using cached PyWavelets-1.3.0-cp38-cp38-win_amd64.whl (4.2 MB)
Collecting scipy
Using cached scipy-1.9.0-cp38-cp38-win_amd64.whl (38.6 MB)
Collecting smmap<6,>=3.0.1
Using cached smmap-5.0.0-py3-none-any.whl (24 kB)
Collecting tensorboard>=2.2.0
Using cached tensorboard-2.10.0-py3-none-any.whl (5.9 MB)
Requirement already satisfied: wheel>=0.26 in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from tensorboard>=2.2.0->pytorch-lightning==1.4.2->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 8)) (0.37.1)
Collecting absl-py>=0.4
Using cached absl_py-1.2.0-py3-none-any.whl (123 kB)
Collecting google-auth<3,>=1.6.3
Using cached google_auth-2.11.0-py2.py3-none-any.whl (167 kB)
Collecting google-auth-oauthlib<0.5,>=0.4.1
Using cached google_auth_oauthlib-0.4.6-py2.py3-none-any.whl (18 kB)
Collecting grpcio>=1.24.3
Using cached grpcio-1.47.0-cp38-cp38-win_amd64.whl (3.6 MB)
Collecting markdown>=2.6.8
Using cached Markdown-3.4.1-py3-none-any.whl (93 kB)
Collecting protobuf<4,>=3.12
Using cached protobuf-3.19.4-cp38-cp38-win_amd64.whl (895 kB)
Collecting pyasn1-modules>=0.2.1
Using cached pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
Collecting pyasn1<0.5.0,>=0.4.6
Using cached pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
Collecting requests-oauthlib>=0.7.0
Using cached requests_oauthlib-1.3.1-py2.py3-none-any.whl (23 kB)
Collecting oauthlib>=3.0.0
Using cached oauthlib-3.2.0-py3-none-any.whl (151 kB)
Collecting rsa<5,>=3.1.4
Using cached rsa-4.9-py3-none-any.whl (34 kB)
Collecting tensorboard-data-server<0.7.0,>=0.6.0
Using cached tensorboard_data_server-0.6.1-py3-none-any.whl (2.4 kB)
Collecting tensorboard-plugin-wit>=1.6.0
Using cached tensorboard_plugin_wit-1.8.1-py3-none-any.whl (781 kB)
Collecting tifffile>=2019.7.26
Using cached tifffile-2022.8.12-py3-none-any.whl (208 kB)
Collecting tokenizers!=0.11.3,<0.13,>=0.11.1
Using cached tokenizers-0.12.1-cp38-cp38-win_amd64.whl (3.3 MB)
Collecting tornado>=5.0
Using cached tornado-6.2-cp37-abi3-win_amd64.whl (425 kB)
Collecting tqdm
Using cached tqdm-4.64.0-py2.py3-none-any.whl (78 kB)
Collecting traitlets>=4.3.2
Using cached traitlets-5.3.0-py3-none-any.whl (106 kB)
Collecting tzlocal>=1.1
Using cached tzlocal-4.2-py3-none-any.whl (19 kB)
Collecting urwid>=1.1.1
Using cached urwid-2.1.2-cp38-cp38-win_amd64.whl
Collecting validators>=0.2
Using cached validators-0.20.0-py3-none-any.whl
Collecting decorator
Using cached decorator-5.1.1-py3-none-any.whl (9.1 kB)
Collecting werkzeug>=1.0.1
Using cached Werkzeug-2.2.2-py3-none-any.whl (232 kB)
Collecting widgetsnbextension~=4.0
Using cached widgetsnbextension-4.0.2-py3-none-any.whl (2.0 MB)
Collecting zipp>=0.5
Using cached zipp-3.8.1-py3-none-any.whl (5.6 kB)
Collecting diffusers
Using cached diffusers-0.2.4-py3-none-any.whl (112 kB)
Collecting invisible-watermark
Using cached invisible_watermark-0.1.5-py3-none-any.whl (1.6 MB)
Collecting aiohttp
Using cached aiohttp-3.8.1-cp38-cp38-win_amd64.whl (555 kB)
Collecting aiosignal>=1.1.2
Using cached aiosignal-1.2.0-py3-none-any.whl (8.2 kB)
Collecting async-timeout<5.0,>=4.0.0a3
Using cached async_timeout-4.0.2-py3-none-any.whl (5.8 kB)
Collecting frozenlist>=1.1.1
Using cached frozenlist-1.3.1-cp38-cp38-win_amd64.whl (34 kB)
Collecting multidict<7.0,>=4.5
Using cached multidict-6.0.2-cp38-cp38-win_amd64.whl (28 kB)
Collecting yarl<2.0,>=1.0
Using cached yarl-1.8.1-cp38-cp38-win_amd64.whl (56 kB)
Collecting backcall
Using cached backcall-0.2.0-py2.py3-none-any.whl (11 kB)
Collecting backports.zoneinfo
Using cached backports.zoneinfo-0.2.1-cp38-cp38-win_amd64.whl (38 kB)
Collecting colorama
Using cached colorama-0.4.5-py2.py3-none-any.whl (16 kB)
Collecting entrypoints
Using cached entrypoints-0.4-py3-none-any.whl (5.3 kB)
Collecting filelock
Using cached filelock-3.8.0-py3-none-any.whl (10 kB)
Collecting ftfy
Using cached ftfy-6.1.1-py3-none-any.whl (53 kB)
Collecting wcwidth
Using cached wcwidth-0.2.5-py2.py3-none-any.whl (30 kB)
Collecting onnx
Using cached onnx-1.12.0-cp38-cp38-win_amd64.whl (11.5 MB)
Collecting onnxruntime
Using cached onnxruntime-1.12.1-cp38-cp38-win_amd64.whl (5.8 MB)
Collecting numpy
Using cached numpy-1.23.2-cp38-cp38-win_amd64.whl (14.7 MB)
Collecting coloredlogs
Using cached coloredlogs-15.0.1-py2.py3-none-any.whl (46 kB)
Collecting humanfriendly>=9.1
Using cached humanfriendly-10.0-py2.py3-none-any.whl (86 kB)
Collecting flatbuffers
Using cached flatbuffers-2.0-py2.py3-none-any.whl (26 kB)
Collecting pickleshare
Using cached pickleshare-0.7.5-py2.py3-none-any.whl (6.9 kB)
Collecting psutil
Using cached psutil-5.9.1-cp38-cp38-win_amd64.whl (246 kB)
Collecting pyreadline3
Using cached pyreadline3-3.4.1-py3-none-any.whl (95 kB)
Collecting pytz-deprecation-shim
Using cached pytz_deprecation_shim-0.1.0.post0-py2.py3-none-any.whl (15 kB)
Collecting semver
Using cached semver-2.13.0-py2.py3-none-any.whl (12 kB)
Collecting stack-data
Using cached stack_data-0.4.0-py3-none-any.whl (23 kB)
Collecting asttokens
Using cached asttokens-2.0.8-py2.py3-none-any.whl (23 kB)
Collecting executing
Using cached executing-0.10.0-py2.py3-none-any.whl (17 kB)
Collecting pure-eval
Using cached pure_eval-0.2.2-py3-none-any.whl (11 kB)
Collecting sympy
Using cached sympy-1.10.1-py3-none-any.whl (6.4 MB)
Collecting mpmath>=0.19
Using cached mpmath-1.2.1-py3-none-any.whl (532 kB)
Collecting toml
Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting toolz
Using cached toolz-0.12.0-py3-none-any.whl (55 kB)
Collecting tzdata
Using cached tzdata-2022.2-py2.py3-none-any.whl (336 kB)
Collecting watchdog
Using cached watchdog-2.1.9-py3-none-win_amd64.whl (78 kB)
Installing collected packages: wcwidth, traitlets, pywin32, pure-eval, parso, executing, asttokens, tornado, stack-data, pyzmq, python-dateutil, pyparsing, pygments, pyasn1, prompt-toolkit, pickleshare, nest-asyncio, matplotlib-inline, jupyter-core, jedi, entrypoints, decorator, colorama, backcall, zipp, rsa, pyreadline3, pyasn1-modules, psutil, packaging, oauthlib, numpy, multidict, jupyter-client, ipython, frozenlist, debugpy, cachetools, yarl, widgetsnbextension, tzdata, tifffile, smmap, scipy, requests-oauthlib, PyWavelets, pytz, pyrsistent, pkgutil-resolve-name, networkx, mpmath, MarkupSafe, jupyterlab-widgets, ipykernel, importlib-resources, importlib-metadata, imageio, humanfriendly, google-auth, backports.zoneinfo, attrs, async-timeout, aiosignal, werkzeug, tqdm, toolz, tensorboard-plugin-wit, tensorboard-data-server, sympy, scikit-image, PyYAML, pytz-deprecation-shim, protobuf, pandas, markdown, jsonschema, jinja2, ipywidgets, grpcio, google-auth-oauthlib, gitdb, fsspec, flatbuffers, filelock, commonmark, coloredlogs, aiohttp, absl-py, watchdog, validators, urwid, tzlocal, torchmetrics, toml, tokenizers, tensorboard, semver, rich, regex, pympler, pyDeprecate, pydeck, pyarrow, opencv-python-headless, opencv-python, onnxruntime, onnx, imgaug, huggingface-hub, gitpython, future, ftfy, click, blinker, antlr4-python3-runtime, altair, transformers, torch-fidelity, test-tube, taming-transformers, streamlit, pytorch-lightning, pudb, omegaconf, latent-diffusion, kornia, invisible-watermark, imageio-ffmpeg, einops, diffusers, clip, albumentations
Attempting uninstall: numpy
Found existing installation: numpy 1.19.2
Uninstalling numpy-1.19.2:
Successfully uninstalled numpy-1.19.2
Running setup.py develop for taming-transformers
Running setup.py develop for latent-diffusion
Running setup.py develop for clip
Successfully installed MarkupSafe-2.1.1 PyWavelets-1.3.0 PyYAML-6.0 absl-py-1.2.0 aiohttp-3.8.1 aiosignal-1.2.0 albumentations-0.4.3 altair-4.2.0 antlr4-python3-runtime-4.8 asttokens-2.0.8 async-timeout-4.0.2 attrs-22.1.0 backcall-0.2.0 backports.zoneinfo-0.2.1 blinker-1.5 cachetools-5.2.0 click-8.1.3 clip colorama-0.4.5 coloredlogs-15.0.1 commonmark-0.9.1 debugpy-1.6.3 decorator-5.1.1 diffusers-0.2.4 einops-0.3.0 entrypoints-0.4 executing-0.10.0 filelock-3.8.0 flatbuffers-2.0 frozenlist-1.3.1 fsspec-2022.7.1 ftfy-6.1.1 future-0.18.2 gitdb-4.0.9 gitpython-3.1.27 google-auth-2.11.0 google-auth-oauthlib-0.4.6 grpcio-1.47.0 huggingface-hub-0.8.1 humanfriendly-10.0 imageio-2.9.0 imageio-ffmpeg-0.4.2 imgaug-0.2.6 importlib-metadata-4.12.0 importlib-resources-5.9.0 invisible-watermark-0.1.5 ipykernel-6.15.1 ipython-8.4.0 ipywidgets-8.0.1 jedi-0.18.1 jinja2-3.1.2 jsonschema-4.14.0 jupyter-client-7.3.4 jupyter-core-4.11.1 jupyterlab-widgets-3.0.2 kornia-0.6.0 latent-diffusion markdown-3.4.1 matplotlib-inline-0.1.6 mpmath-1.2.1 multidict-6.0.2 nest-asyncio-1.5.5 networkx-2.8.6 numpy-1.23.2 oauthlib-3.2.0 omegaconf-2.1.1 onnx-1.12.0 onnxruntime-1.12.1 opencv-python-4.1.2.30 opencv-python-headless-4.6.0.66 packaging-21.3 pandas-1.4.3 parso-0.8.3 pickleshare-0.7.5 pkgutil-resolve-name-1.3.10 prompt-toolkit-3.0.30 protobuf-3.19.4 psutil-5.9.1 pudb-2019.2 pure-eval-0.2.2 pyDeprecate-0.3.1 pyarrow-9.0.0 pyasn1-0.4.8 pyasn1-modules-0.2.8 pydeck-0.7.1 pygments-2.13.0 pympler-1.0.1 pyparsing-3.0.9 pyreadline3-3.4.1 pyrsistent-0.18.1 python-dateutil-2.8.2 pytorch-lightning-1.4.2 pytz-2022.2.1 pytz-deprecation-shim-0.1.0.post0 pywin32-304 pyzmq-23.2.1 regex-2022.8.17 requests-oauthlib-1.3.1 rich-12.5.1 rsa-4.9 scikit-image-0.19.3 scipy-1.9.0 semver-2.13.0 smmap-5.0.0 stack-data-0.4.0 streamlit-1.12.0 sympy-1.10.1 taming-transformers tensorboard-2.10.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 test-tube-0.7.5 tifffile-2022.8.12 tokenizers-0.12.1 toml-0.10.2 toolz-0.12.0 torch-fidelity-0.3.0 torchmetrics-0.6.0 tornado-6.2 tqdm-4.64.0 traitlets-5.3.0 transformers-4.19.2 tzdata-2022.2 tzlocal-4.2 urwid-2.1.2 validators-0.20.0 watchdog-2.1.9 wcwidth-0.2.5 werkzeug-2.2.2 widgetsnbextension-4.0.2 yarl-1.8.1 zipp-3.8.1
```
実行してみるもやっぱダメ。
```
Traceback (most recent call last):
File "C:\Users\syoum\git\github.com\CompVis\stable-diffusion\scripts\txt2img.py", line 3, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
```
いるんだがなあ。。
```txt
Requirement already satisfied: torch in c:\users\syoum\anaconda3\envs\ldm\lib\site-packages (from clip->-r C:\Users\syoum\git\github.com\CompVis\stable-diffusion\condaenv.vvvifg7g.requirements.txt (line 18)) (1.11.0)
```
もしかしてactivateが効いてない??
```console
$ conda list | grep torch
$ conda list -n ldm | grep torch
pytorch 1.11.0 py3.8_cuda11.3_cudnn8_0 pytorch
pytorch-lightning 1.4.2 pypi_0 pypi
pytorch-mutex 1.0 cuda pytorch
torch-fidelity 0.3.0 pypi_0 pypi
torchmetrics 0.6.0 pypi_0 pypi
torchvision 0.12.0 py38_cu113 pytorch
```
## 絶対パスで実行
直接指定したら動いた。
```console
C:\Users\syoum\anaconda3\envs\ldm\python scripts/txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms
```
ただ、途中でエラーに。。
```
- This IS expected if you are initializing CLIPTextModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing CLIPTextModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Traceback (most recent call last):
File "scripts/txt2img.py", line 344, in <module>
main()
File "scripts/txt2img.py", line 240, in main
model = load_model_from_config(config, f"{opt.ckpt}")
File "scripts/txt2img.py", line 63, in load_model_from_config
model.cuda()
File "C:\Users\syoum\anaconda3\envs\ldm\lib\site-packages\pytorch_lightning\core\mixins\device_dtype_mixin.py", line 127, in cuda
return super().cuda(device=device)
File "C:\Users\syoum\anaconda3\envs\ldm\lib\site-packages\torch\nn\modules\module.py", line 688, in cuda
return self._apply(lambda t: t.cuda(device))
File "C:\Users\syoum\anaconda3\envs\ldm\lib\site-packages\torch\nn\modules\module.py", line 578, in _apply
module._apply(fn)
File "C:\Users\syoum\anaconda3\envs\ldm\lib\site-packages\torch\nn\modules\module.py", line 578, in _apply
module._apply(fn)
File "C:\Users\syoum\anaconda3\envs\ldm\lib\site-packages\torch\nn\modules\module.py", line 578, in _apply
module._apply(fn)
[Previous line repeated 4 more times]
File "C:\Users\syoum\anaconda3\envs\ldm\lib\site-packages\torch\nn\modules\module.py", line 601, in _apply
param_applied = fn(param)
File "C:\Users\syoum\anaconda3\envs\ldm\lib\site-packages\torch\nn\modules\module.py", line 688, in <lambda>
return self._apply(lambda t: t.cuda(device))
RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 4.00 GiB total capacity; 3.42 GiB already allocated; 0 bytes free; 3.48 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
```
スペックが足りてなさそう。
## Light版を試す
[[📝Stable Diffusionを実行するとCUDA out of memoryエラー#解決方法]] のフォークされた[[Stable Diffusion]]を使う。
```console
git clone
[email protected]:basujindal/stable-diffusion.git
conda env remove -n ldm
conda env create -f environment.yaml
mkdir -p models/ldm/stable-diffusion-v1/
ln -s C:\Users\syoum\work\sd-v1-4.ckpt models/ldm/stable-diffusion-v1/model.ckpt
```
コマンドを実行。先ほどとは異なり、`optimizedSD`配下のスクリプトを使うので注意。
```console
C:\Users\syoum\anaconda3\envs\ldm\python optimizedSD/optimized_txt2img.py --prompt "Cyberpunk style image of a Telsa car reflection in rain" --H 512 --W 512 --seed 27 --n_iter 2 --n_samples 10 --ddim_steps 50
```
10分くらい待つと生成された画像を格納したパスが案内される。
```console
Your samples are ready in 11.34 minutes and waiting for you here
outputs/txt2img-samples\Cyberpunk_style_image_of_a_Telsa_car_reflection_in_rain
```
## できた画像
20枚のうち1枚だけ貼っておく。
![[00004.png]]
## 参考
[話題のStable Diffusionがオープンソース化されたのでローカルで動かしてみる](https://zenn.dev/koyoarai_/articles/02f3ed864c6127bb2049)