Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
1a035367
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
10 个月 前同步成功
通知
1741
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1a035367
编写于
9月 23, 2022
作者:
A
AUTOMATIC
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Option to use advanced upscalers with normal img2img
上级
6fa20d51
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
15 addition
and
6 deletion
+15
-6
modules/images.py
modules/images.py
+12
-3
modules/processing.py
modules/processing.py
+2
-2
modules/shared.py
modules/shared.py
+1
-1
未找到文件。
modules/images.py
浏览文件 @
1a035367
...
...
@@ -209,8 +209,16 @@ def draw_prompt_matrix(im, width, height, all_prompts):
def
resize_image
(
resize_mode
,
im
,
width
,
height
):
def
resize
(
im
,
w
,
h
):
if
opts
.
upscaler_for_img2img
is
None
or
opts
.
upscaler_for_img2img
==
"None"
:
return
im
.
resize
((
w
,
h
),
resample
=
LANCZOS
)
upscaler
=
[
x
for
x
in
shared
.
sd_upscalers
if
x
.
name
==
opts
.
upscaler_for_img2img
][
0
]
return
upscaler
.
upscale
(
im
,
w
,
h
)
if
resize_mode
==
0
:
res
=
im
.
resize
((
width
,
height
),
resample
=
LANCZOS
)
res
=
resize
(
im
,
width
,
height
)
elif
resize_mode
==
1
:
ratio
=
width
/
height
src_ratio
=
im
.
width
/
im
.
height
...
...
@@ -218,9 +226,10 @@ def resize_image(resize_mode, im, width, height):
src_w
=
width
if
ratio
>
src_ratio
else
im
.
width
*
height
//
im
.
height
src_h
=
height
if
ratio
<=
src_ratio
else
im
.
height
*
width
//
im
.
width
resized
=
im
.
resize
((
src_w
,
src_h
),
resample
=
LANCZOS
)
resized
=
resize
(
im
,
src_w
,
src_h
)
res
=
Image
.
new
(
"RGB"
,
(
width
,
height
))
res
.
paste
(
resized
,
box
=
(
width
//
2
-
src_w
//
2
,
height
//
2
-
src_h
//
2
))
else
:
ratio
=
width
/
height
src_ratio
=
im
.
width
/
im
.
height
...
...
@@ -228,7 +237,7 @@ def resize_image(resize_mode, im, width, height):
src_w
=
width
if
ratio
<
src_ratio
else
im
.
width
*
height
//
im
.
height
src_h
=
height
if
ratio
>=
src_ratio
else
im
.
height
*
width
//
im
.
width
resized
=
im
.
resize
((
src_w
,
src_h
),
resample
=
LANCZOS
)
resized
=
resize
(
im
,
src_w
,
src_h
)
res
=
Image
.
new
(
"RGB"
,
(
width
,
height
))
res
.
paste
(
resized
,
box
=
(
width
//
2
-
src_w
//
2
,
height
//
2
-
src_h
//
2
))
...
...
modules/processing.py
浏览文件 @
1a035367
...
...
@@ -462,7 +462,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
else
:
decoded_samples
=
self
.
sd_model
.
decode_first_stage
(
samples
)
if
opts
.
upscaler_for_
hires_fix
is
None
or
opts
.
upscaler_for_hires_fix
==
"None"
:
if
opts
.
upscaler_for_
img2img
is
None
or
opts
.
upscaler_for_img2img
==
"None"
:
decoded_samples
=
torch
.
nn
.
functional
.
interpolate
(
decoded_samples
,
size
=
(
self
.
height
,
self
.
width
),
mode
=
"bilinear"
)
else
:
lowres_samples
=
torch
.
clamp
((
decoded_samples
+
1.0
)
/
2.0
,
min
=
0.0
,
max
=
1.0
)
...
...
@@ -472,7 +472,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
x_sample
=
255.
*
np
.
moveaxis
(
x_sample
.
cpu
().
numpy
(),
0
,
2
)
x_sample
=
x_sample
.
astype
(
np
.
uint8
)
image
=
Image
.
fromarray
(
x_sample
)
upscaler
=
[
x
for
x
in
shared
.
sd_upscalers
if
x
.
name
==
opts
.
upscaler_for_
hires_fix
][
0
]
upscaler
=
[
x
for
x
in
shared
.
sd_upscalers
if
x
.
name
==
opts
.
upscaler_for_
img2img
][
0
]
image
=
upscaler
.
upscale
(
image
,
self
.
width
,
self
.
height
)
image
=
np
.
array
(
image
).
astype
(
np
.
float32
)
/
255.0
image
=
np
.
moveaxis
(
image
,
2
,
0
)
...
...
modules/shared.py
浏览文件 @
1a035367
...
...
@@ -168,7 +168,7 @@ options_templates.update(options_section(('upscaling', "Upscaling"), {
"ldsr_pre_down"
:
OptionInfo
(
1
,
"LDSR Pre-process downssample scale. 1 = no down-sampling, 4 = 1/4 scale."
,
gr
.
Slider
,
{
"minimum"
:
1
,
"maximum"
:
4
,
"step"
:
1
}),
"ldsr_post_down"
:
OptionInfo
(
1
,
"LDSR Post-process down-sample scale. 1 = no down-sampling, 4 = 1/4 scale."
,
gr
.
Slider
,
{
"minimum"
:
1
,
"maximum"
:
4
,
"step"
:
1
}),
"upscaler_for_
hires_fix"
:
OptionInfo
(
None
,
"Upscaler for highres. fix
"
,
gr
.
Radio
,
lambda
:
{
"choices"
:
[
x
.
name
for
x
in
sd_upscalers
]}),
"upscaler_for_
img2img"
:
OptionInfo
(
None
,
"Upscaler for img2img
"
,
gr
.
Radio
,
lambda
:
{
"choices"
:
[
x
.
name
for
x
in
sd_upscalers
]}),
}))
options_templates
.
update
(
options_section
((
'face-restoration'
,
"Face restoration"
),
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录