Stable Diffusion の学習機能の紹介
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/Stable-Diffusionの学習機能.jpg)
始めに
Stable Diffusionの学習タブの使用方法を紹介する記事です。この機能を使用しているユザーが居ないのか情報がとても少なく難航しましたが、ようやく学習させることが出来ましたので紹介させていただきます。 先に結論を言いますと 高スペックPC以外ではこの機能の使用は避けた方が良さそうです。CPUとGPUがフルに使用され、長時間高温にさらされますのでヤバイです!
設定方法
学習(Train)の設定箇所は8ヶ所で、めんどくさい設定が続きますので出来る限り分かりやすく説明して行きます。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/①.png)
Create hypernetwork(ハイパーネットワークの作成)
設定①
ここでは ファイル名を設定します、分かりやすい名前を選ぶようににしてください。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/06/女の子.png)
Create hypernetworkのタブをクリックしてハイパーネットワークの名前を入力します。
ここでは(test_v1)と入力して進めて行きます。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1.png)
このタブは変更するところは無いのですが「古いファイルの上書きをする」のチェックを入れるかはお任せします。
Hypernetworkを作成(Create hypernetwork)をクリックして数秒で「Created: None」と表示されます。意味は(作成日: なし)です。
preprocessimages(画像の前処理)
② 画像の前処理に付いて説明します。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/06/女の子.png)
私が悩んだ設定箇所ですので間違っていたらごめんなさい!
前処理タブを開いたら「元のなるディレクトリ」と「保存先のディレクトリ」を記入する箇所が表示されます。
「元のなるディレクトリ」とは学習する画像のフォルダの事です、何処に作っても良いのですがCドライブは避けた方が無難だと思います。
可能なら大容量のドライブを選んでファイルを作成してください。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/✓.png)
フォルダーの追加
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/06/女の子.png)
私の環境では大容量のハードディスクは<Jドライブ>ですので”J”ドライブにフィルダーを作ります。
フォルダー名は 仮に(新しいフォルダー1)とします。
日本語名でも動くみたいですのでご自由に。
(新しいフォルダー1)の中に更にフィルダーを2個追加しますフォルダー名は(元となるディレクトリ)と(保存先のディレクトリ)にします、分かりやすいでしょう!
(元となるディレクトリファイル)に学習用画像を入れて行きます、今回はオレンジロードの鮎川さんの画像を集めてみました。
沢山集めた方が良いと言われますが学習時間が長くなるので10~20枚程度が無難だと思います。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/DemoCreatorSnap_2023-05-20-15-22-44.png)
画像が集まつたら(フォルダ:元となるディレクトリ)のパスをコピーして貼り付けます。
フォルダーを選択して右クリックしてパスのコピーを選択してするとコピー&ペーストで済みます。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/06/コピー方法.png)
同じ手順で(ファイル:保存先のディレクト)もコピーして貼り付けてください。
でも,このままでは使用できません ファイル名が <””>で囲まれている状態では認識しませんので<””>を消してください。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/vw5kchih.png)
消込が終わったら、チェック項目に✓を入れてください。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/07/✓-edited.png)
画像を切り出して同じサイズに整える為の項目です。
終わったら前処理を開始してください、5秒程度で処理が終わり「Preprocessing finished.」と表示されます。意味は(前処理が完了しました。)です。
前処理の結果を確認
左右対称の画像とテキストファイルが生成されます。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/DemoCreatorSnap_2023-05-20-16-00-27.jpg)
テキストにはプロンプトが記載されていますので後で利用できるかもしれませんが今のところ理解出来ていません。・・!
では、戻って学習を始めます。
Train(学習)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/①.png)
- ④Embedding
- ここは白紙ままにします
- ⑤Hypernetwork
- 横の更新ボタンを押して最初に登録した(test_v1)を選択します。
- ⑥Dataset directory
- ここは (保管先のディレクトリファイル)のパスを張り付けます。
- ⑦Log directory
- そのまま
- ⑧Prompt template
- そのまま
バージョンが違うと設定項目が増えたり減ったりして迷いますが、進化していると信じて最低限の設定にしてみました。
下にスクロールして設定をつづけます。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/DemoCreatorSnap_2023-05-20-16-54-03.png)
- Max Steps (最大ステップ数)
- 最大ステップ数が100000とありますが学習時間に十数時間も掛かります。ある程度、妥協して50000に変更します。使用時間は約5時間です
- Save an image to log directory every N steps, 0 to disable
- 何ステップ毎に画像を出力するかの設定です。数字を減らせば画像の枚数が増えます、御注意ください
- Embedding
- 今回は使用しませんので0にします
設定はこれで終了です。Train Hypernetworkボタンを押して学習を開始してください。
学習開始
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/DemoCreatorSnap_2023-05-20-17-43-58.png)
学習が始まると500ステップ毎に画像が表示されていきます、
30分で5000ステップ弱のスピードで学習しています、おおよその残り時間は4時間51分と出ていますのでこのまま放置して結果を報告いたします。
CPUとGPUの稼働率
24スレッドのCPUと12GBのグラフィックボードで5時間以上かかる学習工程です。
ハイスペックPCでなければこの機能を使うのは少々無理が有ると言えます、PCの冷却が追い付きませんので余りお勧め出来ない機能です。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/DemoCreatorSnap_2023-05-20-17-53-49-1024x886.png)
GPUはNVIDIA GeForce RTX 3080Tiで低くは無いと思っていますが95%あたりでうろうろしています。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/DemoCreatorSnap_2023-05-20-18-07-14-939x1024.png)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/DemoCreatorSnap_2023-05-20-21-12-38.png)
4時間経で75% 37270ステップが終わり、 後1時間20分 CPU温度が95℃まで上昇し周波数がこれ以上、上がらなように制御されています。通常は4200MHzで動きますので当初の予測時間内では終わらないもよう・・・・( ノД`)シクシク…
この機能をストレス無く使うには超ハイスペックPCを準備した方が良さそうです
ですが、とても買える金額では収まりませんので、諦めてLoRAの使用をお勧めいたします
学習結果
1~10500ステップまでの結果
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-500-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-1000-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-1500-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-2000-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-2500-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-3000-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-3500-2.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-4000-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-4500-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-5000-2.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-5500-2.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-6000-2.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-6500-2.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-7000-2.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-7500-2.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-8000-2.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-8500-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-9000-2.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-9500-2.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-10000-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-10500.jpg)
奇跡的に似ている物もありますがほぼ全滅でした。
10500~21000ステップ
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-11000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-11500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-12000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-12500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-13000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-13500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-14000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-14500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-15000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-15500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-16000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-16500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-17000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-17500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-18000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-18500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-19000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-19500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-20000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-20500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-21000.jpg)
だいぶ安定してきましたが似てません
21500~32500ステップ
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-21500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-22000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-22500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-23000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-23500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-25000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-25500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-26500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-27000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-27500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-28000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-28500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-29000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-29500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-30000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-30500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-31000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-31500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-24000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-32000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-24500.jpg)
30000ステップを超えても安定していません
33000~44500ステップ
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-33000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-33500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-34000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-34500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-35000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-35500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-36000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-36500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-37000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-37500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-38000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-38500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-39000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-39500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-40000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-40500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-41000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-41500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-42000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-42500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-43000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-43500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-44000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-44500.jpg)
安定して出力されて鮎川に似てきました。
45000~50000ステップ
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-45000-1.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-45500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-46000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-46500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-47000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-47500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-48000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-48500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-49000.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-49500.jpg)
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/test_v1-50000-1.jpg)
ようやく終わりました。 要した時間は5時間19分でした。100000ステップの半分でしたがPCの負担が大きい様に思います。一つ言い忘れていましたが一度に終わらせる必要はありません、なぜなら途中からの再開が出来る仕様になっていますので・・・。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/DemoCreatorSnap_2023-05-20-22-39-17.png)
学習の成果を確認しよう
学習したデーターは🎴ボタン内のhypernetworksのタブ内に収納されていますのでそれを使い、簡単なプロンプトで生成してみます。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/DemoCreatorSnap_2023-05-20-22-58-01.png)
プロンプトは<masterpiece*anime>+トリガーワード<hypernet:test_v1>だけを記載します。
![](https://www.deltakousakusitu.com/wp-content/uploads/2023/05/grid-0065.jpg)
無事にオレンジロードの鮎川が生成されるようになりました。
1点だけ注意事項です。モデル(チェックポイント)を変えると上手く生成されませんでした。
どのMODELで学習させたか忘れないようご注意ください。
Conclusion
この記事では、ハイパーネットワークの基礎と、安定した拡散を持つモデルを学習するためにハイパーネットワークをどのように使用するかについて説明しました。
お勧めは致しませんが、興味が有りましたらチャレンジしてみてください。
(_´Д`)ノ~~オツカレー!
追記
画像ファイルは<"D:\stable-diffusion-webui\textual_inversion\2023-05-20\test_v1\images"> textual_inversionのimagesフォルダ中にあります。
途中の学習ファイルは<"D:\stable-diffusion-webui\textual_inversion\2023-05-20\test_v1\hypernetworks">textual_inversionのhypernetworksフォルダ中にあります。
500ステップ毎のファイルを<"D:\stable-diffusion-webui\models\hypernetworks">models\hypernetworksに張り付けると制度は落ちますが利用は可能です。短時間の学習で奇跡的に生成されたファイルを読み込んで使うのも面白いと思います。試してみてはどうでしょうか!