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
463d0d08
Commit
463d0d08
authored
Jan 24, 2023
by
comfyanonymous
Browse files
Add a center crop option to latent upscale node.
parent
c1eac7ba
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
nodes.py
nodes.py
+19
-3
No files found.
nodes.py
View file @
463d0d08
...
@@ -115,17 +115,33 @@ class EmptyLatentImage:
...
@@ -115,17 +115,33 @@ class EmptyLatentImage:
class
LatentUpscale
:
class
LatentUpscale
:
upscale_methods
=
[
"nearest-exact"
,
"bilinear"
,
"area"
]
upscale_methods
=
[
"nearest-exact"
,
"bilinear"
,
"area"
]
crop_methods
=
[
"disabled"
,
"center"
]
@
classmethod
@
classmethod
def
INPUT_TYPES
(
s
):
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"samples"
:
(
"LATENT"
,),
"upscale_method"
:
(
s
.
upscale_methods
,),
return
{
"required"
:
{
"samples"
:
(
"LATENT"
,),
"upscale_method"
:
(
s
.
upscale_methods
,),
"width"
:
(
"INT"
,
{
"default"
:
512
,
"min"
:
64
,
"max"
:
4096
,
"step"
:
64
}),
"width"
:
(
"INT"
,
{
"default"
:
512
,
"min"
:
64
,
"max"
:
4096
,
"step"
:
64
}),
"height"
:
(
"INT"
,
{
"default"
:
512
,
"min"
:
64
,
"max"
:
4096
,
"step"
:
64
}),}}
"height"
:
(
"INT"
,
{
"default"
:
512
,
"min"
:
64
,
"max"
:
4096
,
"step"
:
64
}),
"crop"
:
(
s
.
crop_methods
,)}}
RETURN_TYPES
=
(
"LATENT"
,)
RETURN_TYPES
=
(
"LATENT"
,)
FUNCTION
=
"upscale"
FUNCTION
=
"upscale"
def
upscale
(
self
,
samples
,
upscale_method
,
width
,
height
):
def
upscale
(
self
,
samples
,
upscale_method
,
width
,
height
,
crop
):
s
=
torch
.
nn
.
functional
.
interpolate
(
samples
,
size
=
(
height
//
8
,
width
//
8
),
mode
=
upscale_method
)
if
crop
==
"center"
:
old_width
=
samples
.
shape
[
3
]
old_height
=
samples
.
shape
[
2
]
old_aspect
=
old_width
/
old_height
new_aspect
=
width
/
height
x
=
0
y
=
0
if
old_aspect
>
new_aspect
:
x
=
round
((
old_width
-
old_width
*
(
new_aspect
/
old_aspect
))
/
2
)
elif
old_aspect
<
new_aspect
:
y
=
round
((
old_height
-
old_height
*
(
old_aspect
/
new_aspect
))
/
2
)
s
=
samples
[:,:,
y
:
old_height
-
y
,
x
:
old_width
-
x
]
else
:
s
=
samples
s
=
torch
.
nn
.
functional
.
interpolate
(
s
,
size
=
(
height
//
8
,
width
//
8
),
mode
=
upscale_method
)
return
(
s
,)
return
(
s
,)
class
KSampler
:
class
KSampler
:
...
...
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