News:

Please request registration email again and then check your "Spam" folder

Former www.henthighschool.com

Automated tagging

Started by neronero, Jun 19, 2023, 10:06 AM

Previous topic - Next topic

neroneroTopic starter

Lately I've been interested BLIP captioning and interrogators. I think it's feasible to make a largely automated girlpack tagger. At the very least it would be a useful tool to drastically reduce the workload.

Here's an online example of what I mean: http://dev.kanotype.net:8003/deepdanbooru/ - upload any image and an ML-algorithm attempts to tag it

To batch process images, I'm using stable-diffusion-webui-wd14-tagger for Automatic1111's stable diffusion web UI. It allows me to configure the output, so that it only includes tags that are relevant to Brothel King's tagging system and discards the rest.

My "exclusion list" still needs a bit of finetuning, but here's an example of the output:



I'm also modifying the Tagging Tool to accept/interpret the output properly. For example, it understands that "yuri" implies the tag "lesbian".

But I need some help to get over a big hurdle: The output is saved as a .txt file next to the input image, but obviously to automate this process as much as possible, the filename of the input image should be modified instead. It sounds simple, but my python knowledge is limited and I'm not sure how to go about this. I hope someone can have a look at wd14-tagger's code and point me in the right direction.
My Girl Packs: [ link ] - Trait King mod: [ link ]

neroneroTopic starter

It's terribly inelegant, but I've managed to rename images by adding this to ui.py:

            original_path = str(output_path)[:-3] # output_path is the .txt file's save path

            if os.path.isfile(original_path + 'jpg'):
                os.rename(original_path + 'jpg', output_dir.joinpath(
                    plain_tags_filename + '.jpg'
                ))
            elif os.path.isfile(original_path + 'png'):
                os.rename(original_path + 'png', output_dir.joinpath(
                    plain_tags_filename + '.png'
                ))

I think what makes it difficult for me is that the code mostly doesn't deal with the original image, but with a simplified version of it that's stored in RAM. So I'm having a hard time understanding where the original's name/path is stored.
My Girl Packs: [ link ] - Trait King mod: [ link ]

Toshiro

Hmm this looks pretty interesting/promising.  Tagging was always one of those things that made me not want to make packs.  If it could make it faster I think it would reduce the barrier to entry for many.

neroneroTopic starter

Here are some more test results.

Some liberties are taken when translating from the detected booru-tags to BK-tags, and lots of the 'mistakes' stem from that. For example, "rest" is bound to contain some false-positives since it just checks if the girl is sleeping, sitting or lying down. And when you reduce it to just sleeping, that tag would become too rare and restrictive for BK's purposes.

image>1% confidence>5% confidence>25% confidence>50% confidence
nakednakednakednaked
rest nakedrest nakedrest nakedrest naked
naked bondagebondagebondagebondage
rest swim kimono beadsrest kimonorest kimonokimono
rest naked group sex swim handjob cowgirl cumshot on-body on-face in-hair in-mouth bukkakenaked group sex swim handjob cowgirl cumshot on-body on-face in-hair in-mouth bukkakegroup sex swim handjob cumshot on-body on-face in-hair bukkakegroup sex swim handjob cumshot on-body on-face
rest naked sex anal grope doggy cumshot orgasmnaked sex grope doggynaked sex doggynaked sex doggy
rest naked group lesbian sex swim public grope finger oral sixty-nine rimmingrest naked group lesbian sex swim sixty-nine rimmingrest naked lesbian swim sixty-ninelesbian
swim fight wetswimswimswim
rest naked sex titjob oral cumshot in-mouthtitjob oral cumshot titjobtitjob
profile rest group bisexual lesbian sex dom finger oralrest group bisexual lesbian sexrest group lesbian sexrest
rest sex happy cosplay toy dildo vibrator bondagesex happy toy dildohappy_UNTAGGED
dancer constitution happy cosplayhappy_UNTAGGED_UNTAGGED
My Girl Packs: [ link ] - Trait King mod: [ link ]

neroneroTopic starter

#4
Here are some instructions and modified files if anyone else wants to try it.


Requirements:


- Automatic1111's stable diffusion webui
https://github.com/AUTOMATIC1111/stable-diffusion-webui/

- The toriato's Tagger extension for stable diffusion webui
https://github.com/toriato/stable-diffusion-webui-wd14-tagger/

- BK's tagging tool (v2.8 + latest patch v2.8.14)
https://henthighschool.net/brothel-king/picturenamer/

In case you're not familiar with these tools, installing them might be a bit of a journey. Follow the instructions on the github pages closely.



Modifications:

After downloading/installing those things, these are the modifications I've made to them:

- Modified files for toriato's Tagger extension edit: alternatively, you can skip this edit and use this standalone program to rename files instead
(Adds functionality to enable the tagger to rename files instead of saving tags in a .txt file)
ui.py - replaces this file:
stable-diffusion-webui\extensions\stable-diffusion-webui-wd14-tagger\tagger\ui.py

(Settings preset for the tagger that adds most non-relevant booru tags to an exclude list)
settings_bk.json
- add in this directory:
stable-diffusion-webui\extensions\stable-diffusion-webui-wd14-tagger\presets\...

- Modified files for BK's tagging tool
(Adds more "variants" to the tagging tool so that relevant booru tags are recognised)
settings.rpy and tagset_extended.rpy - replaces files in your BK tagger's game directory:
Picture_namer_for_BK-2.8-pc\game\...



How to use:

1) In Automatic1111's stable diffusion webui, open the "Tagger" tab, then the "Batch from directory" subtab
2) Enable the checkbox "Brothel King mode: Rename original files (no .txt output)"
3) Under preset, load the settings for settings_bk.json, if it's loaded properly then the "Exclude tags" box below is now full of tags. Edit: this can be a bit buggy, if it refuses to load properly, duplicate the file in your /presets/ folder and switch back and forth between different json files to load them) --- Edit 2: Still not working? See here.
4) Add a directory to the "Input directory" field and press interrogate
5) Bring the renamed files to the tagging tool which will translate the booru-tags into BK-tags
My Girl Packs: [ link ] - Trait King mod: [ link ]

kingthandra

3) Under preset, load the settings for settings_bk.json, if it's loaded properly then the "Exclude tags" box below is now full of tags

Sorry neronero, this part doesn't work for me, the preset is loaded but it doesn't add the tags.



I'm missing something?

Downloaded all your files and followed your explanation.

Sorry for bad english not my main language.

neroneroTopic starter

#6
Quote from: kingthandra on Jun 21, 2023, 04:03 PM3) Under preset, load the settings for settings_bk.json, if it's loaded properly then the "Exclude tags" box below is now full of tags

Sorry neronero, this part doesn't work for me, the preset is loaded but it doesn't add the tags.

I'm missing something?

Downloaded all your files and followed your explanation.

Sorry for bad english not my main language.
Try switching back and forth between default.json and settings_bk.json, I've noticed the same issue in the UI: Sometimes the dropdown box will display "settings_bk.json" without having loaded it properly.

Also, in your preset folder make sure that the .json file is still roughly the same size as the one you've downloaded (~2mb), I'm a bit worried that you've overwritten it since the text "successfully saved the preset" is displayed.

If all else fails you can always open settings_bk.json with a text editor to copy over the settings to the UI (json is a format that's easy to read/understand)
My Girl Packs: [ link ] - Trait King mod: [ link ]

kingthandra

Quote from: neronero on Jun 21, 2023, 04:16 PM
Quote from: kingthandra on Jun 21, 2023, 04:03 PM3) Under preset, load the settings for settings_bk.json, if it's loaded properly then the "Exclude tags" box below is now full of tags

Sorry neronero, this part doesn't work for me, the preset is loaded but it doesn't add the tags.

I'm missing something?

Downloaded all your files and followed your explanation.

Sorry for bad english not my main language.
Try switching back and forth between default.json and settings_bk.json, I've noticed the same issue in the UI: Sometimes the dropdown box will display "settings_bk.json" without having loaded it properly.

Also, in your preset folder make sure that the .json file is still roughly the same size as the one you've downloaded (~2mb), I'm a bit worried that you've overwritten it since the text "successfully saved the preset" is displayed.

If all else fails you can always open settings_bk.json with a text editor to copy over the settings to the UI (json is a format that's easy to read/understand)

Okay, i didn't have the "default.json" file in presets but i just duplicated the one you provided (and also true the thing you mentioned i deleted it with the saved preset thing xD), and switching it in the list worked and loaded all the filters.

It's working now, thank you!

neroneroTopic starter

Quote from: neronero on Jun 21, 2023, 12:24 PM- Modified files for toriato's Tagger extension
(Adds functionality to enable the tagger to rename files instead of saving tags in a .txt file)
ui.py - replaces this file:
stable-diffusion-webui\extensions\stable-diffusion-webui-wd14-tagger\tagger\ui.py
Regarding the modifications to toriato's Tagger extension, a user named Kealan on F95zone pointed out that there's a good alternative to this: Don't modify wd14-tagger, and instead create a standalone program that converts the contents of .txt files into filenames. That way, it'll keep working even if future updates and changes are made to the tagger extension.

So here's a standalone py script / executable that does just that: It asks you to pick a folder, looks for text files in that folder and renames any identically named files based on the contents of those text files. The txt files are removed in the process.
My Girl Packs: [ link ] - Trait King mod: [ link ]

ohlookitsnsfw

Quote from: neronero on Jun 21, 2023, 12:24 PMHere are some instructions and modified files if anyone else wants to try it.


Requirements:


- Automatic1111's stable diffusion webui
https://github.com/AUTOMATIC1111/stable-diffusion-webui/

- The toriato's Tagger extension for stable diffusion webui
https://github.com/toriato/stable-diffusion-webui-wd14-tagger/

- BK's tagging tool (v2.8 + latest patch v2.8.14)
https://henthighschool.net/brothel-king/picturenamer/

In case you're not familiar with these tools, installing them might be a bit of a journey. Follow the instructions on the github pages closely.



Modifications:

After downloading/installing those things, these are the modifications I've made to them:

- Modified files for toriato's Tagger extension
(Adds functionality to enable the tagger to rename files instead of saving tags in a .txt file)
ui.py - replaces this file:
stable-diffusion-webui\extensions\stable-diffusion-webui-wd14-tagger\tagger\ui.py

(Settings preset for the tagger that adds most non-relevant booru tags to an exclude list)
settings_bk.json
- add in this directory:
stable-diffusion-webui\extensions\stable-diffusion-webui-wd14-tagger\presets\...

- Modified files for BK's tagging tool
(Adds more "variants" to the tagging tool so that relevant booru tags are recognised)
settings.rpy and tagset_extended.rpy - replaces files in your BK tagger's game directory:
Picture_namer_for_BK-2.8-pc\game\...



How to use:

1) In Automatic1111's stable diffusion webui, open the "Tagger" tab, then the "Batch from directory" subtab
2) Enable the checkbox "Brothel King mode: Rename original files (no .txt output)"
3) Under preset, load the settings for settings_bk.json, if it's loaded properly then the "Exclude tags" box below is now full of tags. Edit: this can be a bit buggy, if it refuses to load properly, duplicate the file in your /presets/ folder and switch back and forth between different json files to load them)
4) Add a directory to the "Input directory" field and press interrogate
5) Bring the renamed files to the tagging tool which will translate the booru-tags into BK-tags
Sorry Nero, I've been trying to follow the instructions on your post but regardlesss of how I installed toriatos tagger extention I couldn't find a presets folder. I went ahead and created my own and put your settings_bk.json file in but I ran into the issue mentioned above where tags weren't being excluded. I duplicated the settings_bk.json file and tried switching between the 2 to no avail so I'm assuming I've misssed something. I'm very new to all of this so any help would be apreciated, thanks.

neroneroTopic starter

Quote from: ohlookitsnsfw on Jun 30, 2023, 12:01 PMSorry Nero, I've been trying to follow the instructions on your post but regardlesss of how I installed toriatos tagger extention I couldn't find a presets folder. I went ahead and created my own and put your settings_bk.json file in but I ran into the issue mentioned above where tags weren't being excluded. I duplicated the settings_bk.json file and tried switching between the 2 to no avail so I'm assuming I've misssed something. I'm very new to all of this so any help would be apreciated, thanks.
You can open the .json in any text editor, such as Notepad, to see its contents and copy over the settings. For the setting "Exclude tags (split by comma)" you'll see a very long list of tags. Copy those over to the exclude tags box in the GUI.

If you don't see a long list of tags there, you may have accidentally saved over the file. It should be about 1,7 MB. Download it again if it's only a few KB and doesn't include the long list of exclusion tags.

Most other settings are not that important or fine by default. Eg: It's important that "Use spaces instead of underscore" is not ticked. The "Threshold" setting determines how 'confident' the algorithm should be before including a tag (set to 0.1/10% confidence in my settings file, but you can change it as you see fit)
My Girl Packs: [ link ] - Trait King mod: [ link ]

kingthandra

Quote from: neronero on Jun 30, 2023, 03:27 PM
Quote from: ohlookitsnsfw on Jun 30, 2023, 12:01 PMSorry Nero, I've been trying to follow the instructions on your post but regardlesss of how I installed toriatos tagger extention I couldn't find a presets folder. I went ahead and created my own and put your settings_bk.json file in but I ran into the issue mentioned above where tags weren't being excluded. I duplicated the settings_bk.json file and tried switching between the 2 to no avail so I'm assuming I've misssed something. I'm very new to all of this so any help would be apreciated, thanks.
You can open the .json in any text editor, such as Notepad, to see its contents and copy over the settings. For the setting "Exclude tags (split by comma)" you'll see a very long list of tags. Copy those over to the exclude tags box in the GUI.

If you don't see a long list of tags there, you may have accidentally saved over the file. It should be about 1,7 MB. Download it again if it's only a few KB and doesn't include the long list of exclusion tags.

Most other settings are not that important or fine by default. Eg: It's important that "Use spaces instead of underscore" is not ticked. The "Threshold" setting determines how 'confident' the algorithm should be before including a tag (set to 0.1/10% confidence in my settings file, but you can change it as you see fit)

How exactly works the confidence setting?

For 0.1, to assign a tag to the image, the AI is like 99.9% sure the image have those tag?

neroneroTopic starter

#12
Quote from: kingthandra on Jun 30, 2023, 05:03 PMHow exactly works the confidence setting?

For 0.1, to assign a tag to the image, the AI is like 99.9% sure the image have those tag?
1.0 = 100%, 0.1 = 10%, 0.01 = 1%

So the table with test images earlier in this thread used 0.01, 0.05, 0.25 and 0.5 as its thresholds.

Even at 0.01 / 1%, the algorithm has some reason (but not a lot of reasons) to believe that a certain tag could be in the image. But the sweet spot seems to be somewhere between 0.05 and 0.25
My Girl Packs: [ link ] - Trait King mod: [ link ]

ohlookitsnsfw

Quote from: neronero on Jun 30, 2023, 03:27 PM
Quote from: ohlookitsnsfw on Jun 30, 2023, 12:01 PMSorry Nero, I've been trying to follow the instructions on your post but regardlesss of how I installed toriatos tagger extention I couldn't find a presets folder. I went ahead and created my own and put your settings_bk.json file in but I ran into the issue mentioned above where tags weren't being excluded. I duplicated the settings_bk.json file and tried switching between the 2 to no avail so I'm assuming I've misssed something. I'm very new to all of this so any help would be apreciated, thanks.
You can open the .json in any text editor, such as Notepad, to see its contents and copy over the settings. For the setting "Exclude tags (split by comma)" you'll see a very long list of tags. Copy those over to the exclude tags box in the GUI.

If you don't see a long list of tags there, you may have accidentally saved over the file. It should be about 1,7 MB. Download it again if it's only a few KB and doesn't include the long list of exclusion tags.

Most other settings are not that important or fine by default. Eg: It's important that "Use spaces instead of underscore" is not ticked. The "Threshold" setting determines how 'confident' the algorithm should be before including a tag (set to 0.1/10% confidence in my settings file, but you can change it as you see fit)
Ah I should have realised that. Thank you it's working now. Hopefully will be able to start posting packs thanks to this, I'm very grateful.

defp

You know, this AI could be used for far more than just tagging. Let's say you have an AI trained to generate images based on these tags. Moreover you could use some of the AI techniques to create variants based on existing character images.

Missing an image for a tag type? No problem! Generate that automagically.