MCPcopy Create free account
hub / github.com/cubiq/ComfyUI_InstantID / InstantIDModelLoader

Class InstantIDModelLoader

InstantID.py:138–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136 to["patches_replace"]["attn2"][key].add(instantid_attention, **patch_kwargs)
137
138class InstantIDModelLoader:
139 @classmethod
140 def INPUT_TYPES(s):
141 return {"required": { "instantid_file": (folder_paths.get_filename_list("instantid"), )}}
142
143 RETURN_TYPES = ("INSTANTID",)
144 FUNCTION = "load_model"
145 CATEGORY = "InstantID"
146
147 def load_model(self, instantid_file):
148 ckpt_path = folder_paths.get_full_path("instantid", instantid_file)
149
150 model = comfy.utils.load_torch_file(ckpt_path, safe_load=True)
151
152 if ckpt_path.lower().endswith(".safetensors"):
153 st_model = {"image_proj": {}, "ip_adapter": {}}
154 for key in model.keys():
155 if key.startswith("image_proj."):
156 st_model["image_proj"][key.replace("image_proj.", "")] = model[key]
157 elif key.startswith("ip_adapter."):
158 st_model["ip_adapter"][key.replace("ip_adapter.", "")] = model[key]
159 model = st_model
160
161 model = InstantID(
162 model,
163 cross_attention_dim=1280,
164 output_cross_attention_dim=model["ip_adapter"]["1.to_k_ip.weight"].shape[1],
165 clip_embeddings_dim=512,
166 clip_extra_context_tokens=16,
167 )
168
169 return (model,)
170
171def extractFeatures(insightface, image, extract_kps=False):
172 face_img = tensor_to_image(image)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected