primerz commited on
Commit
8a37e2d
·
verified ·
1 Parent(s): 5740014

Update generator.py

Browse files
Files changed (1) hide show
  1. generator.py +5 -9
generator.py CHANGED
@@ -810,7 +810,7 @@ class RetroArtConverter:
810
  # 1. InstantID (Identity)
811
  if self.instantid_active:
812
  if has_detected_faces and face_kps_image is not None:
813
- # ... (code to append control_images is unchanged) ...
814
  face_kps_image = ensure_correct_size(face_kps_image, target_width, target_height, "InstantID")
815
  control_images.append(face_kps_image)
816
  conditioning_scales.append(identity_control_scale)
@@ -830,16 +830,12 @@ class RetroArtConverter:
830
 
831
  print(f" - Face embedding: {face_proj_embeds.shape}, Scale: {boosted_scale:.2f}")
832
 
833
- # --- START FIX 2: Your padding solution ---
834
  if 'prompt_embeds' in pipe_kwargs:
835
  original_embeds = pipe_kwargs['prompt_embeds']
836
 
837
- # Handle CFG by creating a [2, 16, 2048] tensor
838
- # [0] is zeros for negative, [1] is face embeds for positive
839
- face_proj_embeds_cfg = torch.cat([torch.zeros_like(face_proj_embeds), face_proj_embeds], dim=0)
840
-
841
  # Concatenate face embeddings to POSITIVE prompt
842
- combined_embeds = torch.cat([original_embeds, face_proj_embeds_cfg[1:2]], dim=1) # [1, 93, 2048] -> [1, 109, 2048]
843
  pipe_kwargs['prompt_embeds'] = combined_embeds
844
 
845
  # CRITICAL: Pad negative_prompt_embeds by the same amount
@@ -862,13 +858,13 @@ class RetroArtConverter:
862
  print(f" [OK] Face embeddings concatenated successfully! Prompt: {combined_embeds.shape}")
863
  else:
864
  print(f" [WARNING] Can't concatenate - no prompt_embeds (use Compel)")
865
- # --- END FIX 2 ---
866
 
867
  elif has_detected_faces:
868
  print(" Face detected but IP-Adapter/embeddings unavailable, using keypoints only")
869
 
870
  else:
871
- # ... (code for no face detected is unchanged) ...
872
  print("[INSTANTID] Using blank map (scale=0, no effect on generation)")
873
  control_images.append(Image.new("RGB", (target_width, target_height), (0,0,0)))
874
  conditioning_scales.append(0.0) # Set scale to 0
 
810
  # 1. InstantID (Identity)
811
  if self.instantid_active:
812
  if has_detected_faces and face_kps_image is not None:
813
+ # Ensure face keypoints image has correct size
814
  face_kps_image = ensure_correct_size(face_kps_image, target_width, target_height, "InstantID")
815
  control_images.append(face_kps_image)
816
  conditioning_scales.append(identity_control_scale)
 
830
 
831
  print(f" - Face embedding: {face_proj_embeds.shape}, Scale: {boosted_scale:.2f}")
832
 
833
+ # --- START FIX: Your padding solution ---
834
  if 'prompt_embeds' in pipe_kwargs:
835
  original_embeds = pipe_kwargs['prompt_embeds']
836
 
 
 
 
 
837
  # Concatenate face embeddings to POSITIVE prompt
838
+ combined_embeds = torch.cat([original_embeds, face_proj_embeds], dim=1)
839
  pipe_kwargs['prompt_embeds'] = combined_embeds
840
 
841
  # CRITICAL: Pad negative_prompt_embeds by the same amount
 
858
  print(f" [OK] Face embeddings concatenated successfully! Prompt: {combined_embeds.shape}")
859
  else:
860
  print(f" [WARNING] Can't concatenate - no prompt_embeds (use Compel)")
861
+ # --- END FIX ---
862
 
863
  elif has_detected_faces:
864
  print(" Face detected but IP-Adapter/embeddings unavailable, using keypoints only")
865
 
866
  else:
867
+ # No face detected - blank map needed to maintain ControlNet list order
868
  print("[INSTANTID] Using blank map (scale=0, no effect on generation)")
869
  control_images.append(Image.new("RGB", (target_width, target_height), (0,0,0)))
870
  conditioning_scales.append(0.0) # Set scale to 0