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
2b1fce29
Commit
2b1fce29
authored
Mar 11, 2023
by
comfyanonymous
Browse files
Make tiled_scale work for downscaling.
parent
9db2e97b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
comfy/utils.py
comfy/utils.py
+7
-7
No files found.
comfy/utils.py
View file @
2b1fce29
...
...
@@ -18,26 +18,26 @@ def common_upscale(samples, width, height, upscale_method, crop):
return
torch
.
nn
.
functional
.
interpolate
(
s
,
size
=
(
height
,
width
),
mode
=
upscale_method
)
@
torch
.
inference_mode
()
def
tiled_scale
(
samples
,
function
,
tile_x
=
64
,
tile_y
=
64
,
overlap
=
8
,
upscale_amount
=
4
):
output
=
torch
.
empty
((
samples
.
shape
[
0
],
3
,
samples
.
shape
[
2
]
*
upscale_amount
,
samples
.
shape
[
3
]
*
upscale_amount
),
device
=
"cpu"
)
def
tiled_scale
(
samples
,
function
,
tile_x
=
64
,
tile_y
=
64
,
overlap
=
8
,
upscale_amount
=
4
,
out_channels
=
3
):
output
=
torch
.
empty
((
samples
.
shape
[
0
],
out_channels
,
round
(
samples
.
shape
[
2
]
*
upscale_amount
)
,
round
(
samples
.
shape
[
3
]
*
upscale_amount
)
)
,
device
=
"cpu"
)
for
b
in
range
(
samples
.
shape
[
0
]):
s
=
samples
[
b
:
b
+
1
]
out
=
torch
.
zeros
((
s
.
shape
[
0
],
3
,
s
.
shape
[
2
]
*
upscale_amount
,
s
.
shape
[
3
]
*
upscale_amount
),
device
=
"cpu"
)
out_div
=
torch
.
zeros
((
s
.
shape
[
0
],
3
,
s
.
shape
[
2
]
*
upscale_amount
,
s
.
shape
[
3
]
*
upscale_amount
),
device
=
"cpu"
)
out
=
torch
.
zeros
((
s
.
shape
[
0
],
out_channels
,
round
(
s
.
shape
[
2
]
*
upscale_amount
)
,
round
(
s
.
shape
[
3
]
*
upscale_amount
)
)
,
device
=
"cpu"
)
out_div
=
torch
.
zeros
((
s
.
shape
[
0
],
out_channels
,
round
(
s
.
shape
[
2
]
*
upscale_amount
)
,
round
(
s
.
shape
[
3
]
*
upscale_amount
)
)
,
device
=
"cpu"
)
for
y
in
range
(
0
,
s
.
shape
[
2
],
tile_y
-
overlap
):
for
x
in
range
(
0
,
s
.
shape
[
3
],
tile_x
-
overlap
):
s_in
=
s
[:,:,
y
:
y
+
tile_y
,
x
:
x
+
tile_x
]
ps
=
function
(
s_in
).
cpu
()
mask
=
torch
.
ones_like
(
ps
)
feather
=
overlap
*
upscale_amount
feather
=
round
(
overlap
*
upscale_amount
)
for
t
in
range
(
feather
):
mask
[:,:,
t
:
1
+
t
,:]
*=
((
1.0
/
feather
)
*
(
t
+
1
))
mask
[:,:,
mask
.
shape
[
2
]
-
1
-
t
:
mask
.
shape
[
2
]
-
t
,:]
*=
((
1.0
/
feather
)
*
(
t
+
1
))
mask
[:,:,:,
t
:
1
+
t
]
*=
((
1.0
/
feather
)
*
(
t
+
1
))
mask
[:,:,:,
mask
.
shape
[
3
]
-
1
-
t
:
mask
.
shape
[
3
]
-
t
]
*=
((
1.0
/
feather
)
*
(
t
+
1
))
out
[:,:,
y
*
upscale_amount
:
(
y
+
tile_y
)
*
upscale_amount
,
x
*
upscale_amount
:
(
x
+
tile_x
)
*
upscale_amount
]
+=
ps
*
mask
out_div
[:,:,
y
*
upscale_amount
:
(
y
+
tile_y
)
*
upscale_amount
,
x
*
upscale_amount
:
(
x
+
tile_x
)
*
upscale_amount
]
+=
mask
out
[:,:,
round
(
y
*
upscale_amount
):
round
(
(
y
+
tile_y
)
*
upscale_amount
),
round
(
x
*
upscale_amount
):
round
(
(
x
+
tile_x
)
*
upscale_amount
)
]
+=
ps
*
mask
out_div
[:,:,
round
(
y
*
upscale_amount
):
round
(
(
y
+
tile_y
)
*
upscale_amount
),
round
(
x
*
upscale_amount
):
round
(
(
x
+
tile_x
)
*
upscale_amount
)
]
+=
mask
output
[
b
:
b
+
1
]
=
out
/
out_div
return
output
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