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
aa57136d
Commit
aa57136d
authored
Apr 25, 2023
by
comfyanonymous
Browse files
Some fixes to the batch masks PR.
parent
c7c1f0d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
10 deletions
+7
-10
comfy/sample.py
comfy/sample.py
+4
-3
nodes.py
nodes.py
+3
-7
No files found.
comfy/sample.py
View file @
aa57136d
import
torch
import
torch
import
comfy.model_management
import
comfy.model_management
import
comfy.samplers
import
comfy.samplers
import
math
def
prepare_noise
(
latent_image
,
seed
,
skip
=
0
):
def
prepare_noise
(
latent_image
,
seed
,
skip
=
0
):
"""
"""
...
@@ -16,10 +16,11 @@ def prepare_noise(latent_image, seed, skip=0):
...
@@ -16,10 +16,11 @@ def prepare_noise(latent_image, seed, skip=0):
def
prepare_mask
(
noise_mask
,
shape
,
device
):
def
prepare_mask
(
noise_mask
,
shape
,
device
):
"""ensures noise mask is of proper dimensions"""
"""ensures noise mask is of proper dimensions"""
noise_mask
=
torch
.
nn
.
functional
.
interpolate
(
noise_mask
[
None
,
None
,]
,
size
=
(
shape
[
2
],
shape
[
3
]),
mode
=
"bilinear"
)
noise_mask
=
torch
.
nn
.
functional
.
interpolate
(
noise_mask
.
reshape
((
-
1
,
1
,
noise_mask
.
shape
[
-
2
],
noise_mask
.
shape
[
-
1
]))
,
size
=
(
shape
[
2
],
shape
[
3
]),
mode
=
"bilinear"
)
noise_mask
=
noise_mask
.
round
()
noise_mask
=
noise_mask
.
round
()
noise_mask
=
torch
.
cat
([
noise_mask
]
*
shape
[
1
],
dim
=
1
)
noise_mask
=
torch
.
cat
([
noise_mask
]
*
shape
[
1
],
dim
=
1
)
noise_mask
=
torch
.
cat
([
noise_mask
]
*
shape
[
0
])
if
noise_mask
.
shape
[
0
]
<
shape
[
0
]:
noise_mask
=
noise_mask
.
repeat
(
math
.
ceil
(
shape
[
0
]
/
noise_mask
.
shape
[
0
]),
1
,
1
,
1
)[:
shape
[
0
]]
noise_mask
=
noise_mask
.
to
(
device
)
noise_mask
=
noise_mask
.
to
(
device
)
return
noise_mask
return
noise_mask
...
...
nodes.py
View file @
aa57136d
...
@@ -172,16 +172,12 @@ class VAEEncodeForInpaint:
...
@@ -172,16 +172,12 @@ class VAEEncodeForInpaint:
def
encode
(
self
,
vae
,
pixels
,
mask
):
def
encode
(
self
,
vae
,
pixels
,
mask
):
x
=
(
pixels
.
shape
[
1
]
//
64
)
*
64
x
=
(
pixels
.
shape
[
1
]
//
64
)
*
64
y
=
(
pixels
.
shape
[
2
]
//
64
)
*
64
y
=
(
pixels
.
shape
[
2
]
//
64
)
*
64
if
len
(
mask
.
shape
)
<
3
:
mask
=
torch
.
nn
.
functional
.
interpolate
(
mask
.
reshape
((
-
1
,
1
,
mask
.
shape
[
-
2
],
mask
.
shape
[
-
1
])),
size
=
(
pixels
.
shape
[
1
],
pixels
.
shape
[
2
]),
mode
=
"bilinear"
)
mask
=
mask
.
unsqueeze
(
0
).
unsqueeze
(
0
)
elif
len
(
mask
.
shape
)
<
4
:
mask
=
mask
.
unsqueeze
(
1
)
mask
=
torch
.
nn
.
functional
.
interpolate
(
mask
,
size
=
(
pixels
.
shape
[
1
],
pixels
.
shape
[
2
]),
mode
=
"bilinear"
)
pixels
=
pixels
.
clone
()
pixels
=
pixels
.
clone
()
if
pixels
.
shape
[
1
]
!=
x
or
pixels
.
shape
[
2
]
!=
y
:
if
pixels
.
shape
[
1
]
!=
x
or
pixels
.
shape
[
2
]
!=
y
:
pixels
=
pixels
[:,:
x
,:
y
,:]
pixels
=
pixels
[:,:
x
,:
y
,:]
mask
=
mask
[:,:
x
,:
y
,:
]
mask
=
mask
[:,:
,:
x
,:
y
]
#grow mask by a few pixels to keep things seamless in latent space
#grow mask by a few pixels to keep things seamless in latent space
kernel_tensor
=
torch
.
ones
((
1
,
1
,
6
,
6
))
kernel_tensor
=
torch
.
ones
((
1
,
1
,
6
,
6
))
...
@@ -193,7 +189,7 @@ class VAEEncodeForInpaint:
...
@@ -193,7 +189,7 @@ class VAEEncodeForInpaint:
pixels
[:,:,:,
i
]
+=
0.5
pixels
[:,:,:,
i
]
+=
0.5
t
=
vae
.
encode
(
pixels
)
t
=
vae
.
encode
(
pixels
)
return
({
"samples"
:
t
,
"noise_mask"
:
(
mask_erosion
[:,:
x
,:
y
,:
].
round
())},
)
return
({
"samples"
:
t
,
"noise_mask"
:
(
mask_erosion
[:,:
,:
x
,:
y
].
round
())},
)
class
CheckpointLoader
:
class
CheckpointLoader
:
@
classmethod
@
classmethod
...
...
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