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
6135a21e
"git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "85d7d50ebe2b0e41b49f020c55999898dafaed17"
Commit
6135a21e
authored
Feb 16, 2023
by
comfyanonymous
Browse files
Add a way to control controlnet strength.
parent
56498d50
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
4 deletions
+13
-4
comfy/sd.py
comfy/sd.py
+6
-1
nodes.py
nodes.py
+7
-3
No files found.
comfy/sd.py
View file @
6135a21e
...
@@ -331,6 +331,7 @@ class ControlNet:
...
@@ -331,6 +331,7 @@ class ControlNet:
self
.
control_model
=
control_model
self
.
control_model
=
control_model
self
.
cond_hint_original
=
None
self
.
cond_hint_original
=
None
self
.
cond_hint
=
None
self
.
cond_hint
=
None
self
.
strength
=
1.0
def
get_control
(
self
,
x_noisy
,
t
,
cond_txt
):
def
get_control
(
self
,
x_noisy
,
t
,
cond_txt
):
if
self
.
cond_hint
is
None
or
x_noisy
.
shape
[
2
]
*
8
!=
self
.
cond_hint
.
shape
[
2
]
or
x_noisy
.
shape
[
3
]
*
8
!=
self
.
cond_hint
.
shape
[
3
]:
if
self
.
cond_hint
is
None
or
x_noisy
.
shape
[
2
]
*
8
!=
self
.
cond_hint
.
shape
[
2
]
or
x_noisy
.
shape
[
3
]
*
8
!=
self
.
cond_hint
.
shape
[
3
]:
...
@@ -340,10 +341,13 @@ class ControlNet:
...
@@ -340,10 +341,13 @@ class ControlNet:
self
.
cond_hint
=
utils
.
common_upscale
(
self
.
cond_hint_original
,
x_noisy
.
shape
[
3
]
*
8
,
x_noisy
.
shape
[
2
]
*
8
,
'nearest-exact'
,
"center"
).
to
(
x_noisy
.
device
)
self
.
cond_hint
=
utils
.
common_upscale
(
self
.
cond_hint_original
,
x_noisy
.
shape
[
3
]
*
8
,
x_noisy
.
shape
[
2
]
*
8
,
'nearest-exact'
,
"center"
).
to
(
x_noisy
.
device
)
print
(
"set cond_hint"
,
self
.
cond_hint
.
shape
)
print
(
"set cond_hint"
,
self
.
cond_hint
.
shape
)
control
=
self
.
control_model
(
x
=
x_noisy
,
hint
=
self
.
cond_hint
,
timesteps
=
t
,
context
=
cond_txt
)
control
=
self
.
control_model
(
x
=
x_noisy
,
hint
=
self
.
cond_hint
,
timesteps
=
t
,
context
=
cond_txt
)
for
x
in
control
:
x
*=
self
.
strength
return
control
return
control
def
set_cond_hint
(
self
,
cond_hint
):
def
set_cond_hint
(
self
,
cond_hint
,
strength
=
1.0
):
self
.
cond_hint_original
=
cond_hint
self
.
cond_hint_original
=
cond_hint
self
.
strength
=
strength
return
self
return
self
def
cleanup
(
self
):
def
cleanup
(
self
):
...
@@ -354,6 +358,7 @@ class ControlNet:
...
@@ -354,6 +358,7 @@ class ControlNet:
def
copy
(
self
):
def
copy
(
self
):
c
=
ControlNet
(
self
.
control_model
)
c
=
ControlNet
(
self
.
control_model
)
c
.
cond_hint_original
=
self
.
cond_hint_original
c
.
cond_hint_original
=
self
.
cond_hint_original
c
.
strength
=
self
.
strength
return
c
return
c
def
load_controlnet
(
ckpt_path
):
def
load_controlnet
(
ckpt_path
):
...
...
nodes.py
View file @
6135a21e
...
@@ -234,19 +234,23 @@ class ControlNetLoader:
...
@@ -234,19 +234,23 @@ class ControlNetLoader:
class
ControlNetApply
:
class
ControlNetApply
:
@
classmethod
@
classmethod
def
INPUT_TYPES
(
s
):
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"conditioning"
:
(
"CONDITIONING"
,
),
"control_net"
:
(
"CONTROL_NET"
,
),
"image"
:
(
"IMAGE"
,
)}}
return
{
"required"
:
{
"conditioning"
:
(
"CONDITIONING"
,
),
"control_net"
:
(
"CONTROL_NET"
,
),
"image"
:
(
"IMAGE"
,
),
"strength"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0.0
,
"max"
:
10.0
,
"step"
:
0.01
})
}}
RETURN_TYPES
=
(
"CONDITIONING"
,)
RETURN_TYPES
=
(
"CONDITIONING"
,)
FUNCTION
=
"apply_controlnet"
FUNCTION
=
"apply_controlnet"
CATEGORY
=
"conditioning"
CATEGORY
=
"conditioning"
def
apply_controlnet
(
self
,
conditioning
,
control_net
,
image
):
def
apply_controlnet
(
self
,
conditioning
,
control_net
,
image
,
strength
):
c
=
[]
c
=
[]
control_hint
=
image
.
movedim
(
-
1
,
1
)
control_hint
=
image
.
movedim
(
-
1
,
1
)
print
(
control_hint
.
shape
)
print
(
control_hint
.
shape
)
for
t
in
conditioning
:
for
t
in
conditioning
:
n
=
[
t
[
0
],
t
[
1
].
copy
()]
n
=
[
t
[
0
],
t
[
1
].
copy
()]
n
[
1
][
'control'
]
=
control_net
.
copy
().
set_cond_hint
(
control_hint
)
n
[
1
][
'control'
]
=
control_net
.
copy
().
set_cond_hint
(
control_hint
,
strength
)
c
.
append
(
n
)
c
.
append
(
n
)
return
(
c
,
)
return
(
c
,
)
...
...
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