aboutsummaryrefslogtreecommitdiffstats
path: root/modules/deepbooru.py
diff options
context:
space:
mode:
authorGreg Fuller <gfuller23@gmail.com>2022-10-12 01:02:41 +0000
committerGreg Fuller <gfuller23@gmail.com>2022-10-12 01:02:41 +0000
commitd717eb079cd6b7fa7a4f97c0a10d400bdec753fb (patch)
tree5e63e2a59b4f0de00bf3b7cb960e4f86c23b3be0 /modules/deepbooru.py
parent6be32b31d181e42c639dad3451229aa7b9cfd1cf (diff)
downloadstable-diffusion-webui-gfx803-d717eb079cd6b7fa7a4f97c0a10d400bdec753fb.tar.gz
stable-diffusion-webui-gfx803-d717eb079cd6b7fa7a4f97c0a10d400bdec753fb.tar.bz2
stable-diffusion-webui-gfx803-d717eb079cd6b7fa7a4f97c0a10d400bdec753fb.zip
Interrogate: add option to include ranks in output
Since the UI also allows users to specify ranks, it can be useful to show people what ranks are being returned by interrogate This can also give much better results when feeding the interrogate results back into either img2img or txt2img, especially when trying to generate a specific character or scene for which you have a similar concept image Testing Steps: Launch Webui with command line arg: --deepdanbooru Navigate to img2img tab, use interrogate DeepBooru, verify tags appears as before. Use "Interrogate CLIP", verify prompt appears as before Navigate to Settings tab, enable new option, click "apply settings" Navigate to img2img, Interrogate DeepBooru again, verify that weights appear and are properly formatted. Note that "Interrogate CLIP" prompt is still unchanged In my testing, this change has no effect to "Interrogate CLIP", as it seems to generate a sentence-structured caption, and not a set of tags. (reproduce changes from https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/2149/commits/6ed4faac46c45ca7353f228aca9b436bbaba7bc7)
Diffstat (limited to 'modules/deepbooru.py')
-rw-r--r--modules/deepbooru.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/modules/deepbooru.py b/modules/deepbooru.py
index 7e3c0618..32d741e2 100644
--- a/modules/deepbooru.py
+++ b/modules/deepbooru.py
@@ -3,7 +3,7 @@ from concurrent.futures import ProcessPoolExecutor
from multiprocessing import get_context
-def _load_tf_and_return_tags(pil_image, threshold):
+def _load_tf_and_return_tags(pil_image, threshold, include_ranks):
import deepdanbooru as dd
import tensorflow as tf
import numpy as np
@@ -52,12 +52,16 @@ def _load_tf_and_return_tags(pil_image, threshold):
if result_dict[tag] >= threshold:
if tag.startswith("rating:"):
continue
- result_tags_out.append(tag)
+ tag_formatted = tag.replace('_', ' ').replace(':', ' ')
+ if include_ranks:
+ result_tags_out.append(f'({tag_formatted}:{result_dict[tag]})')
+ else:
+ result_tags_out.append(tag_formatted)
result_tags_print.append(f'{result_dict[tag]} {tag}')
print('\n'.join(sorted(result_tags_print, reverse=True)))
- return ', '.join(result_tags_out).replace('_', ' ').replace(':', ' ')
+ return ', '.join(result_tags_out)
def subprocess_init_no_cuda():
@@ -65,9 +69,9 @@ def subprocess_init_no_cuda():
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
-def get_deepbooru_tags(pil_image, threshold=0.5):
+def get_deepbooru_tags(pil_image, threshold=0.5, include_ranks=False):
context = get_context('spawn')
with ProcessPoolExecutor(initializer=subprocess_init_no_cuda, mp_context=context) as executor:
- f = executor.submit(_load_tf_and_return_tags, pil_image, threshold, )
+ f = executor.submit(_load_tf_and_return_tags, pil_image, threshold, include_ranks)
ret = f.result() # will rethrow any exceptions
return ret \ No newline at end of file