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

Class ApplyInstantIDControlNet

InstantID.py:518–588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

516 return(work_model, { "cond": image_prompt_embeds, "uncond": uncond_image_prompt_embeds }, )
517
518class ApplyInstantIDControlNet:
519 @classmethod
520 def INPUT_TYPES(s):
521 return {
522 "required": {
523 "face_embeds": ("FACE_EMBEDS", ),
524 "control_net": ("CONTROL_NET", ),
525 "image_kps": ("IMAGE", ),
526 "positive": ("CONDITIONING", ),
527 "negative": ("CONDITIONING", ),
528 "strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01, }),
529 "start_at": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.001, }),
530 "end_at": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.001, }),
531 },
532 "optional": {
533 "mask": ("MASK",),
534 }
535 }
536
537 RETURN_TYPES = ("CONDITIONING", "CONDITIONING",)
538 RETURN_NAMES = ("positive", "negative", )
539 FUNCTION = "apply_controlnet"
540 CATEGORY = "InstantID"
541
542 def apply_controlnet(self, face_embeds, control_net, image_kps, positive, negative, strength, start_at, end_at, mask=None):
543 self.device = comfy.model_management.get_torch_device()
544
545 if strength == 0:
546 return (positive, negative)
547
548 if mask is not None:
549 mask = mask.to(self.device)
550
551 if mask is not None and len(mask.shape) < 3:
552 mask = mask.unsqueeze(0)
553
554 image_prompt_embeds = face_embeds['cond']
555 uncond_image_prompt_embeds = face_embeds['uncond']
556
557 cnets = {}
558 cond_uncond = []
559 control_hint = image_kps.movedim(-1,1)
560
561 is_cond = True
562 for conditioning in [positive, negative]:
563 c = []
564 for t in conditioning:
565 d = t[1].copy()
566
567 prev_cnet = d.get('control', None)
568 if prev_cnet in cnets:
569 c_net = cnets[prev_cnet]
570 else:
571 c_net = control_net.copy().set_cond_hint(control_hint, strength, (start_at, end_at))
572 c_net.set_previous_controlnet(prev_cnet)
573 cnets[prev_cnet] = c_net
574
575 d['control'] = c_net

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected