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
|
|
|
| 1 |
+
## リポジトリについて
|
| 2 |
+
Stable Diffusionの学習、画像生成、その他のスクリプトを入れたリポジトリです。
|
| 3 |
+
|
| 4 |
+
[README in English](./README.md) ←更新情報はこちらにあります
|
| 5 |
+
|
| 6 |
+
GUIやPowerShellスクリプトなど、より使いやすくする機能が[bmaltais氏のリポジトリ](https://github.com/bmaltais/kohya_ss)で提供されています(英語です)のであわせてご覧ください。bmaltais氏に感謝します。
|
| 7 |
+
|
| 8 |
+
以下のスクリプトがあります。
|
| 9 |
+
|
| 10 |
+
* DreamBooth、U-NetおよびText Encoderの学習をサポート
|
| 11 |
+
* fine-tuning、同上
|
| 12 |
+
* LoRAの学習をサポート
|
| 13 |
+
* 画像生成
|
| 14 |
+
* モデル変換(Stable Diffision ckpt/safetensorsとDiffusersの相互変換)
|
| 15 |
+
|
| 16 |
+
## 使用法について
|
| 17 |
+
|
| 18 |
+
* [学習について、共通編](./docs/train_README-ja.md) : データ整備やオプションなど
|
| 19 |
+
* [データセット設定](./docs/config_README-ja.md)
|
| 20 |
+
* [SDXL学習](./docs/train_SDXL-en.md) (英語版)
|
| 21 |
+
* [DreamBoothの学習について](./docs/train_db_README-ja.md)
|
| 22 |
+
* [fine-tuningのガイド](./docs/fine_tune_README_ja.md):
|
| 23 |
+
* [LoRAの学習について](./docs/train_network_README-ja.md)
|
| 24 |
+
* [Textual Inversionの学習について](./docs/train_ti_README-ja.md)
|
| 25 |
+
* [画像生成スクリプト](./docs/gen_img_README-ja.md)
|
| 26 |
+
* note.com [モデル変換スクリプト](https://note.com/kohya_ss/n/n374f316fe4ad)
|
| 27 |
+
|
| 28 |
+
## Windowsでの動作に必要なプログラム
|
| 29 |
+
|
| 30 |
+
Python 3.10.6およびGitが必要です。
|
| 31 |
+
|
| 32 |
+
- Python 3.10.6: https://www.python.org/ftp/python/3.10.6/python-3.10.6-amd64.exe
|
| 33 |
+
- git: https://git-scm.com/download/win
|
| 34 |
+
|
| 35 |
+
PowerShellを使う場合、venvを使えるようにするためには以下の手順でセキュリティ設定を変更してください。
|
| 36 |
+
(venvに限らずスクリプトの実行が可能になりますので注意してください。)
|
| 37 |
+
|
| 38 |
+
- PowerShellを管理者として開きます。
|
| 39 |
+
- 「Set-ExecutionPolicy Unrestricted」と入力し、Yと答えます。
|
| 40 |
+
- 管理者のPowerShellを閉じます。
|
| 41 |
+
|
| 42 |
+
## Windows環境でのインストール
|
| 43 |
+
|
| 44 |
+
スクリプトはPyTorch 2.1.2でテストしています。PyTorch 2.0.1、1.12.1でも動作すると思われます。
|
| 45 |
+
|
| 46 |
+
(なお、python -m venv~の行で「python」とだけ表示された場合、py -m venv~のようにpythonをpyに変更してください。)
|
| 47 |
+
|
| 48 |
+
PowerShellを使う場合、通常の(管理者ではない)PowerShellを開き以下を順に実行します。
|
| 49 |
+
|
| 50 |
+
```powershell
|
| 51 |
+
git clone https://github.com/kohya-ss/sd-scripts.git
|
| 52 |
+
cd sd-scripts
|
| 53 |
+
|
| 54 |
+
python -m venv venv
|
| 55 |
+
.\venv\Scripts\activate
|
| 56 |
+
|
| 57 |
+
pip install torch==2.1.2 torchvision==0.16.2 --index-url https://download.pytorch.org/whl/cu118
|
| 58 |
+
pip install --upgrade -r requirements.txt
|
| 59 |
+
pip install xformers==0.0.23.post1 --index-url https://download.pytorch.org/whl/cu118
|
| 60 |
+
|
| 61 |
+
accelerate config
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
コマンドプロンプトでも同一です。
|
| 65 |
+
|
| 66 |
+
注:`bitsandbytes==0.43.0`、`prodigyopt==1.0`、`lion-pytorch==0.0.6` は `requirements.txt` に含まれるようになりました。他のバージョンを使う場合は適宜インストールしてください。
|
| 67 |
+
|
| 68 |
+
この例では PyTorch および xfomers は2.1.2/CUDA 11.8版をインストールします。CUDA 12.1版やPyTorch 1.12.1を使う場合は適宜書き換えください。たとえば CUDA 12.1版の場合は `pip install torch==2.1.2 torchvision==0.16.2 --index-url https://download.pytorch.org/whl/cu121` および `pip install xformers==0.0.23.post1 --index-url https://download.pytorch.org/whl/cu121` としてください。
|
| 69 |
+
|
| 70 |
+
accelerate configの質問には以下のように答えてください。(bf16で学習する場合、最後の質問にはbf16と答えてください。)
|
| 71 |
+
|
| 72 |
+
```txt
|
| 73 |
+
- This machine
|
| 74 |
+
- No distributed training
|
| 75 |
+
- NO
|
| 76 |
+
- NO
|
| 77 |
+
- NO
|
| 78 |
+
- all
|
| 79 |
+
- fp16
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
※場合によって ``ValueError: fp16 mixed precision requires a GPU`` というエラーが出ることがあるようです。この場合、6番目の質問(
|
| 83 |
+
``What GPU(s) (by id) should be used for training on this machine as a comma-separated list? [all]:``)に「0」と答えてください。(id `0`のGPUが使われます。)
|
| 84 |
+
|
| 85 |
+
## アップグレード
|
| 86 |
+
|
| 87 |
+
新しいリリースがあった場合、以下のコマンドで更新できます。
|
| 88 |
+
|
| 89 |
+
```powershell
|
| 90 |
+
cd sd-scripts
|
| 91 |
+
git pull
|
| 92 |
+
.\venv\Scripts\activate
|
| 93 |
+
pip install --use-pep517 --upgrade -r requirements.txt
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
コマンドが成功すれば新しいバージョンが使用できます。
|
| 97 |
+
|
| 98 |
+
## 謝意
|
| 99 |
+
|
| 100 |
+
LoRAの実装は[cloneofsimo氏のリポジトリ](https://github.com/cloneofsimo/lora)を基にしたものです。感謝申し上げます。
|
| 101 |
+
|
| 102 |
+
Conv2d 3x3への拡大は [cloneofsimo氏](https://github.com/cloneofsimo/lora) が最初にリリースし、KohakuBlueleaf氏が [LoCon](https://github.com/KohakuBlueleaf/LoCon) でその有効性を明らかにしたものです。KohakuBlueleaf氏に深く感謝します。
|
| 103 |
+
|
| 104 |
+
## ライセンス
|
| 105 |
+
|
| 106 |
+
スクリプトのライセンスはASL 2.0ですが(Diffusersお���びcloneofsimo氏のリポジトリ由来のものも同様)、一部他のライセンスのコードを含みます。
|
| 107 |
+
|
| 108 |
+
[Memory Efficient Attention Pytorch](https://github.com/lucidrains/memory-efficient-attention-pytorch): MIT
|
| 109 |
+
|
| 110 |
+
[bitsandbytes](https://github.com/TimDettmers/bitsandbytes): MIT
|
| 111 |
+
|
| 112 |
+
[BLIP](https://github.com/salesforce/BLIP): BSD-3-Clause
|
| 113 |
+
|
| 114 |
+
## その他の情報
|
| 115 |
+
|
| 116 |
+
### LoRAの名称について
|
| 117 |
+
|
| 118 |
+
`train_network.py` がサポートするLoRAについて、混乱を避けるため名前を付けました。ドキュメントは更新済みです。以下は当リポジトリ内の独自の名称です。
|
| 119 |
+
|
| 120 |
+
1. __LoRA-LierLa__ : (LoRA for __Li__ n __e__ a __r__ __La__ yers、リエラと読みます)
|
| 121 |
+
|
| 122 |
+
Linear 層およびカーネルサイズ 1x1 の Conv2d 層に適用されるLoRA
|
| 123 |
+
|
| 124 |
+
2. __LoRA-C3Lier__ : (LoRA for __C__ olutional layers with __3__ x3 Kernel and __Li__ n __e__ a __r__ layers、セリアと読みます)
|
| 125 |
+
|
| 126 |
+
1.に加え、カーネルサイズ 3x3 の Conv2d 層に適用されるLoRA
|
| 127 |
+
|
| 128 |
+
デフォルトではLoRA-LierLaが使われます。LoRA-C3Lierを使う場合は `--network_args` に `conv_dim` を指定してください。
|
| 129 |
+
|
| 130 |
+
<!--
|
| 131 |
+
LoRA-LierLa は[Web UI向け拡張](https://github.com/kohya-ss/sd-webui-additional-networks)、またはAUTOMATIC1111氏のWeb UIのLoRA機能で使用することができます。
|
| 132 |
+
|
| 133 |
+
LoRA-C3Lierを使いWeb UIで生成するには拡張を使用してください。
|
| 134 |
+
-->
|
| 135 |
+
|
| 136 |
+
### 学習中のサンプル画像生成
|
| 137 |
+
|
| 138 |
+
プロンプトファイルは例えば以下のようになります。
|
| 139 |
+
|
| 140 |
+
```
|
| 141 |
+
# prompt 1
|
| 142 |
+
masterpiece, best quality, (1girl), in white shirts, upper body, looking at viewer, simple background --n low quality, worst quality, bad anatomy,bad composition, poor, low effort --w 768 --h 768 --d 1 --l 7.5 --s 28
|
| 143 |
+
|
| 144 |
+
# prompt 2
|
| 145 |
+
masterpiece, best quality, 1boy, in business suit, standing at street, looking back --n (low quality, worst quality), bad anatomy,bad composition, poor, low effort --w 576 --h 832 --d 2 --l 5.5 --s 40
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
`#` で始まる行はコメントになります。`--n` のように「ハイフン二個+英小文字」の形でオプションを指定できます。以下が使用可能できます。
|
| 149 |
+
|
| 150 |
+
* `--n` Negative prompt up to the next option.
|
| 151 |
+
* `--w` Specifies the width of the generated image.
|
| 152 |
+
* `--h` Specifies the height of the generated image.
|
| 153 |
+
* `--d` Specifies the seed of the generated image.
|
| 154 |
+
* `--l` Specifies the CFG scale of the generated image.
|
| 155 |
+
* `--s` Specifies the number of steps in the generation.
|
| 156 |
+
|
| 157 |
+
`( )` や `[ ]` などの重みづけも動作します。
|