Improve code.

This commit is contained in:
corkborg
2023-10-01 19:17:25 +09:00
parent 0b8bec1ac6
commit cf0b86be80
2 changed files with 6 additions and 8 deletions
+6 -2
View File
@@ -1,7 +1,9 @@
import sys
from tagger.interrogator import Interrogator, WaifuDiffusionInterrogator
from PIL import Image
from pathlib import Path
interrogator = WaifuDiffusionInterrogator(
'wd14-convnextv2-v2',
@@ -9,9 +11,11 @@ interrogator = WaifuDiffusionInterrogator(
revision='v2.0'
)
im = Image.open("image.jpg")
image_path = Path(sys.argv[1])
im = Image.open(image_path)
result = interrogator.interrogate(im)
tags = Interrogator.postprocess_tags(result[1])
tags = Interrogator.postprocess_tags(result[1], threshold=0.35)
print()
for k, v in tags.items():
-6
View File
@@ -10,16 +10,11 @@ from pathlib import Path
from huggingface_hub import hf_hub_download
import re
# from tagger.deepbooru import re_special as tag_escape_pattern
tag_escape_pattern = re.compile(r'([\\()])')
# i'm not sure if it's okay to add this file to the repository
import tagger.dbimutils as dbimutils
# select a device to process
use_cpu = True
if use_cpu:
tf_device_name = '/cpu:0'
else:
@@ -29,7 +24,6 @@ class Interrogator:
@staticmethod
def postprocess_tags(
tags: Dict[str, float],
threshold=0.35,
additional_tags: List[str] = [],
exclude_tags: List[str] = [],