Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
31c5ea7b
Commit
31c5ea7b
authored
Nov 20, 2023
by
comfyanonymous
Browse files
Add LatentInterpolate to interpolate between latents.
parent
dba4f3b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
comfy_extras/nodes_latent.py
comfy_extras/nodes_latent.py
+36
-0
No files found.
comfy_extras/nodes_latent.py
View file @
31c5ea7b
import
comfy.utils
import
comfy.utils
import
torch
def
reshape_latent_to
(
target_shape
,
latent
):
def
reshape_latent_to
(
target_shape
,
latent
):
if
latent
.
shape
[
1
:]
!=
target_shape
[
1
:]:
if
latent
.
shape
[
1
:]
!=
target_shape
[
1
:]:
...
@@ -67,8 +68,43 @@ class LatentMultiply:
...
@@ -67,8 +68,43 @@ class LatentMultiply:
samples_out
[
"samples"
]
=
s1
*
multiplier
samples_out
[
"samples"
]
=
s1
*
multiplier
return
(
samples_out
,)
return
(
samples_out
,)
class
LatentInterpolate
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"samples1"
:
(
"LATENT"
,),
"samples2"
:
(
"LATENT"
,),
"ratio"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0.0
,
"max"
:
1.0
,
"step"
:
0.01
}),
}}
RETURN_TYPES
=
(
"LATENT"
,)
FUNCTION
=
"op"
CATEGORY
=
"latent/advanced"
def
op
(
self
,
samples1
,
samples2
,
ratio
):
samples_out
=
samples1
.
copy
()
s1
=
samples1
[
"samples"
]
s2
=
samples2
[
"samples"
]
s2
=
reshape_latent_to
(
s1
.
shape
,
s2
)
m1
=
torch
.
linalg
.
vector_norm
(
s1
,
dim
=
(
1
))
m2
=
torch
.
linalg
.
vector_norm
(
s2
,
dim
=
(
1
))
s1
=
torch
.
nan_to_num
(
s1
/
m1
)
s2
=
torch
.
nan_to_num
(
s2
/
m2
)
t
=
(
s1
*
ratio
+
s2
*
(
1.0
-
ratio
))
mt
=
torch
.
linalg
.
vector_norm
(
t
,
dim
=
(
1
))
st
=
torch
.
nan_to_num
(
t
/
mt
)
samples_out
[
"samples"
]
=
st
*
(
m1
*
ratio
+
m2
*
(
1.0
-
ratio
))
return
(
samples_out
,)
NODE_CLASS_MAPPINGS
=
{
NODE_CLASS_MAPPINGS
=
{
"LatentAdd"
:
LatentAdd
,
"LatentAdd"
:
LatentAdd
,
"LatentSubtract"
:
LatentSubtract
,
"LatentSubtract"
:
LatentSubtract
,
"LatentMultiply"
:
LatentMultiply
,
"LatentMultiply"
:
LatentMultiply
,
"LatentInterpolate"
:
LatentInterpolate
,
}
}
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