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
2cf3d2ac
Commit
2cf3d2ac
authored
Nov 04, 2022
by
AUTOMATIC1111
Committed by
GitHub
Nov 04, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3923 from random-thoughtss/master
Fix weighted mask for highres fix
parents
3f0f3284
243253ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
15 deletions
+14
-15
modules/masking.py
modules/masking.py
+1
-1
modules/processing.py
modules/processing.py
+13
-14
No files found.
modules/masking.py
View file @
2cf3d2ac
...
@@ -49,7 +49,7 @@ def expand_crop_region(crop_region, processing_width, processing_height, image_w
...
@@ -49,7 +49,7 @@ def expand_crop_region(crop_region, processing_width, processing_height, image_w
ratio_processing
=
processing_width
/
processing_height
ratio_processing
=
processing_width
/
processing_height
if
ratio_crop_region
>
ratio_processing
:
if
ratio_crop_region
>
ratio_processing
:
desired_height
=
(
x2
-
x1
)
*
ratio_processing
desired_height
=
(
x2
-
x1
)
/
ratio_processing
desired_height_diff
=
int
(
desired_height
-
(
y2
-
y1
))
desired_height_diff
=
int
(
desired_height
-
(
y2
-
y1
))
y1
-=
desired_height_diff
//
2
y1
-=
desired_height_diff
//
2
y2
+=
desired_height_diff
-
desired_height_diff
//
2
y2
+=
desired_height_diff
-
desired_height_diff
//
2
...
...
modules/processing.py
View file @
2cf3d2ac
...
@@ -134,11 +134,7 @@ class StableDiffusionProcessing():
...
@@ -134,11 +134,7 @@ class StableDiffusionProcessing():
# Dummy zero conditioning if we're not using inpainting model.
# Dummy zero conditioning if we're not using inpainting model.
# Still takes up a bit of memory, but no encoder call.
# Still takes up a bit of memory, but no encoder call.
# Pretty sure we can just make this a 1x1 image since its not going to be used besides its batch size.
# Pretty sure we can just make this a 1x1 image since its not going to be used besides its batch size.
return
torch
.
zeros
(
return
x
.
new_zeros
(
x
.
shape
[
0
],
5
,
1
,
1
)
x
.
shape
[
0
],
5
,
1
,
1
,
dtype
=
x
.
dtype
,
device
=
x
.
device
)
height
=
height
or
self
.
height
height
=
height
or
self
.
height
width
=
width
or
self
.
width
width
=
width
or
self
.
width
...
@@ -156,11 +152,7 @@ class StableDiffusionProcessing():
...
@@ -156,11 +152,7 @@ class StableDiffusionProcessing():
def
img2img_image_conditioning
(
self
,
source_image
,
latent_image
,
image_mask
=
None
):
def
img2img_image_conditioning
(
self
,
source_image
,
latent_image
,
image_mask
=
None
):
if
self
.
sampler
.
conditioning_key
not
in
{
'hybrid'
,
'concat'
}:
if
self
.
sampler
.
conditioning_key
not
in
{
'hybrid'
,
'concat'
}:
# Dummy zero conditioning if we're not using inpainting model.
# Dummy zero conditioning if we're not using inpainting model.
return
torch
.
zeros
(
return
latent_image
.
new_zeros
(
latent_image
.
shape
[
0
],
5
,
1
,
1
)
latent_image
.
shape
[
0
],
5
,
1
,
1
,
dtype
=
latent_image
.
dtype
,
device
=
latent_image
.
device
)
# Handle the different mask inputs
# Handle the different mask inputs
if
image_mask
is
not
None
:
if
image_mask
is
not
None
:
...
@@ -174,11 +166,11 @@ class StableDiffusionProcessing():
...
@@ -174,11 +166,11 @@ class StableDiffusionProcessing():
# Inpainting model uses a discretized mask as input, so we round to either 1.0 or 0.0
# Inpainting model uses a discretized mask as input, so we round to either 1.0 or 0.0
conditioning_mask
=
torch
.
round
(
conditioning_mask
)
conditioning_mask
=
torch
.
round
(
conditioning_mask
)
else
:
else
:
conditioning_mask
=
torch
.
ones
(
1
,
1
,
*
source_image
.
shape
[
-
2
:])
conditioning_mask
=
source_image
.
new_
ones
(
1
,
1
,
*
source_image
.
shape
[
-
2
:])
# Create another latent image, this time with a masked version of the original input.
# Create another latent image, this time with a masked version of the original input.
# Smoothly interpolate between the masked and unmasked latent conditioning image using a parameter.
# Smoothly interpolate between the masked and unmasked latent conditioning image using a parameter.
conditioning_mask
=
conditioning_mask
.
to
(
source_image
.
device
)
conditioning_mask
=
conditioning_mask
.
to
(
source_image
.
device
)
.
to
(
source_image
.
dtype
)
conditioning_image
=
torch
.
lerp
(
conditioning_image
=
torch
.
lerp
(
source_image
,
source_image
,
source_image
*
(
1.0
-
conditioning_mask
),
source_image
*
(
1.0
-
conditioning_mask
),
...
@@ -674,6 +666,13 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
...
@@ -674,6 +666,13 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
if
opts
.
use_scale_latent_for_hires_fix
:
if
opts
.
use_scale_latent_for_hires_fix
:
samples
=
torch
.
nn
.
functional
.
interpolate
(
samples
,
size
=
(
self
.
height
//
opt_f
,
self
.
width
//
opt_f
),
mode
=
"bilinear"
)
samples
=
torch
.
nn
.
functional
.
interpolate
(
samples
,
size
=
(
self
.
height
//
opt_f
,
self
.
width
//
opt_f
),
mode
=
"bilinear"
)
# Avoid making the inpainting conditioning unless necessary as
# this does need some extra compute to decode / encode the image again.
if
getattr
(
self
,
"inpainting_mask_weight"
,
shared
.
opts
.
inpainting_mask_weight
)
<
1.0
:
image_conditioning
=
self
.
img2img_image_conditioning
(
decode_first_stage
(
self
.
sd_model
,
samples
),
samples
)
else
:
image_conditioning
=
self
.
txt2img_image_conditioning
(
samples
)
for
i
in
range
(
samples
.
shape
[
0
]):
for
i
in
range
(
samples
.
shape
[
0
]):
save_intermediate
(
samples
,
i
)
save_intermediate
(
samples
,
i
)
...
@@ -700,14 +699,14 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
...
@@ -700,14 +699,14 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
samples
=
self
.
sd_model
.
get_first_stage_encoding
(
self
.
sd_model
.
encode_first_stage
(
decoded_samples
))
samples
=
self
.
sd_model
.
get_first_stage_encoding
(
self
.
sd_model
.
encode_first_stage
(
decoded_samples
))
image_conditioning
=
self
.
img2img_image_conditioning
(
decoded_samples
,
samples
)
shared
.
state
.
nextjob
()
shared
.
state
.
nextjob
()
self
.
sampler
=
sd_samplers
.
create_sampler_with_index
(
sd_samplers
.
samplers
,
self
.
sampler_index
,
self
.
sd_model
)
self
.
sampler
=
sd_samplers
.
create_sampler_with_index
(
sd_samplers
.
samplers
,
self
.
sampler_index
,
self
.
sd_model
)
noise
=
create_random_tensors
(
samples
.
shape
[
1
:],
seeds
=
seeds
,
subseeds
=
subseeds
,
subseed_strength
=
subseed_strength
,
seed_resize_from_h
=
self
.
seed_resize_from_h
,
seed_resize_from_w
=
self
.
seed_resize_from_w
,
p
=
self
)
noise
=
create_random_tensors
(
samples
.
shape
[
1
:],
seeds
=
seeds
,
subseeds
=
subseeds
,
subseed_strength
=
subseed_strength
,
seed_resize_from_h
=
self
.
seed_resize_from_h
,
seed_resize_from_w
=
self
.
seed_resize_from_w
,
p
=
self
)
image_conditioning
=
self
.
txt2img_image_conditioning
(
x
)
# GC now before running the next img2img to prevent running out of memory
# GC now before running the next img2img to prevent running out of memory
x
=
None
x
=
None
devices
.
torch_gc
()
devices
.
torch_gc
()
...
...
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