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 6ed4faac46)
This commit is contained in:
Greg Fuller
2022-10-11 18:02:41 -07:00
parent 6be32b31d1
commit d717eb079c
4 changed files with 17 additions and 10 deletions

View File

@@ -123,7 +123,7 @@ class InterrogateModels:
return caption[0]
def interrogate(self, pil_image):
def interrogate(self, pil_image, include_ranks=False):
res = None
try:
@@ -156,7 +156,10 @@ class InterrogateModels:
for name, topn, items in self.categories:
matches = self.rank(image_features, items, top_count=topn)
for match, score in matches:
res += ", " + match
if include_ranks:
res += ", " + match
else:
res += f", ({match}:{score})"
except Exception:
print(f"Error interrogating", file=sys.stderr)