Skip to content

Commit cae5aa0

Browse files
committed
update wd14 tagger and doc
1 parent 6ba8428 commit cae5aa0

File tree

4 files changed

+277
-25
lines changed

4 files changed

+277
-25
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ The majority of scripts is licensed under ASL 2.0 (including codes from Diffuser
156156
- The support for v3 repositories is added to `tag_image_by_wd14_tagger.py` (`--onnx` option only). PR [#1192](https://github.com/kohya-ss/sd-scripts/pull/1192) Thanks to sdbds!
157157
- Onnx may need to be updated. Onnx is not installed by default, so please install or update it with `pip install onnx==1.15.0 onnxruntime-gpu==1.17.1` etc. Please also check the comments in `requirements.txt`.
158158
- The model is now saved in the subdirectory as `--repo_id` in `tag_image_by_wd14_tagger.py` . This caches multiple repo_id models. Please delete unnecessary files under `--model_dir`.
159+
- Some options are added to `tag_image_by_wd14_tagger.py`.
160+
- Some are added in PR [#1216](https://github.com/kohya-ss/sd-scripts/pull/1216) Thanks to Disty0!
161+
- Output rating tags `--use_rating_tags` and `--use_rating_tags_as_last_tag`
162+
- Output character tags first `--character_tags_first`
163+
- Expand character tags and series `--character_tag_expand`
164+
- Specify tags to output first `--always_first_tags`
165+
- Replace tags `--tag_replacement`
166+
- See [Tagging documentation](./docs/wd14_tagger_README-en.md) for details.
159167
- Fixed an error when specifying `--beam_search` and a value of 2 or more for `--num_beams` in `make_captions.py`.
160168
- The options `--noise_offset_random_strength` and `--ip_noise_gamma_random_strength` are added to each training script. These options can be used to vary the noise offset and ip noise gamma in the range of 0 to the specified value. PR [#1177](https://github.com/kohya-ss/sd-scripts/pull/1177) Thanks to KohakuBlueleaf!
161169
- The options `--save_state_on_train_end` are added to each training script. PR [#1168](https://github.com/kohya-ss/sd-scripts/pull/1168) Thanks to gesen2egee!
@@ -181,6 +189,14 @@ The majority of scripts is licensed under ASL 2.0 (including codes from Diffuser
181189
- `tag_image_by_wd14_tagger.py` で v3 のリポジトリがサポートされました(`--onnx` 指定時のみ有効)。 PR [#1192](https://github.com/kohya-ss/sd-scripts/pull/1192) sdbds 氏に感謝します。
182190
- Onnx のバージョンアップが必要になるかもしれません。デフォルトでは Onnx はインストールされていませんので、`pip install onnx==1.15.0 onnxruntime-gpu==1.17.1` 等でインストール、アップデートしてください。`requirements.txt` のコメントもあわせてご確認ください。
183191
- `tag_image_by_wd14_tagger.py` で、モデルを`--repo_id` のサブディレクトリに保存するようにしました。これにより複数のモデルファイルがキャッシュされます。`--model_dir` 直下の不要なファイルは削除願います。
192+
- `tag_image_by_wd14_tagger.py` にいくつかのオプションを追加しました。
193+
- 一部は PR [#1216](https://github.com/kohya-ss/sd-scripts/pull/1216) で追加されました。Disty0 氏に感謝します。
194+
- レーティングタグを出力する `--use_rating_tags` および `--use_rating_tags_as_last_tag`
195+
- キャラクタタグを最初に出力する `--character_tags_first`
196+
- キャラクタタグとシリーズを展開する `--character_tag_expand`
197+
- 常に最初に出力するタグを指定する `--always_first_tags`
198+
- タグを置換する `--tag_replacement`
199+
- 詳細は [タグ付けに関するドキュメント](./docs/wd14_tagger_README-ja.md) をご覧ください。
184200
- `make_captions.py``--beam_search` を指定し `--num_beams` に2以上の値を指定した時のエラーを修正しました。
185201
- 各学習スクリプトに、noise offset、ip noise gammaを、それぞれ 0~指定した値の範囲で変動させるオプション `--noise_offset_random_strength` および `--ip_noise_gamma_random_strength` が追加されました。 PR [#1177](https://github.com/kohya-ss/sd-scripts/pull/1177) KohakuBlueleaf 氏に感謝します。
186202
- 各学習スクリプトに、学習終了時に state を保存する `--save_state_on_train_end` オプションが追加されました。 PR [#1168](https://github.com/kohya-ss/sd-scripts/pull/1168) gesen2egee 氏に感謝します。

docs/wd14_tagger_README-en.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Image Tagging using WD14Tagger
2+
3+
This document is based on the information from this github page (https://github.com/toriato/stable-diffusion-webui-wd14-tagger#mrsmilingwolfs-model-aka-waifu-diffusion-14-tagger).
4+
5+
Using onnx for inference is recommended. Please install onnx with the following command:
6+
7+
```powershell
8+
pip install onnx==1.15.0 onnxruntime-gpu==1.17.1
9+
```
10+
11+
The model weights will be automatically downloaded from Hugging Face.
12+
13+
# Usage
14+
15+
Run the script to perform tagging.
16+
17+
```powershell
18+
python finetune/tag_images_by_wd14_tagger.py --onnx --repo_id <model repo id> --batch_size <batch size> <training data folder>
19+
```
20+
21+
For example, if using the repository `SmilingWolf/wd-swinv2-tagger-v3` with a batch size of 4, and the training data is located in the parent folder `train_data`, it would be:
22+
23+
```powershell
24+
python tag_images_by_wd14_tagger.py --onnx --repo_id SmilingWolf/wd-swinv2-tagger-v3 --batch_size 4 ..\train_data
25+
```
26+
27+
On the first run, the model files will be automatically downloaded to the `wd14_tagger_model` folder (the folder can be changed with an option).
28+
29+
Tag files will be created in the same directory as the training data images, with the same filename and a `.txt` extension.
30+
31+
![Generated tag files](https://user-images.githubusercontent.com/52813779/208910534-ea514373-1185-4b7d-9ae3-61eb50bc294e.png)
32+
33+
![Tags and image](https://user-images.githubusercontent.com/52813779/208910599-29070c15-7639-474f-b3e4-06bd5a3df29e.png)
34+
35+
## Example
36+
37+
To output in the Animagine XL 3.1 format, it would be as follows (enter on a single line in practice):
38+
39+
```
40+
python tag_images_by_wd14_tagger.py --onnx --repo_id SmilingWolf/wd-swinv2-tagger-v3
41+
--batch_size 4 --remove_underscore --undesired_tags "PUT,YOUR,UNDESIRED,TAGS" --recursive
42+
--use_rating_tagss_as_last_tag --character_tags_first --character_tag_expand
43+
--always_first_tags "1girl,1boy" ..\train_data
44+
```
45+
46+
## Available Repository IDs
47+
48+
[SmilingWolf's V2 and V3 models](https://huggingface.co/SmilingWolf) are available for use. Specify them in the format like `SmilingWolf/wd-vit-tagger-v3`. The default when omitted is `SmilingWolf/wd-v1-4-convnext-tagger-v2`.
49+
50+
# Options
51+
52+
## General Options
53+
54+
- `--onnx`: Use ONNX for inference. If not specified, TensorFlow will be used. If using TensorFlow, please install TensorFlow separately.
55+
- `--batch_size`: Number of images to process at once. Default is 1. Adjust according to VRAM capacity.
56+
- `--caption_extension`: File extension for caption files. Default is `.txt`.
57+
- `--max_data_loader_n_workers`: Maximum number of workers for DataLoader. Specifying a value of 1 or more will use DataLoader to speed up image loading. If unspecified, DataLoader will not be used.
58+
- `--thresh`: Confidence threshold for outputting tags. Default is 0.35. Lowering the value will assign more tags but accuracy will decrease.
59+
- `--general_threshold`: Confidence threshold for general tags. If omitted, same as `--thresh`.
60+
- `--character_threshold`: Confidence threshold for character tags. If omitted, same as `--thresh`.
61+
- `--recursive`: If specified, subfolders within the specified folder will also be processed recursively.
62+
- `--append_tags`: Append tags to existing tag files.
63+
- `--frequency_tags`: Output tag frequencies.
64+
- `--debug`: Debug mode. Outputs debug information if specified.
65+
66+
## Model Download
67+
68+
- `--model_dir`: Folder to save model files. Default is `wd14_tagger_model`.
69+
- `--force_download`: Re-download model files if specified.
70+
71+
## Tag Editing
72+
73+
- `--remove_underscore`: Remove underscores from output tags.
74+
- `--undesired_tags`: Specify tags not to output. Multiple tags can be specified, separated by commas. For example, `black eyes,black hair`.
75+
- `--use_rating_tags`: Output rating tags at the beginning of the tags.
76+
- `--use_rating_tags_as_last_tag`: Add rating tags at the end of the tags.
77+
- `--character_tags_first`: Output character tags first.
78+
- `--character_tag_expand`: Expand character tag series names. For example, split the tag `chara_name_(series)` into `chara_name, series`.
79+
- `--always_first_tags`: Specify tags to always output first when a certain tag appears in an image. Multiple tags can be specified, separated by commas. For example, `1girl,1boy`.
80+
- `--caption_separator`: Separate tags with this string in the output file. Default is `, `.
81+
- `--tag_replacement`: Perform tag replacement. Specify in the format `tag1,tag2;tag3,tag4`.
82+
83+
When specifying `remove_underscore`, specify `undesired_tags`, `always_first_tags`, and `tag_replacement` without including underscores.
84+
85+
When specifying `caption_separator`, separate `undesired_tags` and `always_first_tags` with `caption_separator`. Always separate `tag_replacement` with `,`.

docs/wd14_tagger_README-ja.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# WD14Taggerによるタグ付け
2+
3+
こちらのgithubページ(https://github.com/toriato/stable-diffusion-webui-wd14-tagger#mrsmilingwolfs-model-aka-waifu-diffusion-14-tagger )の情報を参考にさせていただきました。
4+
5+
onnx を用いた推論を推奨します。以下のコマンドで onnx をインストールしてください。
6+
7+
```powershell
8+
pip install onnx==1.15.0 onnxruntime-gpu==1.17.1
9+
```
10+
11+
モデルの重みはHugging Faceから自動的にダウンロードしてきます。
12+
13+
# 使い方
14+
15+
スクリプトを実行してタグ付けを行います。
16+
```
17+
python fintune/tag_images_by_wd14_tagger.py --onnx --repo_id <モデルのrepo id> --batch_size <バッチサイズ> <教師データフォルダ>
18+
```
19+
20+
レポジトリに `SmilingWolf/wd-swinv2-tagger-v3` を使用し、バッチサイズを4にして、教師データを親フォルダの `train_data`に置いた場合、以下のようになります。
21+
22+
```
23+
python tag_images_by_wd14_tagger.py --onnx --repo_id SmilingWolf/wd-swinv2-tagger-v3 --batch_size 4 ..\train_data
24+
```
25+
26+
初回起動時にはモデルファイルが `wd14_tagger_model` フォルダに自動的にダウンロードされます(フォルダはオプションで変えられます)。
27+
28+
タグファイルが教師データ画像と同じディレクトリに、同じファイル名、拡張子.txtで作成されます。
29+
30+
![生成されたタグファイル](https://user-images.githubusercontent.com/52813779/208910534-ea514373-1185-4b7d-9ae3-61eb50bc294e.png)
31+
32+
![タグと画像](https://user-images.githubusercontent.com/52813779/208910599-29070c15-7639-474f-b3e4-06bd5a3df29e.png)
33+
34+
## 記述例
35+
36+
Animagine XL 3.1 方式で出力する場合、以下のようになります(実際には 1 行で入力してください)。
37+
38+
```
39+
python tag_images_by_wd14_tagger.py --onnx --repo_id SmilingWolf/wd-swinv2-tagger-v3
40+
--batch_size 4 --remove_underscore --undesired_tags "PUT,YOUR,UNDESIRED,TAGS" --recursive
41+
--use_rating_tagss_as_last_tag --character_tags_first --character_tag_expand
42+
--always_first_tags "1girl,1boy" ..\train_data
43+
```
44+
45+
## 使用可能なリポジトリID
46+
47+
[SmilingWolf 氏の V2、V3 のモデル](https://huggingface.co/SmilingWolf)が使用可能です。`SmilingWolf/wd-vit-tagger-v3` のように指定してください。省略時のデフォルトは `SmilingWolf/wd-v1-4-convnext-tagger-v2` です。
48+
49+
# オプション
50+
51+
## 一般オプション
52+
53+
- `--onnx` : ONNX を使用して推論します。指定しない場合は TensorFlow を使用します。TensorFlow 使用時は別途 TensorFlow をインストールしてください。
54+
- `--batch_size` : 一度に処理する画像の数。デフォルトは1です。VRAMの容量に応じて増減してください。
55+
- `--caption_extension` : キャプションファイルの拡張子。デフォルトは `.txt` です。
56+
- `--max_data_loader_n_workers` : DataLoader の最大ワーカー数です。このオプションに 1 以上の数値を指定すると、DataLoader を用いて画像読み込みを高速化します。未指定時は DataLoader を用いません。
57+
- `--thresh` : 出力するタグの信頼度の閾値。デフォルトは0.35です。値を下げるとより多くのタグが付与されますが、精度は下がります。
58+
- `--general_threshold` : 一般タグの信頼度の閾値。省略時は `--thresh` と同じです。
59+
- `--character_threshold` : キャラクタータグの信頼度の閾値。省略時は `--thresh` と同じです。
60+
- `--recursive` : 指定すると、指定したフォルダ内のサブフォルダも再帰的に処理します。
61+
- `--append_tags` : 既存のタグファイルにタグを追加します。
62+
- `--frequency_tags` : タグの頻度を出力します。
63+
- `--debug` : デバッグモード。指定するとデバッグ情報を出力します。
64+
65+
## モデルのダウンロード
66+
67+
- `--model_dir` : モデルファイルの保存先フォルダ。デフォルトは `wd14_tagger_model` です。
68+
- `--force_download` : 指定するとモデルファイルを再ダウンロードします。
69+
70+
## タグ編集関連
71+
72+
- `--remove_underscore` : 出力するタグからアンダースコアを削除します。
73+
- `--undesired_tags` : 出力しないタグを指定します。カンマ区切りで複数指定できます。たとえば `black eyes,black hair` のように指定します。
74+
- `--use_rating_tags` : タグの最初にレーティングタグを出力します。
75+
- `--use_rating_tags_as_last_tag` : タグの最後にレーティングタグを追加します。
76+
- `--character_tags_first` : キャラクタータグを最初に出力します。
77+
- `--character_tag_expand` : キャラクタータグのシリーズ名を展開します。たとえば `chara_name_(series)` のタグを `chara_name, series` に分割します。
78+
- `--always_first_tags` : あるタグが画像に出力されたとき、そのタグを最初に出力するタグを指定します。カンマ区切りで複数指定できます。たとえば `1girl,1boy` のように指定します。
79+
- `--caption_separator` : 出力するファイルでタグをこの文字列で区切ります。デフォルトは `, ` です。
80+
- `--tag_replacement` : タグの置換を行います。`tag1,tag2;tag3,tag4` のように指定します。
81+
82+
`remove_underscore` 指定時は、`undesired_tags``always_first_tags``tag_replacement` はアンダースコアを含めずに指定してください。
83+
84+
`caption_separator` 指定時は、`undesired_tags``always_first_tags``caption_separator` で区切ってください。`tag_replacement` は必ず `,` で区切ってください。
85+

0 commit comments

Comments
 (0)