Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
1a035367
Commit
1a035367
authored
Sep 23, 2022
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Option to use advanced upscalers with normal img2img
parent
6fa20d51
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
6 deletions
+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
No files found.
modules/images.py
View file @
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
View file @
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
View file @
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"
),
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment