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
b8ccbec6
"...git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "3296bcee6907926348cbfb34960f671633eef4de"
Commit
b8ccbec6
authored
May 23, 2023
by
comfyanonymous
Browse files
Various improvements to bislerp.
parent
451fb416
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
18 deletions
+25
-18
comfy/utils.py
comfy/utils.py
+25
-18
No files found.
comfy/utils.py
View file @
b8ccbec6
...
@@ -56,35 +56,42 @@ def bislerp(samples, width, height):
...
@@ -56,35 +56,42 @@ def bislerp(samples, width, height):
shape
[
2
]
=
height
shape
[
2
]
=
height
out1
=
torch
.
empty
(
shape
,
dtype
=
samples
.
dtype
,
layout
=
samples
.
layout
,
device
=
samples
.
device
)
out1
=
torch
.
empty
(
shape
,
dtype
=
samples
.
dtype
,
layout
=
samples
.
layout
,
device
=
samples
.
device
)
def
algorithm
(
in1
,
w1
,
in2
,
w2
):
def
algorithm
(
in1
,
in2
,
t
):
dims
=
in1
.
shape
dims
=
in1
.
shape
val
=
w2
val
=
t
#flatten to batches
#flatten to batches
low
=
in1
.
reshape
(
dims
[
0
],
-
1
)
low
=
in1
.
reshape
(
dims
[
0
],
-
1
)
high
=
in2
.
reshape
(
dims
[
0
],
-
1
)
high
=
in2
.
reshape
(
dims
[
0
],
-
1
)
low_norm
=
low
/
torch
.
norm
(
low
,
dim
=
1
,
keepdim
=
True
)
low_weight
=
torch
.
norm
(
low
,
dim
=
1
,
keepdim
=
True
)
high_norm
=
high
/
torch
.
norm
(
high
,
dim
=
1
,
keepdim
=
True
)
low_weight
[
low_weight
==
0
]
=
0.0000000001
low_norm
=
low
/
low_weight
# in case we divide by zero
high_weight
=
torch
.
norm
(
high
,
dim
=
1
,
keepdim
=
True
)
low_norm
[
low_norm
!=
low_norm
]
=
0.0
high_weight
[
high_weight
==
0
]
=
0.0000000001
high_norm
[
high_norm
!=
high_norm
]
=
0.0
high_norm
=
high
/
high_weight
omega
=
torch
.
acos
((
low_norm
*
high_norm
).
sum
(
1
))
dot_prod
=
(
low_norm
*
high_norm
).
sum
(
1
)
dot_prod
[
dot_prod
>
0.9995
]
=
0.9995
dot_prod
[
dot_prod
<
-
0.9995
]
=
-
0.9995
omega
=
torch
.
acos
(
dot_prod
)
so
=
torch
.
sin
(
omega
)
so
=
torch
.
sin
(
omega
)
res
=
(
torch
.
sin
((
1.0
-
val
)
*
omega
)
/
so
).
unsqueeze
(
1
)
*
low
+
(
torch
.
sin
(
val
*
omega
)
/
so
).
unsqueeze
(
1
)
*
high
res
=
(
torch
.
sin
((
1.0
-
val
)
*
omega
)
/
so
).
unsqueeze
(
1
)
*
low_norm
+
(
torch
.
sin
(
val
*
omega
)
/
so
).
unsqueeze
(
1
)
*
high_norm
res
*=
(
low_weight
*
(
1.0
-
val
)
+
high_weight
*
val
)
return
res
.
reshape
(
dims
)
return
res
.
reshape
(
dims
)
for
x_dest
in
range
(
shape
[
3
]):
for
x_dest
in
range
(
shape
[
3
]):
for
y_dest
in
range
(
shape
[
2
]):
for
y_dest
in
range
(
shape
[
2
]):
y
=
(
y_dest
)
*
height_scale
y
=
(
y_dest
+
0.5
)
*
height_scale
-
0.5
x
=
(
x_dest
)
*
width_scale
x
=
(
x_dest
+
0.5
)
*
width_scale
-
0.5
x1
=
max
(
math
.
floor
(
x
),
0
)
x1
=
max
(
math
.
floor
(
x
),
0
)
x2
=
min
(
x1
+
1
,
samples
.
shape
[
3
]
-
1
)
x2
=
min
(
x1
+
1
,
samples
.
shape
[
3
]
-
1
)
wx
=
x
-
math
.
floor
(
x
)
y1
=
max
(
math
.
floor
(
y
),
0
)
y1
=
max
(
math
.
floor
(
y
),
0
)
y2
=
min
(
y1
+
1
,
samples
.
shape
[
2
]
-
1
)
y2
=
min
(
y1
+
1
,
samples
.
shape
[
2
]
-
1
)
wy
=
y
-
math
.
floor
(
y
)
in1
=
samples
[:,:,
y1
,
x1
]
in1
=
samples
[:,:,
y1
,
x1
]
in2
=
samples
[:,:,
y1
,
x2
]
in2
=
samples
[:,:,
y1
,
x2
]
...
@@ -94,13 +101,13 @@ def bislerp(samples, width, height):
...
@@ -94,13 +101,13 @@ def bislerp(samples, width, height):
if
(
x1
==
x2
)
and
(
y1
==
y2
):
if
(
x1
==
x2
)
and
(
y1
==
y2
):
out_value
=
in1
out_value
=
in1
elif
(
x1
==
x2
):
elif
(
x1
==
x2
):
out_value
=
algorithm
(
in1
,
(
y2
-
y
),
in3
,
(
y
-
y1
)
)
out_value
=
algorithm
(
in1
,
in3
,
wy
)
elif
(
y1
==
y2
):
elif
(
y1
==
y2
):
out_value
=
algorithm
(
in1
,
(
x2
-
x
),
in2
,
(
x
-
x1
)
)
out_value
=
algorithm
(
in1
,
in2
,
wx
)
else
:
else
:
o1
=
algorithm
(
in1
,
(
x2
-
x
),
in2
,
(
x
-
x1
)
)
o1
=
algorithm
(
in1
,
in2
,
wx
)
o2
=
algorithm
(
in3
,
(
x2
-
x
),
in4
,
(
x
-
x1
)
)
o2
=
algorithm
(
in3
,
in4
,
wx
)
out_value
=
algorithm
(
o1
,
(
y2
-
y
),
o2
,
(
y
-
y1
)
)
out_value
=
algorithm
(
o1
,
o2
,
wy
)
out1
[:,:,
y_dest
,
x_dest
]
=
out_value
out1
[:,:,
y_dest
,
x_dest
]
=
out_value
return
out1
return
out1
...
...
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