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
e33dc2b3
Commit
e33dc2b3
authored
Mar 11, 2023
by
comfyanonymous
Browse files
Add a VAEEncodeTiled node.
parent
1de86851
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
comfy/sd.py
comfy/sd.py
+8
-0
nodes.py
nodes.py
+22
-0
No files found.
comfy/sd.py
View file @
e33dc2b3
...
...
@@ -400,6 +400,14 @@ class VAE:
samples
=
samples
.
cpu
()
return
samples
def
encode_tiled
(
self
,
pixel_samples
,
tile_x
=
512
,
tile_y
=
512
,
overlap
=
64
):
model_management
.
unload_model
()
self
.
first_stage_model
=
self
.
first_stage_model
.
to
(
self
.
device
)
pixel_samples
=
pixel_samples
.
movedim
(
-
1
,
1
).
to
(
self
.
device
)
samples
=
utils
.
tiled_scale
(
pixel_samples
,
lambda
a
:
self
.
first_stage_model
.
encode
(
2.
*
a
-
1.
).
sample
()
*
self
.
scale_factor
,
tile_x
,
tile_y
,
overlap
,
upscale_amount
=
(
1
/
8
),
out_channels
=
4
)
self
.
first_stage_model
=
self
.
first_stage_model
.
cpu
()
samples
=
samples
.
cpu
()
return
samples
def
resize_image_to
(
tensor
,
target_latent_tensor
,
batched_number
):
tensor
=
utils
.
common_upscale
(
tensor
,
target_latent_tensor
.
shape
[
3
]
*
8
,
target_latent_tensor
.
shape
[
2
]
*
8
,
'nearest-exact'
,
"center"
)
...
...
nodes.py
View file @
e33dc2b3
...
...
@@ -151,6 +151,27 @@ class VAEEncode:
return
({
"samples"
:
t
},
)
class
VAEEncodeTiled
:
def
__init__
(
self
,
device
=
"cpu"
):
self
.
device
=
device
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"pixels"
:
(
"IMAGE"
,
),
"vae"
:
(
"VAE"
,
)}}
RETURN_TYPES
=
(
"LATENT"
,)
FUNCTION
=
"encode"
CATEGORY
=
"_for_testing"
def
encode
(
self
,
vae
,
pixels
):
x
=
(
pixels
.
shape
[
1
]
//
64
)
*
64
y
=
(
pixels
.
shape
[
2
]
//
64
)
*
64
if
pixels
.
shape
[
1
]
!=
x
or
pixels
.
shape
[
2
]
!=
y
:
pixels
=
pixels
[:,:
x
,:
y
,:]
t
=
vae
.
encode_tiled
(
pixels
[:,:,:,:
3
])
return
({
"samples"
:
t
},
)
class
VAEEncodeForInpaint
:
def
__init__
(
self
,
device
=
"cpu"
):
self
.
device
=
device
...
...
@@ -946,6 +967,7 @@ NODE_CLASS_MAPPINGS = {
"StyleModelLoader"
:
StyleModelLoader
,
"CLIPVisionLoader"
:
CLIPVisionLoader
,
"VAEDecodeTiled"
:
VAEDecodeTiled
,
"VAEEncodeTiled"
:
VAEEncodeTiled
,
}
def
load_custom_node
(
module_path
):
...
...
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