News:

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

Former www.henthighschool.com

BK Autotagger

Started by Ch12, Feb 23, 2025, 05:37 PM

Previous topic - Next topic

Ch12Topic starter

Hi,

It took me quite a bit longer than I thought, but here's the first version of the BK-Autotagger. Basically, it automates the process of tagging images, building upon modern AI technology.
It works by taking the output of the WD14-Tagger (booru-tags with weights) and converts them into tags from the BrothelKing tagging system.

While there are a few missed tags here and there, overall the Autotagger performs really well. (To be honest, when I started out, I expected the tagging quality to be much worse.)

Here's a Girlpack for Shampoo completely tagged by the Autotagger. Basically, I took an old girlpack for Shampoo and fed it into the Autotagger. I did not edit the tags afterwards, so this is the pure result from automated tagging. It can definitely benefit from a human going over it and finetune it some more, but I think it has reasonable quality on its own.
It reaches A+ all on its own, which is pretty cool.

Installation:

To use BK Autotagger, you need to first install the Stable Diffusion WebUI.
I recommend to the sd . webui . zip file from
https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/tag/v1.0.0-pre
Extract this to a new directory, and then start 'run.bat'

Next, once the WebUI is up and running, you need to install
https://github.com/picobyte/stable-diffusion-webui-wd14-tagger
(there's also https://github.com/toriato/stable-diffusion-webui-wd14-tagger , but according to Jman that one did not work)
Once downloaded, you should see a new tab "Tagger". Switch to it.

Please make sure you follow all of these steps:
- In the "Tagger" UI, you HAVE to switch to "Batch from Directory".
- Disable "Save to tags files". This is recommended, as BK Autotagger works purely on the db.json file, which includes not only the tags, but also the confidence levels.
- Make sure the interrogator WD14 moat tagger v2 is selected. BK Autotagger was trained using that model, so using other models here would decrease prediction quality later.
- Enter the directory of one of your girlpacks and start the tagger
- The outcome should be a "db.json" file in your girlpack directory
  - This is a test run. Normally, it is recommended you copy the girlpack directly into the 'imagepacks' directory of BK Autotagger. (which we install in the following step)


Now, download the BK Autotagger 1.0.
- Extract it into the sd.webui directory, so that it sits next to the WebUI. This allows you to reuse the python runtime, which already has a lot of the necessary components installed. If you did things correctly, things should look like this: (basically, run.bat and bk-autotagger.bat should be in the same directory)

sd.webui
    bk-autotagger
        imagepacks
            (your girlpacks go here9
        (python files)
    system
        ...
    webui
        ...
    bk-autotagger.bat
    bk-autotagger_initialInstall.bat
    run.bat


- run bk-autotagger_initialInstall.bat. This installs any missing python packages.
- copy your girlpack into the imagepacks directory.
- run bk-autotagger.bat. It will create a directory 'autotagged' inside the girlpack and copy the images there with the new tags.


Please be aware that this is a first version. So there is no fancy UI or manual. But it works, and it works well. :)
That being said, there are a few shortcomings. It cannot properly recognize fisting, because WD14 does not tag it either. In Bisexual and lesbian images, tags like 'sub' and 'dom' may be applied incorrectly, as the tagger does not know which of the women is the 'focus'.


But other than that, it does really well. (Though maybe I am biased ;) )
You can also try playing with some of the settings in config . py.
Download My High Quality Girlpacks
Belldandy, Urd, Kaenbyou Rin, Jessica Albert, Kino Makoto (Sailor Jupiter), Temari, Tohsaka Rin, Pyra, Lyndis, Atago, Zelda, Kasumi, Camilla, Ningguang

Ch12Topic starter

Download My High Quality Girlpacks
Belldandy, Urd, Kaenbyou Rin, Jessica Albert, Kino Makoto (Sailor Jupiter), Temari, Tohsaka Rin, Pyra, Lyndis, Atago, Zelda, Kasumi, Camilla, Ningguang

Ch12Topic starter

Download My High Quality Girlpacks
Belldandy, Urd, Kaenbyou Rin, Jessica Albert, Kino Makoto (Sailor Jupiter), Temari, Tohsaka Rin, Pyra, Lyndis, Atago, Zelda, Kasumi, Camilla, Ningguang

Jman

#3
Looks cool and all. 👍

But... :'(
ERROR: No matching distribution found for pytorch_lightning==1.7.6
For whatever reason it seems to want that particular version. If I try to install that manually, I get version 2.5, which still returns me to the same error (with an extra step).



Edit: After wasting some more GB, I finally got some sort of browser UI up and running. Still, it's throwing stuff like this at me:
Stable diffusion model failed to load
Torch not compiled with CUDA enabled
cannot import name 'models_path' from partially initialized module 'modules.shared' (most likely due to a circular import)
cannot import name 'wrap_gradio_gpu_call' from 'webui'


And, the image generation part says 'Torch not compiled with CUDA enabled'.

So I assume the actual SD part is borked due to prereqs not lining up. Damn if I know how to solve this, though.


Finally, I figured maybe that was not so important and tried installing https://github.com/toriato/stable-diffusion-webui-wd14-tagger. Now it sits there under 'Extensions', but no 'Tagger' tab is appearing.

I kinda feel stupid. :-\



Edit2: Okay, I finally got this up by using https://github.com/picobyte/stable-diffusion-webui-wd14-tagger instead.



Edit3: Tested it on a Sill pack I've never got around to completing. Seems to work pretty well, except for not always recognising her pink kimono-like garb as either 'geisha' or 'kimono', and occasionally splashing 'sensitivity' onto random images. 👍
And with strange aeons even death may die...

Ch12Topic starter

#4
Hey Jman,

Looks like you also had a fun time installing the WebUI. If it is any consolation, it also took me a while, but after that it works pretty stable.

The error messages from Edit1 seem like you do not have a generative model. Or maybe it's your GPU, I don't know. In the first case, I can recommend you download the "Dreamshaper" model from https://civitai.com/ (~2GB). you then have to put it into /model/stable-diffusion

Anyway, what you mention about Sill is one of the weaknesses of automatic tagging. In case your girl has some prominent feature, you end up with lots of tags about her standard outfit, catears, etc.

Regarding sensitivity, I lowered the strictness for that tag in config . py. You can increase the value, that should make less random sensitivity tags appear. Ultimately, the model seems to have inferred something for sensitivity, but hell if I know what it looks for exactly. :D


Anyway, thanks for the positive feedback, good to hear that it works. I've added your feedback regarding picobyte to the install instructions.
Download My High Quality Girlpacks
Belldandy, Urd, Kaenbyou Rin, Jessica Albert, Kino Makoto (Sailor Jupiter), Temari, Tohsaka Rin, Pyra, Lyndis, Atago, Zelda, Kasumi, Camilla, Ningguang

Jman

#5
I do seem to have some sort of model in models\Stable-diffusion. It takes up 4 GB, it better be one! :P

I think it's kind of conflicting dependencies thing, which doesn't play well with either autoinstall or my setup (Win 10, Python 3.10 instead of the latest, an older Nvidia GPU, god knows what exactly in the nooks and crannies of the OS). Not sure I really want to mess with it further, since I'm unlikely to start cranking out faux Sills anytime soon. :)


Anyway, Sill seemed to have an opposite problem. What I, a human ;), clearly consider either formal enough to be 'geisha' or even an outright kimono/yukata, strange pink colour notwithstanding, wasn't really registering with the autotagger.

https://rule34.xxx/index.php?page=post&s=view&id=20715 is a typical example.


As to sensitivity, where it puts it is not totally unwarranted. But it fails to tag the same image with very slight differences, e.g. open mouth instead of closed. And there are lots of other images that look quite similar and don't get it. So, yeah, IDK what exactly is going on there. Wonder what booru tags it's deriving it from? The db.json file doesn't seem to be human-readable...
And with strange aeons even death may die...

Ch12Topic starter

Regarding the image you posted, do miko clothes (I think Sill is cosplaying here?) rate as kimono?

Anyway, if you are curious what is going on under the hood:
- You can turn on write_db_csv in the config, this will write a csv-file containing the contents of db.json, which you can then open with Calc or Excel.
  - If you want to check one particular image, you are probably better off just checking it in the WebUI
- The linear model is the only one that's intuitively understandable by humans. There is a _modelinfo file in the model-lin folder that shows how the different tags factor in.
Download My High Quality Girlpacks
Belldandy, Urd, Kaenbyou Rin, Jessica Albert, Kino Makoto (Sailor Jupiter), Temari, Tohsaka Rin, Pyra, Lyndis, Atago, Zelda, Kasumi, Camilla, Ningguang

Jman

#7
I think these are just Sill's clothes for that game? Or maybe she's dressing native, as sometimes happens? Granted, the tagger didn't find any 'miko' in there, either, although 'japanese_clothes' did show up towards the end.

As far as I'm concerned, this particular variety of strange kimono/miko/whatever is close enough to be 'kimono', and definitely 'geisha'. Actually, it's a bit strange that 'miko' doesn't go under 'geisha'. I guess your training packs didn't have many of those?

I took a look at 'sensitivity' weights, and I'm as clueless as ever. The closest thing there is 'open_mouth', but this both didn't show up in the booru-tagger and the image that got the 'sensitive' tag was the variant where her mouth was closed. The open-mouth version didn't get 'sensitive' and the highest-weight actual tag that showed up was 'closed_eyes'. So, IDK what exactly is happening here.

Can I somehow check which tags were assigned by the booru-tagger for a specific image, and what the BK autotagger transformed those into? Because it seems running it again might change some lower-confidence tags.
And with strange aeons even death may die...

Ch12Topic starter

You are correct, miko was one of 3 tags where I had almost no training data. I added some images manually, but even after that, it's less than 100 images.
Compare that to almost 6k images for happy, 4k for profile or sex, and you can see that some tags have a lot more training data than others.

One more thing, the way I'm tagging, I usually add 'miko' images to 'ceremony', not 'geisha'.

QuoteCan I somehow check which tags were assigned by the booru-tagger for a specific image, and what the BK autotagger transformed those into?

You could enable the db.csv, and then combine it with the data from _predictions.csv. However, I want to warn you - I've tried that before, and it did not really lead me anywhere.
Best you can do is probably increase/decrease the strictness for tags you feel are over/underrepresented.
Download My High Quality Girlpacks
Belldandy, Urd, Kaenbyou Rin, Jessica Albert, Kino Makoto (Sailor Jupiter), Temari, Tohsaka Rin, Pyra, Lyndis, Atago, Zelda, Kasumi, Camilla, Ningguang

Jman

#9
How do I get db.csv? Righ now, I'm getting the JSON and a bunch of individual .txt files. Can't see an obvious option in the WebUI, either.



Regarding 'miko', there's some variance but the classical versions are close enough to fit 'geisha', which is a much more important tag than 'ceremony' (I don't think vanilla BK uses it at all). Sure, if a girl has both and in quantity, you can make a distinction.

Then again, this is easily solved by changing the 'miko' rules within BK itself, so doesn't really matter too much. If only the tagger actually detected 'miko'...
And with strange aeons even death may die...

Ch12Topic starter

It's not through the WebUI. The BK Autotagger comes with a config . py file. There you can set the option 'write_db_csv' to True. Then running the autotagger will create a csv-file in the specific imagepack directory. (not in the autotagged folder, but the parent directory)
Download My High Quality Girlpacks
Belldandy, Urd, Kaenbyou Rin, Jessica Albert, Kino Makoto (Sailor Jupiter), Temari, Tohsaka Rin, Pyra, Lyndis, Atago, Zelda, Kasumi, Camilla, Ningguang

Jman

Hmm, this is indeed of not much use without a lot of further cleaning.

What do the 'target-XXX' entries mean?
And with strange aeons even death may die...

Ch12Topic starter

Yeah, I also think this is ultimately not very useful for everyday purposes. (The reason why I turned it off by default)

You can ignore the target columns, these are from training and have no influence on prediction.
Download My High Quality Girlpacks
Belldandy, Urd, Kaenbyou Rin, Jessica Albert, Kino Makoto (Sailor Jupiter), Temari, Tohsaka Rin, Pyra, Lyndis, Atago, Zelda, Kasumi, Camilla, Ningguang

empee2000

Got this working on ubuntu 24.04 LTS. Had to change the line that was hardcoding backslashes into the file paths, but no other major issues. Since the binary distribution of the webui was windows only I just cloned it and followed the readme to get it set up. I had to manually install python3.11 and the python3.11 venv, but mostly was just able to follow instructions. I put the autotagger in it's own directory, installed requirements in a venv and ran main.py. It took about 45 minutes for the stable diffusion tagger to analyze ~1k images, this is probably(?) variable based on hardware. I haven't had a chance to check how well the autotagger actually did, but I'll try to leave some feedback once I've looked at it. I also haven't messed with the config yet.

Ch12Topic starter

Thanks for the feedback. I heard stable diffusion can be faster on Linux, though I'm not sure if it is actually true.

Also, on my Windows machine, the tagging process seems to only use the CPU. I tried enabling GPU support, but so far have not been successful. Seeing it takes you 45 minutes for 1k images, it seems you are stuck with CPU as well.

On Windows, I get some hints from ONNX about enabling GPU support. Is there something similar on Linux as well?
Download My High Quality Girlpacks
Belldandy, Urd, Kaenbyou Rin, Jessica Albert, Kino Makoto (Sailor Jupiter), Temari, Tohsaka Rin, Pyra, Lyndis, Atago, Zelda, Kasumi, Camilla, Ningguang