Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
76ef3d75
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
11 个月 前同步成功
通知
1765
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
76ef3d75
编写于
10月 10, 2022
作者:
J
JC_Array
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added deepbooru settings (threshold and sort by alpha or likelyhood)
上级
b980e718
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
11 deletion
+31
-11
modules/deepbooru.py
modules/deepbooru.py
+25
-11
modules/shared.py
modules/shared.py
+6
-0
未找到文件。
modules/deepbooru.py
浏览文件 @
76ef3d75
...
...
@@ -3,31 +3,32 @@ from concurrent.futures import ProcessPoolExecutor
import
multiprocessing
import
time
def
get_deepbooru_tags
(
pil_image
,
threshold
=
0.5
):
def
get_deepbooru_tags
(
pil_image
):
"""
This method is for running only one image at a time for simple use. Used to the img2img interrogate.
"""
from
modules
import
shared
# prevents circular reference
create_deepbooru_process
(
threshold
)
create_deepbooru_process
(
shared
.
opts
.
deepbooru_threshold
,
shared
.
opts
.
deepbooru_sort_alpha
)
shared
.
deepbooru_process_return
[
"value"
]
=
-
1
shared
.
deepbooru_process_queue
.
put
(
pil_image
)
while
shared
.
deepbooru_process_return
[
"value"
]
==
-
1
:
time
.
sleep
(
0.2
)
tags
=
shared
.
deepbooru_process_return
[
"value"
]
release_process
()
return
tags
def
deepbooru_process
(
queue
,
deepbooru_process_return
,
threshold
):
def
deepbooru_process
(
queue
,
deepbooru_process_return
,
threshold
,
alpha_sort
):
model
,
tags
=
get_deepbooru_tags_model
()
while
True
:
# while process is running, keep monitoring queue for new image
pil_image
=
queue
.
get
()
if
pil_image
==
"QUIT"
:
break
else
:
deepbooru_process_return
[
"value"
]
=
get_deepbooru_tags_from_model
(
model
,
tags
,
pil_image
,
threshold
)
deepbooru_process_return
[
"value"
]
=
get_deepbooru_tags_from_model
(
model
,
tags
,
pil_image
,
threshold
,
alpha_sort
)
def
create_deepbooru_process
(
threshold
=
0.5
):
def
create_deepbooru_process
(
threshold
,
alpha_sort
):
"""
Creates deepbooru process. A queue is created to send images into the process. This enables multiple images
to be processed in a row without reloading the model or creating a new process. To return the data, a shared
...
...
@@ -40,7 +41,7 @@ def create_deepbooru_process(threshold=0.5):
shared
.
deepbooru_process_queue
=
shared
.
deepbooru_process_manager
.
Queue
()
shared
.
deepbooru_process_return
=
shared
.
deepbooru_process_manager
.
dict
()
shared
.
deepbooru_process_return
[
"value"
]
=
-
1
shared
.
deepbooru_process
=
multiprocessing
.
Process
(
target
=
deepbooru_process
,
args
=
(
shared
.
deepbooru_process_queue
,
shared
.
deepbooru_process_return
,
threshold
))
shared
.
deepbooru_process
=
multiprocessing
.
Process
(
target
=
deepbooru_process
,
args
=
(
shared
.
deepbooru_process_queue
,
shared
.
deepbooru_process_return
,
threshold
,
alpha_sort
))
shared
.
deepbooru_process
.
start
()
...
...
@@ -80,7 +81,7 @@ def get_deepbooru_tags_model():
return
model
,
tags
def
get_deepbooru_tags_from_model
(
model
,
tags
,
pil_image
,
threshold
=
0.5
):
def
get_deepbooru_tags_from_model
(
model
,
tags
,
pil_image
,
threshold
,
alpha_sort
):
import
deepdanbooru
as
dd
import
tensorflow
as
tf
import
numpy
as
np
...
...
@@ -105,15 +106,28 @@ def get_deepbooru_tags_from_model(model, tags, pil_image, threshold=0.5):
for
i
,
tag
in
enumerate
(
tags
):
result_dict
[
tag
]
=
y
[
i
]
result_tags_out
=
[]
unsorted_tags_in_theshold
=
[]
result_tags_print
=
[]
for
tag
in
tags
:
if
result_dict
[
tag
]
>=
threshold
:
if
tag
.
startswith
(
"rating:"
):
continue
result_tags_out
.
append
(
tag
)
unsorted_tags_in_theshold
.
append
((
result_dict
[
tag
],
tag
)
)
result_tags_print
.
append
(
f
'
{
result_dict
[
tag
]
}
{
tag
}
'
)
# sort tags
result_tags_out
=
[]
sort_ndx
=
0
print
(
alpha_sort
)
if
alpha_sort
:
sort_ndx
=
1
# sort by reverse by likelihood and normal for alpha
unsorted_tags_in_theshold
.
sort
(
key
=
lambda
y
:
y
[
sort_ndx
],
reverse
=
(
not
alpha_sort
))
for
weight
,
tag
in
unsorted_tags_in_theshold
:
result_tags_out
.
append
(
tag
)
print
(
'
\n
'
.
join
(
sorted
(
result_tags_print
,
reverse
=
True
)))
return
', '
.
join
(
result_tags_out
).
replace
(
'_'
,
' '
).
replace
(
':'
,
' '
)
\ No newline at end of file
return
', '
.
join
(
result_tags_out
).
replace
(
'_'
,
' '
).
replace
(
':'
,
' '
)
modules/shared.py
浏览文件 @
76ef3d75
...
...
@@ -261,6 +261,12 @@ options_templates.update(options_section(('sampler-params', "Sampler parameters"
's_noise'
:
OptionInfo
(
1.0
,
"sigma noise"
,
gr
.
Slider
,
{
"minimum"
:
0.0
,
"maximum"
:
1.0
,
"step"
:
0.01
}),
}))
if
cmd_opts
.
deepdanbooru
:
options_templates
.
update
(
options_section
((
'deepbooru-params'
,
"DeepBooru parameters"
),
{
"deepbooru_sort_alpha"
:
OptionInfo
(
True
,
"Sort Alphabetical"
,
gr
.
Checkbox
),
'deepbooru_threshold'
:
OptionInfo
(
0.5
,
"Threshold"
,
gr
.
Slider
,
{
"minimum"
:
0.0
,
"maximum"
:
1.0
,
"step"
:
0.01
}),
}))
class
Options
:
data
=
None
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录