primerz commited on
Commit
f3238f2
·
verified ·
1 Parent(s): 3620e60

Update generator.py

Browse files
Files changed (1) hide show
  1. generator.py +10 -6
generator.py CHANGED
@@ -69,16 +69,19 @@ class Generator:
69
  if face_info is not None:
70
  print("Face detected: Applying InstantID with keypoints.")
71
 
72
- # --- MODIFIED: Explicitly cast tensor to Config.DTYPE ---
 
 
73
  face_emb = torch.tensor(
74
- face_info.normed_embedding,
75
- dtype=Config.DTYPE, # <-- This is the fix
76
  device=Config.DEVICE
77
  ).unsqueeze(0)
78
- # --- END MODIFIED ---
79
 
80
  # Create keypoint image
81
  face_kps = draw_kps(processed_image, face_info['kps'])
 
82
 
83
  # Set strengths (using 0.8 from file's example)
84
  controlnet_conditioning_scale = [0.8, depth_strength, lineart_strength]
@@ -89,13 +92,14 @@ class Generator:
89
  face_emb = torch.zeros((1, 512), dtype=Config.DTYPE, device=Config.DEVICE)
90
  # Create dummy keypoint image (black)
91
  face_kps = Image.new('RGB', (target_width, target_height), (0, 0, 0))
 
92
 
93
  # Set strengths
94
  controlnet_conditioning_scale = [0.0, depth_strength, lineart_strength]
95
  self.mh.pipeline.set_ip_adapter_scale(0.0)
96
 
97
  # We keep the guidance_end for pose low
98
- control_guidance_end = [0.3, 0.6, 0.6]
99
 
100
  # --- Seed/Generator Logic ---
101
  if seed == -1 or seed is None:
@@ -123,7 +127,7 @@ class Generator:
123
  controlnet_conditioning_scale=controlnet_conditioning_scale,
124
  control_guidance_end=control_guidance_end,
125
 
126
- clip_skip=2,
127
 
128
  ).images[0]
129
 
 
69
  if face_info is not None:
70
  print("Face detected: Applying InstantID with keypoints.")
71
 
72
+ # --- FIX APPLIED HERE ---
73
+ # We use face_info['embedding'] (raw) instead of normed_embedding.
74
+ # Raw embedding has higher magnitude (~20-30) required for the adapter.
75
  face_emb = torch.tensor(
76
+ face_info['embedding'],
77
+ dtype=Config.DTYPE,
78
  device=Config.DEVICE
79
  ).unsqueeze(0)
80
+ # --- END FIX ---
81
 
82
  # Create keypoint image
83
  face_kps = draw_kps(processed_image, face_info['kps'])
84
+ face_kps_guidance_end = 0.3
85
 
86
  # Set strengths (using 0.8 from file's example)
87
  controlnet_conditioning_scale = [0.8, depth_strength, lineart_strength]
 
92
  face_emb = torch.zeros((1, 512), dtype=Config.DTYPE, device=Config.DEVICE)
93
  # Create dummy keypoint image (black)
94
  face_kps = Image.new('RGB', (target_width, target_height), (0, 0, 0))
95
+ face_kps_guidance_end = 0.0
96
 
97
  # Set strengths
98
  controlnet_conditioning_scale = [0.0, depth_strength, lineart_strength]
99
  self.mh.pipeline.set_ip_adapter_scale(0.0)
100
 
101
  # We keep the guidance_end for pose low
102
+ control_guidance_end = [face_kps_guidance_end, 0.6, 0.6]
103
 
104
  # --- Seed/Generator Logic ---
105
  if seed == -1 or seed is None:
 
127
  controlnet_conditioning_scale=controlnet_conditioning_scale,
128
  control_guidance_end=control_guidance_end,
129
 
130
+ clip_skip=1,
131
 
132
  ).images[0]
133