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
2e73367f
Commit
2e73367f
authored
Mar 17, 2023
by
comfyanonymous
Browse files
Merge T2IAdapterLoader and ControlNetLoader.
Workflows will be auto updated.
parent
e1a9e269
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
14 additions
and
44 deletions
+14
-44
comfy/sd.py
comfy/sd.py
+8
-5
comfy_extras/nodes_upscale_model.py
comfy_extras/nodes_upscale_model.py
+0
-1
models/controlnet/put_controlnets_and_t2i_here
models/controlnet/put_controlnets_and_t2i_here
+0
-0
models/t2i_adapter/put_t2i_adapter_models_here
models/t2i_adapter/put_t2i_adapter_models_here
+0
-0
nodes.py
nodes.py
+0
-38
web/scripts/app.js
web/scripts/app.js
+6
-0
No files found.
comfy/sd.py
View file @
2e73367f
...
@@ -527,8 +527,10 @@ def load_controlnet(ckpt_path, model=None):
...
@@ -527,8 +527,10 @@ def load_controlnet(ckpt_path, model=None):
elif
key
in
controlnet_data
:
elif
key
in
controlnet_data
:
pass
pass
else
:
else
:
print
(
"error checkpoint does not contain controlnet data"
,
ckpt_path
)
net
=
load_t2i_adapter
(
controlnet_data
)
return
None
if
net
is
None
:
print
(
"error checkpoint does not contain controlnet or t2i adapter data"
,
ckpt_path
)
return
net
context_dim
=
controlnet_data
[
key
].
shape
[
1
]
context_dim
=
controlnet_data
[
key
].
shape
[
1
]
...
@@ -682,15 +684,16 @@ class T2IAdapter:
...
@@ -682,15 +684,16 @@ class T2IAdapter:
out
+=
self
.
previous_controlnet
.
get_control_models
()
out
+=
self
.
previous_controlnet
.
get_control_models
()
return
out
return
out
def
load_t2i_adapter
(
ckpt_path
,
model
=
None
):
def
load_t2i_adapter
(
t2i_data
):
t2i_data
=
load_torch_file
(
ckpt_path
)
keys
=
t2i_data
.
keys
()
keys
=
t2i_data
.
keys
()
if
"body.0.in_conv.weight"
in
keys
:
if
"body.0.in_conv.weight"
in
keys
:
cin
=
t2i_data
[
'body.0.in_conv.weight'
].
shape
[
1
]
cin
=
t2i_data
[
'body.0.in_conv.weight'
].
shape
[
1
]
model_ad
=
adapter
.
Adapter_light
(
cin
=
cin
,
channels
=
[
320
,
640
,
1280
,
1280
],
nums_rb
=
4
)
model_ad
=
adapter
.
Adapter_light
(
cin
=
cin
,
channels
=
[
320
,
640
,
1280
,
1280
],
nums_rb
=
4
)
els
e
:
el
if
'conv_in.weight'
in
key
s
:
cin
=
t2i_data
[
'conv_in.weight'
].
shape
[
1
]
cin
=
t2i_data
[
'conv_in.weight'
].
shape
[
1
]
model_ad
=
adapter
.
Adapter
(
cin
=
cin
,
channels
=
[
320
,
640
,
1280
,
1280
][:
4
],
nums_rb
=
2
,
ksize
=
1
,
sk
=
True
,
use_conv
=
False
)
model_ad
=
adapter
.
Adapter
(
cin
=
cin
,
channels
=
[
320
,
640
,
1280
,
1280
][:
4
],
nums_rb
=
2
,
ksize
=
1
,
sk
=
True
,
use_conv
=
False
)
else
:
return
None
model_ad
.
load_state_dict
(
t2i_data
)
model_ad
.
load_state_dict
(
t2i_data
)
return
T2IAdapter
(
model_ad
,
cin
//
64
)
return
T2IAdapter
(
model_ad
,
cin
//
64
)
...
...
comfy_extras/nodes_upscale_model.py
View file @
2e73367f
...
@@ -2,7 +2,6 @@ import os
...
@@ -2,7 +2,6 @@ import os
from
comfy_extras.chainner_models
import
model_loading
from
comfy_extras.chainner_models
import
model_loading
from
comfy.sd
import
load_torch_file
from
comfy.sd
import
load_torch_file
import
model_management
import
model_management
from
nodes
import
filter_files_extensions
,
recursive_search
,
supported_ckpt_extensions
import
torch
import
torch
import
comfy.utils
import
comfy.utils
import
folder_paths
import
folder_paths
...
...
models/controlnet/put_controlnets_here
→
models/controlnet/put_controlnets_
and_t2i_
here
View file @
2e73367f
File moved
models/t2i_adapter/put_t2i_adapter_models_here
deleted
100644 → 0
View file @
e1a9e269
nodes.py
View file @
2e73367f
...
@@ -24,26 +24,6 @@ import model_management
...
@@ -24,26 +24,6 @@ import model_management
import
importlib
import
importlib
import
folder_paths
import
folder_paths
supported_ckpt_extensions
=
[
'.ckpt'
,
'.pth'
]
supported_pt_extensions
=
[
'.ckpt'
,
'.pt'
,
'.bin'
,
'.pth'
]
try
:
import
safetensors.torch
supported_ckpt_extensions
+=
[
'.safetensors'
]
supported_pt_extensions
+=
[
'.safetensors'
]
except
:
print
(
"Could not import safetensors, safetensors support disabled."
)
def
recursive_search
(
directory
):
result
=
[]
for
root
,
subdir
,
file
in
os
.
walk
(
directory
,
followlinks
=
True
):
for
filepath
in
file
:
#we os.path,join directory with a blank string to generate a path separator at the end.
result
.
append
(
os
.
path
.
join
(
root
,
filepath
).
replace
(
os
.
path
.
join
(
directory
,
''
),
''
))
return
result
def
filter_files_extensions
(
files
,
extensions
):
return
sorted
(
list
(
filter
(
lambda
a
:
os
.
path
.
splitext
(
a
)[
-
1
].
lower
()
in
extensions
,
files
)))
def
before_node_execution
():
def
before_node_execution
():
model_management
.
throw_exception_if_processing_interrupted
()
model_management
.
throw_exception_if_processing_interrupted
()
...
@@ -348,23 +328,6 @@ class ControlNetApply:
...
@@ -348,23 +328,6 @@ class ControlNetApply:
c
.
append
(
n
)
c
.
append
(
n
)
return
(
c
,
)
return
(
c
,
)
class
T2IAdapterLoader
:
models_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"models"
)
t2i_adapter_dir
=
os
.
path
.
join
(
models_dir
,
"t2i_adapter"
)
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"t2i_adapter_name"
:
(
filter_files_extensions
(
recursive_search
(
s
.
t2i_adapter_dir
),
supported_pt_extensions
),
)}}
RETURN_TYPES
=
(
"CONTROL_NET"
,)
FUNCTION
=
"load_t2i_adapter"
CATEGORY
=
"loaders"
def
load_t2i_adapter
(
self
,
t2i_adapter_name
):
t2i_path
=
os
.
path
.
join
(
self
.
t2i_adapter_dir
,
t2i_adapter_name
)
t2i_adapter
=
comfy
.
sd
.
load_t2i_adapter
(
t2i_path
)
return
(
t2i_adapter
,)
class
CLIPLoader
:
class
CLIPLoader
:
@
classmethod
@
classmethod
def
INPUT_TYPES
(
s
):
def
INPUT_TYPES
(
s
):
...
@@ -963,7 +926,6 @@ NODE_CLASS_MAPPINGS = {
...
@@ -963,7 +926,6 @@ NODE_CLASS_MAPPINGS = {
"ControlNetApply"
:
ControlNetApply
,
"ControlNetApply"
:
ControlNetApply
,
"ControlNetLoader"
:
ControlNetLoader
,
"ControlNetLoader"
:
ControlNetLoader
,
"DiffControlNetLoader"
:
DiffControlNetLoader
,
"DiffControlNetLoader"
:
DiffControlNetLoader
,
"T2IAdapterLoader"
:
T2IAdapterLoader
,
"StyleModelLoader"
:
StyleModelLoader
,
"StyleModelLoader"
:
StyleModelLoader
,
"CLIPVisionLoader"
:
CLIPVisionLoader
,
"CLIPVisionLoader"
:
CLIPVisionLoader
,
"VAEDecodeTiled"
:
VAEDecodeTiled
,
"VAEDecodeTiled"
:
VAEDecodeTiled
,
...
...
web/scripts/app.js
View file @
2e73367f
...
@@ -614,6 +614,12 @@ class ComfyApp {
...
@@ -614,6 +614,12 @@ class ComfyApp {
if
(
!
graphData
)
{
if
(
!
graphData
)
{
graphData
=
defaultGraph
;
graphData
=
defaultGraph
;
}
}
// Patch T2IAdapterLoader to ControlNetLoader since they are the same node now
for
(
let
n
of
graphData
.
nodes
)
{
if
(
n
.
type
==
"
T2IAdapterLoader
"
)
n
.
type
=
"
ControlNetLoader
"
;
}
this
.
graph
.
configure
(
graphData
);
this
.
graph
.
configure
(
graphData
);
for
(
const
node
of
this
.
graph
.
_nodes
)
{
for
(
const
node
of
this
.
graph
.
_nodes
)
{
...
...
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