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
c962884a
Commit
c962884a
authored
Nov 14, 2023
by
comfyanonymous
Browse files
Make bislerp work on GPU.
parent
420beeeb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
comfy/utils.py
comfy/utils.py
+5
-5
No files found.
comfy/utils.py
View file @
c962884a
...
@@ -307,13 +307,13 @@ def bislerp(samples, width, height):
...
@@ -307,13 +307,13 @@ def bislerp(samples, width, height):
res
[
dot
<
1e-5
-
1
]
=
(
b1
*
(
1.0
-
r
)
+
b2
*
r
)[
dot
<
1e-5
-
1
]
res
[
dot
<
1e-5
-
1
]
=
(
b1
*
(
1.0
-
r
)
+
b2
*
r
)[
dot
<
1e-5
-
1
]
return
res
return
res
def
generate_bilinear_data
(
length_old
,
length_new
):
def
generate_bilinear_data
(
length_old
,
length_new
,
device
):
coords_1
=
torch
.
arange
(
length_old
).
reshape
((
1
,
1
,
1
,
-
1
))
.
to
(
torch
.
float32
)
coords_1
=
torch
.
arange
(
length_old
,
dtype
=
torch
.
float32
,
device
=
device
).
reshape
((
1
,
1
,
1
,
-
1
))
coords_1
=
torch
.
nn
.
functional
.
interpolate
(
coords_1
,
size
=
(
1
,
length_new
),
mode
=
"bilinear"
)
coords_1
=
torch
.
nn
.
functional
.
interpolate
(
coords_1
,
size
=
(
1
,
length_new
),
mode
=
"bilinear"
)
ratios
=
coords_1
-
coords_1
.
floor
()
ratios
=
coords_1
-
coords_1
.
floor
()
coords_1
=
coords_1
.
to
(
torch
.
int64
)
coords_1
=
coords_1
.
to
(
torch
.
int64
)
coords_2
=
torch
.
arange
(
length_old
).
reshape
((
1
,
1
,
1
,
-
1
))
.
to
(
torch
.
float32
)
+
1
coords_2
=
torch
.
arange
(
length_old
,
dtype
=
torch
.
float32
,
device
=
device
).
reshape
((
1
,
1
,
1
,
-
1
))
+
1
coords_2
[:,:,:,
-
1
]
-=
1
coords_2
[:,:,:,
-
1
]
-=
1
coords_2
=
torch
.
nn
.
functional
.
interpolate
(
coords_2
,
size
=
(
1
,
length_new
),
mode
=
"bilinear"
)
coords_2
=
torch
.
nn
.
functional
.
interpolate
(
coords_2
,
size
=
(
1
,
length_new
),
mode
=
"bilinear"
)
coords_2
=
coords_2
.
to
(
torch
.
int64
)
coords_2
=
coords_2
.
to
(
torch
.
int64
)
...
@@ -323,7 +323,7 @@ def bislerp(samples, width, height):
...
@@ -323,7 +323,7 @@ def bislerp(samples, width, height):
h_new
,
w_new
=
(
height
,
width
)
h_new
,
w_new
=
(
height
,
width
)
#linear w
#linear w
ratios
,
coords_1
,
coords_2
=
generate_bilinear_data
(
w
,
w_new
)
ratios
,
coords_1
,
coords_2
=
generate_bilinear_data
(
w
,
w_new
,
samples
.
device
)
coords_1
=
coords_1
.
expand
((
n
,
c
,
h
,
-
1
))
coords_1
=
coords_1
.
expand
((
n
,
c
,
h
,
-
1
))
coords_2
=
coords_2
.
expand
((
n
,
c
,
h
,
-
1
))
coords_2
=
coords_2
.
expand
((
n
,
c
,
h
,
-
1
))
ratios
=
ratios
.
expand
((
n
,
1
,
h
,
-
1
))
ratios
=
ratios
.
expand
((
n
,
1
,
h
,
-
1
))
...
@@ -336,7 +336,7 @@ def bislerp(samples, width, height):
...
@@ -336,7 +336,7 @@ def bislerp(samples, width, height):
result
=
result
.
reshape
(
n
,
h
,
w_new
,
c
).
movedim
(
-
1
,
1
)
result
=
result
.
reshape
(
n
,
h
,
w_new
,
c
).
movedim
(
-
1
,
1
)
#linear h
#linear h
ratios
,
coords_1
,
coords_2
=
generate_bilinear_data
(
h
,
h_new
)
ratios
,
coords_1
,
coords_2
=
generate_bilinear_data
(
h
,
h_new
,
samples
.
device
)
coords_1
=
coords_1
.
reshape
((
1
,
1
,
-
1
,
1
)).
expand
((
n
,
c
,
-
1
,
w_new
))
coords_1
=
coords_1
.
reshape
((
1
,
1
,
-
1
,
1
)).
expand
((
n
,
c
,
-
1
,
w_new
))
coords_2
=
coords_2
.
reshape
((
1
,
1
,
-
1
,
1
)).
expand
((
n
,
c
,
-
1
,
w_new
))
coords_2
=
coords_2
.
reshape
((
1
,
1
,
-
1
,
1
)).
expand
((
n
,
c
,
-
1
,
w_new
))
ratios
=
ratios
.
reshape
((
1
,
1
,
-
1
,
1
)).
expand
((
n
,
1
,
-
1
,
w_new
))
ratios
=
ratios
.
reshape
((
1
,
1
,
-
1
,
1
)).
expand
((
n
,
1
,
-
1
,
w_new
))
...
...
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