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
21000f13
Commit
21000f13
authored
Aug 04, 2023
by
Kohaku-Blueleaf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace get_first_stage_encoding
parent
073342c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
7 deletions
+5
-7
modules/processing.py
modules/processing.py
+5
-7
No files found.
modules/processing.py
View file @
21000f13
...
@@ -16,6 +16,7 @@ from typing import Any, Dict, List
...
@@ -16,6 +16,7 @@ from typing import Any, Dict, List
import
modules.sd_hijack
import
modules.sd_hijack
from
modules
import
devices
,
prompt_parser
,
masking
,
sd_samplers
,
lowvram
,
generation_parameters_copypaste
,
extra_networks
,
sd_vae_approx
,
scripts
,
sd_samplers_common
,
sd_unet
,
errors
from
modules
import
devices
,
prompt_parser
,
masking
,
sd_samplers
,
lowvram
,
generation_parameters_copypaste
,
extra_networks
,
sd_vae_approx
,
scripts
,
sd_samplers_common
,
sd_unet
,
errors
from
modules.sd_hijack
import
model_hijack
from
modules.sd_hijack
import
model_hijack
from
modules.sd_samplers_common
import
images_tensor_to_samples
,
decode_first_stage
,
approximation_indexes
from
modules.shared
import
opts
,
cmd_opts
,
state
from
modules.shared
import
opts
,
cmd_opts
,
state
import
modules.shared
as
shared
import
modules.shared
as
shared
import
modules.paths
as
paths
import
modules.paths
as
paths
...
@@ -30,7 +31,6 @@ from ldm.models.diffusion.ddpm import LatentDepth2ImageDiffusion
...
@@ -30,7 +31,6 @@ from ldm.models.diffusion.ddpm import LatentDepth2ImageDiffusion
from
einops
import
repeat
,
rearrange
from
einops
import
repeat
,
rearrange
from
blendmodes.blend
import
blendLayers
,
BlendType
from
blendmodes.blend
import
blendLayers
,
BlendType
decode_first_stage
=
sd_samplers_common
.
decode_first_stage
# some of those options should not be changed at all because they would break the model, so I removed them from options.
# some of those options should not be changed at all because they would break the model, so I removed them from options.
opt_C
=
4
opt_C
=
4
...
@@ -84,7 +84,7 @@ def txt2img_image_conditioning(sd_model, x, width, height):
...
@@ -84,7 +84,7 @@ def txt2img_image_conditioning(sd_model, x, width, height):
# The "masked-image" in this case will just be all zeros since the entire image is masked.
# The "masked-image" in this case will just be all zeros since the entire image is masked.
image_conditioning
=
torch
.
zeros
(
x
.
shape
[
0
],
3
,
height
,
width
,
device
=
x
.
device
)
image_conditioning
=
torch
.
zeros
(
x
.
shape
[
0
],
3
,
height
,
width
,
device
=
x
.
device
)
image_conditioning
=
sd_model
.
get_first_stage_encoding
(
sd_model
.
encode_first_stage
(
image_conditioning
))
image_conditioning
=
images_tensor_to_samples
(
image_conditioning
,
approximation_indexes
.
get
(
opts
.
sd_vae_encode_method
))
# Add the fake full 1s mask to the first dimension.
# Add the fake full 1s mask to the first dimension.
image_conditioning
=
torch
.
nn
.
functional
.
pad
(
image_conditioning
,
(
0
,
0
,
0
,
0
,
1
,
0
),
value
=
1.0
)
image_conditioning
=
torch
.
nn
.
functional
.
pad
(
image_conditioning
,
(
0
,
0
,
0
,
0
,
1
,
0
),
value
=
1.0
)
...
@@ -203,7 +203,7 @@ class StableDiffusionProcessing:
...
@@ -203,7 +203,7 @@ class StableDiffusionProcessing:
midas_in
=
torch
.
from_numpy
(
transformed
[
"midas_in"
][
None
,
...
])
.
to
(
device
=
shared
.
device
)
midas_in
=
torch
.
from_numpy
(
transformed
[
"midas_in"
][
None
,
...
])
.
to
(
device
=
shared
.
device
)
midas_in
=
repeat
(
midas_in
,
"1 ... -> n ..."
,
n
=
self
.
batch_size
)
midas_in
=
repeat
(
midas_in
,
"1 ... -> n ..."
,
n
=
self
.
batch_size
)
conditioning_image
=
self
.
sd_model
.
get_first_stage_encoding
(
self
.
sd_model
.
encode_first_stage
(
source_image
))
conditioning_image
=
images_tensor_to_samples
(
source_image
*
0.5
+
0.5
,
approximation_indexes
.
get
(
opts
.
sd_vae_encode_method
))
conditioning
=
torch
.
nn
.
functional
.
interpolate
(
conditioning
=
torch
.
nn
.
functional
.
interpolate
(
self
.
sd_model
.
depth_model
(
midas_in
),
self
.
sd_model
.
depth_model
(
midas_in
),
size
=
conditioning_image
.
shape
[
2
:],
size
=
conditioning_image
.
shape
[
2
:],
...
@@ -216,7 +216,7 @@ class StableDiffusionProcessing:
...
@@ -216,7 +216,7 @@ class StableDiffusionProcessing:
return
conditioning
return
conditioning
def
edit_image_conditioning
(
self
,
source_image
):
def
edit_image_conditioning
(
self
,
source_image
):
conditioning_image
=
self
.
sd_model
.
encode_first_stage
(
source_image
)
.
mode
(
)
conditioning_image
=
images_tensor_to_samples
(
source_image
*
0.5
+
0.5
,
approximation_indexes
.
get
(
opts
.
sd_vae_encode_method
)
)
return
conditioning_image
return
conditioning_image
...
@@ -1099,9 +1099,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
...
@@ -1099,9 +1099,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
decoded_samples
=
torch
.
from_numpy
(
np
.
array
(
batch_images
))
decoded_samples
=
torch
.
from_numpy
(
np
.
array
(
batch_images
))
decoded_samples
=
decoded_samples
.
to
(
shared
.
device
)
decoded_samples
=
decoded_samples
.
to
(
shared
.
device
)
decoded_samples
=
2.
*
decoded_samples
-
1.
samples
=
self
.
sd_model
.
get_first_stage_encoding
(
self
.
sd_model
.
encode_first_stage
(
decoded_samples
))
samples
=
images_tensor_to_samples
(
decoded_samples
,
approximation_indexes
.
get
(
opts
.
sd_vae_encode_method
))
image_conditioning
=
self
.
img2img_image_conditioning
(
decoded_samples
,
samples
)
image_conditioning
=
self
.
img2img_image_conditioning
(
decoded_samples
,
samples
)
...
@@ -1339,7 +1338,6 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
...
@@ -1339,7 +1338,6 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
raise
RuntimeError
(
f
"bad number of images passed: {len(imgs)}; expecting {self.batch_size} or less"
)
raise
RuntimeError
(
f
"bad number of images passed: {len(imgs)}; expecting {self.batch_size} or less"
)
image
=
torch
.
from_numpy
(
batch_images
)
image
=
torch
.
from_numpy
(
batch_images
)
from
modules.sd_samplers_common
import
images_tensor_to_samples
,
approximation_indexes
self
.
init_latent
=
images_tensor_to_samples
(
image
,
approximation_indexes
.
get
(
opts
.
sd_vae_encode_method
),
self
.
sd_model
)
self
.
init_latent
=
images_tensor_to_samples
(
image
,
approximation_indexes
.
get
(
opts
.
sd_vae_encode_method
),
self
.
sd_model
)
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