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
60c60223
Commit
60c60223
authored
Dec 04, 2023
by
CodeHatchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restored original formatting.
parent
57f29bd6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
25 deletions
+11
-25
modules/processing.py
modules/processing.py
+11
-25
No files found.
modules/processing.py
View file @
60c60223
...
@@ -370,10 +370,7 @@ class StableDiffusionProcessing:
...
@@ -370,10 +370,7 @@ class StableDiffusionProcessing:
return
self
.
edit_image_conditioning
(
source_image
)
return
self
.
edit_image_conditioning
(
source_image
)
if
self
.
sampler
.
conditioning_key
in
{
'hybrid'
,
'concat'
}:
if
self
.
sampler
.
conditioning_key
in
{
'hybrid'
,
'concat'
}:
return
self
.
inpainting_image_conditioning
(
source_image
,
return
self
.
inpainting_image_conditioning
(
source_image
,
latent_image
,
image_mask
=
image_mask
,
round_image_mask
=
round_image_mask
)
latent_image
,
image_mask
=
image_mask
,
round_image_mask
=
round_image_mask
)
if
self
.
sampler
.
conditioning_key
==
"crossattn-adm"
:
if
self
.
sampler
.
conditioning_key
==
"crossattn-adm"
:
return
self
.
unclip_image_conditioning
(
source_image
)
return
self
.
unclip_image_conditioning
(
source_image
)
...
@@ -885,7 +882,8 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
...
@@ -885,7 +882,8 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
if
getattr
(
samples_ddim
,
'already_decoded'
,
False
):
if
getattr
(
samples_ddim
,
'already_decoded'
,
False
):
x_samples_ddim
=
samples_ddim
x_samples_ddim
=
samples_ddim
# todo: generate masks the old fashioned way
# todo: generate adaptive masks based on pixel differences.
# if p.masks_for_overlay is used, it will already be populated with masks
else
:
else
:
if
opts
.
sd_vae_decode_method
!=
'Full'
:
if
opts
.
sd_vae_decode_method
!=
'Full'
:
p
.
extra_generation_params
[
'VAE Decoder'
]
=
opts
.
sd_vae_decode_method
p
.
extra_generation_params
[
'VAE Decoder'
]
=
opts
.
sd_vae_decode_method
...
@@ -900,9 +898,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
...
@@ -900,9 +898,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
height
=
p
.
height
,
height
=
p
.
height
,
paste_to
=
p
.
paste_to
)
paste_to
=
p
.
paste_to
)
x_samples_ddim
=
decode_latent_batch
(
p
.
sd_model
,
samples_ddim
,
x_samples_ddim
=
decode_latent_batch
(
p
.
sd_model
,
samples_ddim
,
target_device
=
devices
.
cpu
,
check_for_nans
=
True
)
target_device
=
devices
.
cpu
,
check_for_nans
=
True
)
x_samples_ddim
=
torch
.
stack
(
x_samples_ddim
)
.
float
()
x_samples_ddim
=
torch
.
stack
(
x_samples_ddim
)
.
float
()
x_samples_ddim
=
torch
.
clamp
((
x_samples_ddim
+
1.0
)
/
2.0
,
min
=
0.0
,
max
=
1.0
)
x_samples_ddim
=
torch
.
clamp
((
x_samples_ddim
+
1.0
)
/
2.0
,
min
=
0.0
,
max
=
1.0
)
...
@@ -927,9 +923,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
...
@@ -927,9 +923,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
x_samples_ddim
=
batch_params
.
images
x_samples_ddim
=
batch_params
.
images
def
infotext
(
index
=
0
,
use_main_prompt
=
False
):
def
infotext
(
index
=
0
,
use_main_prompt
=
False
):
return
create_infotext
(
p
,
p
.
prompts
,
p
.
seeds
,
p
.
subseeds
,
return
create_infotext
(
p
,
p
.
prompts
,
p
.
seeds
,
p
.
subseeds
,
use_main_prompt
=
use_main_prompt
,
index
=
index
,
all_negative_prompts
=
p
.
negative_prompts
)
use_main_prompt
=
use_main_prompt
,
index
=
index
,
all_negative_prompts
=
p
.
negative_prompts
)
save_samples
=
p
.
save_samples
()
save_samples
=
p
.
save_samples
()
...
@@ -972,8 +966,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
...
@@ -972,8 +966,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
image
=
apply_overlay
(
image
,
p
.
paste_to
,
i
,
p
.
overlay_images
)
image
=
apply_overlay
(
image
,
p
.
paste_to
,
i
,
p
.
overlay_images
)
if
save_samples
:
if
save_samples
:
images
.
save_image
(
image
,
p
.
outpath_samples
,
""
,
p
.
seeds
[
i
],
images
.
save_image
(
image
,
p
.
outpath_samples
,
""
,
p
.
seeds
[
i
],
p
.
prompts
[
i
],
opts
.
samples_format
,
info
=
infotext
(
i
),
p
=
p
)
p
.
prompts
[
i
],
opts
.
samples_format
,
info
=
infotext
(
i
),
p
=
p
)
text
=
infotext
(
i
)
text
=
infotext
(
i
)
infotexts
.
append
(
text
)
infotexts
.
append
(
text
)
...
@@ -983,14 +976,10 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
...
@@ -983,14 +976,10 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
if
save_samples
and
any
([
opts
.
save_mask
,
opts
.
save_mask_composite
,
opts
.
return_mask
,
opts
.
return_mask_composite
]):
if
save_samples
and
any
([
opts
.
save_mask
,
opts
.
save_mask_composite
,
opts
.
return_mask
,
opts
.
return_mask_composite
]):
if
hasattr
(
p
,
'masks_for_overlay'
)
and
p
.
masks_for_overlay
:
if
hasattr
(
p
,
'masks_for_overlay'
)
and
p
.
masks_for_overlay
:
image_mask
=
p
.
masks_for_overlay
[
i
]
.
convert
(
'RGB'
)
image_mask
=
p
.
masks_for_overlay
[
i
]
.
convert
(
'RGB'
)
image_mask_composite
=
Image
.
composite
(
image_mask_composite
=
Image
.
composite
(
original_denoised_image
.
convert
(
'RGBA'
)
.
convert
(
'RGBa'
),
Image
.
new
(
'RGBa'
,
image
.
size
),
images
.
resize_image
(
2
,
p
.
masks_for_overlay
[
i
],
image
.
width
,
image
.
height
)
.
convert
(
'L'
))
.
convert
(
'RGBA'
)
original_denoised_image
.
convert
(
'RGBA'
)
.
convert
(
'RGBa'
),
Image
.
new
(
'RGBa'
,
image
.
size
),
images
.
resize_image
(
2
,
p
.
masks_for_overlay
[
i
],
image
.
width
,
image
.
height
)
.
convert
(
'L'
))
.
convert
(
'RGBA'
)
elif
hasattr
(
p
,
'mask_for_overlay'
)
and
p
.
mask_for_overlay
:
elif
hasattr
(
p
,
'mask_for_overlay'
)
and
p
.
mask_for_overlay
:
image_mask
=
p
.
mask_for_overlay
.
convert
(
'RGB'
)
image_mask
=
p
.
mask_for_overlay
.
convert
(
'RGB'
)
image_mask_composite
=
Image
.
composite
(
image_mask_composite
=
Image
.
composite
(
original_denoised_image
.
convert
(
'RGBA'
)
.
convert
(
'RGBa'
),
Image
.
new
(
'RGBa'
,
image
.
size
),
images
.
resize_image
(
2
,
p
.
mask_for_overlay
,
image
.
width
,
image
.
height
)
.
convert
(
'L'
))
.
convert
(
'RGBA'
)
original_denoised_image
.
convert
(
'RGBA'
)
.
convert
(
'RGBa'
),
Image
.
new
(
'RGBa'
,
image
.
size
),
images
.
resize_image
(
2
,
p
.
mask_for_overlay
,
image
.
width
,
image
.
height
)
.
convert
(
'L'
))
.
convert
(
'RGBA'
)
else
:
else
:
image_mask
=
None
image_mask
=
None
image_mask_composite
=
None
image_mask_composite
=
None
...
@@ -1515,8 +1504,8 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
...
@@ -1515,8 +1504,8 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
self
.
masks_for_overlay
.
append
(
image_mask
)
self
.
masks_for_overlay
.
append
(
image_mask
)
else
:
else
:
image_masked
=
Image
.
new
(
'RGBa'
,
(
image
.
width
,
image
.
height
))
image_masked
=
Image
.
new
(
'RGBa'
,
(
image
.
width
,
image
.
height
))
image_masked
.
paste
(
image
.
convert
(
"RGBA"
)
.
convert
(
"RGBa"
),
image_masked
.
paste
(
image
.
convert
(
"RGBA"
)
.
convert
(
"RGBa"
),
mask
=
ImageOps
.
invert
(
self
.
mask_for_overlay
.
convert
(
'L'
)))
mask
=
ImageOps
.
invert
(
self
.
mask_for_overlay
.
convert
(
'L'
)))
self
.
overlay_images
.
append
(
image_masked
.
convert
(
'RGBA'
))
self
.
overlay_images
.
append
(
image_masked
.
convert
(
'RGBA'
))
# crop_region is not None if we are doing inpaint full res
# crop_region is not None if we are doing inpaint full res
...
@@ -1583,10 +1572,7 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
...
@@ -1583,10 +1572,7 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
elif
self
.
inpainting_fill
==
3
:
elif
self
.
inpainting_fill
==
3
:
self
.
init_latent
=
self
.
init_latent
*
self
.
mask
self
.
init_latent
=
self
.
init_latent
*
self
.
mask
self
.
image_conditioning
=
self
.
img2img_image_conditioning
(
image
*
2
-
1
,
self
.
image_conditioning
=
self
.
img2img_image_conditioning
(
image
*
2
-
1
,
self
.
init_latent
,
image_mask
,
self
.
soft_inpainting
is
None
)
self
.
init_latent
,
image_mask
,
self
.
soft_inpainting
is
None
)
def
sample
(
self
,
conditioning
,
unconditional_conditioning
,
seeds
,
subseeds
,
subseed_strength
,
prompts
):
def
sample
(
self
,
conditioning
,
unconditional_conditioning
,
seeds
,
subseeds
,
subseed_strength
,
prompts
):
x
=
self
.
rng
.
next
()
x
=
self
.
rng
.
next
()
...
...
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