Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
d252c2a
Make classes WaifuDiffusionInterrogator and MLDanbooruInterrogator a
Jul 23, 2023
714c335
a little more work is required
Jul 23, 2023
e4c056a
add interrogators.json move refresh to interrogator as a static,
Jul 23, 2023
520915b
cleanup
Jul 25, 2023
4d82af3
Merge branch 'master' into configurable_hf_cache
Jul 25, 2023
1d71a8e
As suggested by WSH032
Jul 25, 2023
50203aa
As WSH032 mentioned, this is already caught.
Jul 25, 2023
543fd6e
This was a bug
Jul 25, 2023
3122bfd
allow json to override settings
Jul 25, 2023
9c6df86
broken
Aug 5, 2023
d6dac05
Merge branch 'master' into configurable_hf_cache
Aug 5, 2023
fe9f3fa
Style is deprecated
Aug 6, 2023
1845c72
improve wording, this is just a warning
Aug 6, 2023
1f7ef93
cleanups
Aug 6, 2023
07cd9bd
gvi
Aug 12, 2023
77797f1
a little more work is required
Jul 23, 2023
6d81c4c
add interrogators.json move refresh to interrogator as a static,
Aug 12, 2023
f7f8f18
fix again
Aug 10, 2023
0caa420
Merge branch 'configurable_hf_cache' into configurable_hf_cache2
Aug 12, 2023
39d4fd2
Actually use `--additional-device-ids` arg
catboxanon Aug 12, 2023
ae8345b
currently only one device is supported
Aug 12, 2023
aa92dba
Revert "improve types and other cleanups"
Aug 12, 2023
63892a5
Use a state variable to be able to send the tags via txt2img and friends
Aug 13, 2023
b5d5e6b
Correct nr of args in error returns
Aug 26, 2023
fcbc59b
recursive glob was failing for directories
Aug 19, 2023
aa98f05
actually better to default to True here.
Aug 19, 2023
3e7e6d1
only the double asterisk will recurse
Aug 19, 2023
83ed754
revert back to previous behaviour, but make the recursion more clear …
Aug 19, 2023
0d46fef
ui.py typo
picobyte Aug 22, 2023
8693e13
update changelog
Aug 26, 2023
28cc72d
typos
Aug 26, 2023
e871aa7
Three scripts, a bash script to create per safetensors file the fract…
Sep 2, 2023
aa55f4e
shell/scripts/compare_weighted_frequencies.py: If only interrogated in
Sep 3, 2023
836a6c8
nit
Sep 3, 2023
08a4d81
deprecation warning
Sep 16, 2023
7e0c595
observing dengrixionghnu's branch the version should probably not pass a
Sep 11, 2023
3486bf6
because people were trying to configure exclude tags from the setting…
Sep 13, 2023
fdda828
excudes l
Sep 13, 2023
3c18632
more api tweaks
Sep 16, 2023
16239dc
or rather.. lock like this.
Jul 25, 2023
bd15c8c
The api model also needs to change. Allow a comma delimited list of
Sep 16, 2023
0d8055b
Actually I think first posting, then batch processing multiple is more
Sep 16, 2023
66f8253
allow weight based filtering
Jul 26, 2023
bf792e8
.. and this
Jul 26, 2023
189cc0c
typing
Aug 26, 2023
ad5e474
Fix/use consistent prefix in names for responses
Sep 16, 2023
55acbfa
clobber image if already queued
Aug 26, 2023
f4b0ee8
no assignment to tuple
Aug 26, 2023
fe07da1
The pydantic models require named, not positional arguments
Aug 26, 2023
cab60e7
in progress
Sep 1, 2023
1284e6c
Forgot to commit these before pushing
Sep 11, 2023
bae45dc
something like this
Sep 11, 2023
f6f1dc6
If queue is empty, there is a single interrogation with response. If …
Sep 12, 2023
83614c1
add missing api_model defaults
Sep 12, 2023
0be994c
no running event loop
Sep 12, 2023
dfd7c82
better threshold default (no threshold)
Sep 12, 2023
c1ce31e
first success with running using queue, but the queue is only started
Sep 12, 2023
58f76e8
This does something more, but still some tasks do not complete.
Sep 13, 2023
0a29c4f
asyncio.run already handles the event loop
Sep 13, 2023
05901ad
although an interrogation does not complete, it is queued and executed
Sep 13, 2023
6407d48
(off-topic) allow grepping from stdin
Sep 15, 2023
803ef56
finally some progress
Sep 15, 2023
b057db1
fix name clobber issue
Sep 15, 2023
54add7f
prevent sha256 dup
Sep 15, 2023
cc1768a
For the first image, if no queue name is provided, generate a random
Sep 15, 2023
4579951
move bash_scripts/tag_based_image_dedup.sh
Sep 15, 2023
34759d6
update chagelog
Sep 15, 2023
0ef398a
bump version
Sep 15, 2023
cc4b4c2
gvi
Sep 16, 2023
9dffaad
add interrogators.json move refresh to interrogator as a static,
Sep 16, 2023
571c56c
broken
Sep 16, 2023
0880cd9
cleanups
Aug 6, 2023
b564858
Fixes, Tagger is loaded without initialization errors
Sep 17, 2023
06927ea
clean up
Sep 17, 2023
5d470ef
fix
Sep 17, 2023
8bbad93
clean up
Sep 18, 2023
2741435
this seems to work again, requires json edits for custom models, though
Sep 18, 2023
6d68c96
add fromfile interrogator
Sep 19, 2023
486edca
fix fromfileinterrogator
Sep 19, 2023
ac32226
fix
Sep 20, 2023
6262435
The intent was to allow editing the interrogator properties in settings
Sep 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ __pycache__/
.vscode/
.venv/
.env

presets/
presets/
addons/
77 changes: 74 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,73 @@
# v1.1.1

Api changes:
Image interrogation via api receives two extra parameters; empty strings by
default. `queue`: the name for a queue, which could be e.g. the person or
subject name. You can leave it empty for the first interrogation, then the
response will que in a new auto-generated unique name, listed in the response.
# v1.2.0 (2023-09-16)

Make sure you use this same name as queue, for all interrogations that you want
to be grouped together. The second parameter is `name_in_queue`: the name for
that particular image that is being queued, e.g. a file name.

If both queue and name are empty, there is a single interrogation with response,
which includes nested objects "ratings" and "tags", so:
`{"ratings": {"sensitive": 0.5, ..}, "tags": {"tag1": 0.5, ..}}`

If neither name nor queue are empty, the interrogation is queued under that name.
If already in queue, that name is changed - clobbered - with #. An exception is if
the given name is <sha256> in which case an image checksum will be used instead of
a name. Duplicates are ignored.

During queuing, the response is the number of all processed interrogations for all
active queues.

If name_in_queue is empty, but queue is not, that particular queue is finalized,
A response is awaited for remaining interrogations in this queue (if any still).
The response, only for this queue, is an object with the name_in_queue as key,
and the tag with weights contained. Ratings have ther tag name prefixed with
"rating:". Example:
`{"name_in_queue": {"rating:sensitive": 0.5, "tag1": 0.5, ..}}`

Fix in absence of tensrflow_io
Fix deprecation warning
Added three scripts in shell scripts under shell_scripts:
* A bash script to generate per safetensors file the fraction of images
that the model was trained on that was tagged with particular tokens.
* A python script to compare the interrogation results (read from db.json)
and find the top -c safetensors files that contain similar weights (or at
least, that was the intention, there may be better algorithms to compare,
but it seems to do the job).
* And finally a model_grep script which listts the tags and number of trained
images in a safetensors model.

# v1.1.2 c9f8efd (2023-08-26)

Explain recursive path usage better in ui
Fix sending tags via buttons to txt2img and img2img
type additions, inadvertently pushed, later retouched.
allow setting gpu device via flag
Fix inverted cumulative checkbox
wrap_gradio_gpu_call fallback
Fix for preload shared access
preload update
A few ui changes
Fix not clearing the tags after writing them to files
Fix: Tags were still added, beyond count threshold
fix search/replace bug
(here int based weights were reverted)
circumvent when unable to load tensorflow
fix for too many exclude_tags
add db.json validation schema, add schema validation
return fix for fastapi
pick up huggingface cache dir from env, with default, configurable also via settings.
leave tensorflow requirements to the user.
Fix for Reappearance of gradio bug: duplicate image edit
(index based weights, but later reverted)
Instead of cache_dir use local_dir, leav


# v1.1.1 eada050 (2023-07-20)

Internal cleanup, no separate interrogation for inverse
Fix issues with search and sending selection to keep/exclude
Expand All @@ -11,7 +80,9 @@ fix some hf download issues
fixes for fastapi
added ML-Danbooru support, thanks to [CCRcmcpe](github.com/CCRcmcpe)

# v1.1.0

# v1.1.0 87706b7 (2023-07-16)

fix: failed to install onnxruntime package on MacOS thanks to heady713
fastapi: remote unload model, picked up from [here](https://github.com/toriato/stable-diffusion-webui-wd14-tagger/pull/109)
attribute error fix from aria1th also reported by yjunej
Expand Down Expand Up @@ -39,7 +110,7 @@ changed internal error handling, It is a bit quirky, which I intend to fix, stil
If you find it keeps complaining about an input field without reason, just try editing that one again (e.g. add a space there and remove it).


# v1.0.0
# v1.0.0 a1b59d6 (2023-07-10)

You may have to remove the presets/default.json and save a new one.witth your desired defaults. Otherwise checkboxes may not have the right default values.

Expand Down
71 changes: 71 additions & 0 deletions default/interrogators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"MLDanbooruInterrogator": {
"mld-caformer.dec-5-97527" : {
"model_path" : "ml_caformer_m36_dec-5-97527.onnx",
"name" : "ML-Danbooru Caformer dec-5-97527",
"repo_id" : "deepghs/ml-danbooru-onnx"
},
"mld-tresnetd.6-30000" : {
"model_path" : "TResnet-D-FLq_ema_6-30000.onnx",
"name" : "ML-Danbooru TResNet-D 6-30000",
"repo_id" : "deepghs/ml-danbooru-onnx"
}
},
"WaifuDiffusionInterrogator": {
"wd-v1-4-moat-tagger.v2" : {
"name" : "WD14 moat tagger v2",
"repo_id" : "SmilingWolf/wd-v1-4-moat-tagger-v2"
},
"wd14-convnext.v1" : {
"name" : "WD14 ConvNeXT v1",
"repo_id" : "SmilingWolf/wd-v1-4-convnext-tagger"
},
"wd14-convnext.v2" : {
"name" : "WD14 ConvNeXT v2",
"repo_id" : "SmilingWolf/wd-v1-4-convnext-tagger-v2"
},
"wd14-convnextv2.v1" : {
"name" : "WD14 ConvNeXTV2 v1",
"repo_id" : "SmilingWolf/wd-v1-4-convnextv2-tagger-v2"
},
"wd14-swinv2-v1" : {
"name" : "WD14 SwinV2 v1",
"repo_id" : "SmilingWolf/wd-v1-4-swinv2-tagger-v2"
},
"wd14-vit.v1" : {
"name" : "WD14 ViT v1",
"repo_id" : "SmilingWolf/wd-v1-4-vit-tagger"
},
"wd14-vit.v2" : {
"name" : "WD14 ViT v2",
"repo_id" : "SmilingWolf/wd-v1-4-vit-tagger-v2"
}
},
"DeepDanbooruInterrogator": {
"deepdanbooru-v3-20211112-sgd-e28": {
"zip": "https://github.com/KichangKim/DeepDanbooru/releases/download/v3-20211112-sgd-e28/deepdanbooru-v3-20211112-sgd-e28.zip"
},
"deepdanbooru-v4-20200814-sgd-e30": {
"zip": "https://github.com/KichangKim/DeepDanbooru/releases/download/v4-20200814-sgd-e30/deepdanbooru-v4-20200814-sgd-e30.zip"
}
},
"FromFileInterrogator": {
"[name].[hash:sha1].[output_extension]": {
"format": "[name].[hash:sha1].[output_extension]",
"path": "",
"value": 1.0
}
},
"MLDanbooruInterrogator": {
"mld-caformer.dec-5-97527" : {
"model_path" : "ml_caformer_m36_dec-5-97527.onnx",
"name" : "ML-Danbooru Caformer dec-5-97527",
"repo_id" : "deepghs/ml-danbooru-onnx"
},
"mld-tresnetd.6-30000" : {
"model_path" : "TResnet-D-FLq_ema_6-30000.onnx",
"name" : "ML-Danbooru TResNet-D 6-30000",
"repo_id" : "deepghs/ml-danbooru-onnx"
}
}
}
7 changes: 4 additions & 3 deletions install.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Install requirements for WD14-tagger."""
import os
import sys

import json
from launch import run # pylint: disable=import-error

local_dir = os.path.dirname(os.path.realpath(__file__))

NAME = "WD14-tagger"
req_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"requirements.txt")
req_file = os.path.join(local_dir, "requirements.txt")
print(f"loading {NAME} reqs from {req_file}")
run(f'"{sys.executable}" -m pip install -q -r "{req_file}"',
f"Checking {NAME} requirements.",
Expand Down
40 changes: 20 additions & 20 deletions json_schema/db_json_v1_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@
"type": "array",
"prefixItems": [
{"type": "string" },
{"type": "number", "minimum": 0}
],
"minContains": 2,
"maxContains": 2
}
}
},
"meta": {
"type": "object",
"properties": {
"index_shift": {
"type": "integer",
"minimum": 0,
"maximum": 16
{"type": "number", "minimum": 0}
],
"minContains": 2,
"maxContains": 2
}
}
},
"meta": {
"type": "object",
"properties": {
"index_shift": {
"type": "integer",
"minimum": 0,
"maximum": 16
}
},
"add": { "type": "string" },
"exclude": { "type": "string" },
"keep": { "type": "string" },
"repl": { "type": "string" },
"search": { "type": "string" }
}
},
"add": { "type": "string" },
"exclude": { "type": "string" },
"keep": { "type": "string" },
"repl": { "type": "string" },
"search": { "type": "string" }
},
"required": ["rating", "tag", "query"],
"additionalProperties": false,
Expand Down
104 changes: 104 additions & 0 deletions json_schema/interrogators_v1_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Interrogator Configurations",
"type": "object",
"properties": {
"MLDanbooruInterrogator": {
"type": "object",
"patternProperties": {
".*": { "$ref": "#/$defs/huggingfaceInterrogator" }
}
},
"WaifuDiffusionInterrogator": {
"type": "object",
"patternProperties": {
".*": { "$ref": "#/$defs/huggingfaceInterrogator" }
}
},
"DeepDanbooruInterrogator": {
"type": "object",
"patternProperties": {
".*": {
"type": "object",
"properties": {
"zip": { "type": "string" }
},
"additionalProperties": false
}
}
},
"MLDanbooruInterrogator": {
"type": "object",
"patternProperties": {
".*": { "$ref": "#/$defs/huggingfaceInterrogator" }
}
},
"FromFileInterrogator": {
"type": "object",
"patternProperties": {
".*": {
"type": "object",
"properties": {
"path": { "type": "string" },
"format": { "type": "string", "default": "[name].[output_extension]" },
"value": { "type": "number", "default": 1.0 }
},
"required": [
"path"
],
"additionalProperties": false
}
}
},
"additionalProperties": false
},
"$defs": {
"huggingfaceInterrogator": {
"type": "object",
"properties": {
"name": { "type": "string" },
"local_model": { "type": "string" },
"local_tags": { "type": "string" },
"model_path": { "type": "string" },
"repo_id": { "type": "string" },
"filename": { "type": "string" },
"subfolder": { "type": "string" },
"repo_type": { "type": "string" },
"revision": { "type": "string" },
"endpoint": { "type": "string" },
"library_name": { "type": "string" },
"library_version": { "type": "string" },
"cache_dir": { "type": "string" },
"local_dir": { "type": "string" },
"local_dir_use_symlinks": { "type": "string" },
"user_agent": { "type": "string" },
"force_download": { "type": "boolean" },
"force_filename": { "type": "string" },
"proxies": { "type": "string" },
"etag_timeout": { "type": "number" },
"resume_download": { "type": "boolean" },
"token": { "type": "string" },
"local_files_only": { "type": "boolean" },
"legacy_cache_layout": { "type": "boolean" }
},
"$comment": "repo_id is required if you want to actually download the model",
"oneOf": [
{
"required": [
"name",
"repo_id"
]
},
{
"required": [
"name",
"local_model",
"local_tags"
]
}
],
"additionalProperties": false
}
}
}

7 changes: 5 additions & 2 deletions preload.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
""" Preload module for DeepDanbooru or onnxtagger. """
from pathlib import Path
from argparse import ArgumentParser
from pathlib import Path

root_dir = Path(__file__).parent


def preload(parser: ArgumentParser):
Expand All @@ -19,8 +21,9 @@ def preload(parser: ArgumentParser):
type=str,
help='Path to directory with Onnyx project(s).'
)
# TODO allow using devices in parallel, specified as comma separed list
parser.add_argument(
'--additional-device-ids',
type=str,
help='Extra device ID to use. cpu:0,gpu:1..',
help='Device ID to use. cpu:0, gpu:0 or gpu:1, etc.',
)
Loading