primerz commited on
Commit
e4dd0ff
·
verified ·
1 Parent(s): 874765f

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +6 -12
model.py CHANGED
@@ -119,23 +119,14 @@ class ModelHandler:
119
  # --- END NEW ---
120
 
121
  # 4. Set Scheduler
122
- # --- MODIFIED: Fine-tune LCMScheduler configuration ---
123
  print("Configuring fine-tuned LCMScheduler...")
124
-
125
- # Get the original config to use as a base
126
  scheduler_config = self.pipeline.scheduler.config
127
-
128
- # Apply our new, tuned settings
129
  scheduler_config['original_inference_steps'] = 75
130
  scheduler_config['timestep_spacing'] = "trailing"
131
  scheduler_config['timestep_scaling'] = 12.0
132
  scheduler_config['rescale_betas_zero_snr'] = True
133
-
134
- # Load the new scheduler from our modified config
135
  self.pipeline.scheduler = LCMScheduler.from_config(scheduler_config)
136
  print(" [OK] LCMScheduler fine-tuned.")
137
- # --- END MODIFIED ---
138
-
139
 
140
  # 5. Load Adapters (IP-Adapter & LoRA)
141
  print("Loading Adapters (IP-Adapter & LoRA)...")
@@ -169,8 +160,9 @@ class ModelHandler:
169
 
170
  print("--- All models loaded successfully ---")
171
 
172
- def get_face_embedding(self, image):
173
- """Extracts face embedding, returns None if no face is found."""
 
174
  if not self.face_analysis_loaded:
175
  return None
176
 
@@ -181,9 +173,11 @@ class ModelHandler:
181
  if len(faces) == 0:
182
  return None
183
 
 
184
  faces = sorted(faces, key=lambda x: (x['bbox'][2]-x['bbox'][0])*(x['bbox'][3]-x['bbox'][1]), reverse=True)
185
 
186
- return torch.tensor(faces[0].normed_embedding).unsqueeze(0)
 
187
  except Exception as e:
188
  print(f"Face embedding extraction failed: {e}")
189
  return None
 
119
  # --- END NEW ---
120
 
121
  # 4. Set Scheduler
 
122
  print("Configuring fine-tuned LCMScheduler...")
 
 
123
  scheduler_config = self.pipeline.scheduler.config
 
 
124
  scheduler_config['original_inference_steps'] = 75
125
  scheduler_config['timestep_spacing'] = "trailing"
126
  scheduler_config['timestep_scaling'] = 12.0
127
  scheduler_config['rescale_betas_zero_snr'] = True
 
 
128
  self.pipeline.scheduler = LCMScheduler.from_config(scheduler_config)
129
  print(" [OK] LCMScheduler fine-tuned.")
 
 
130
 
131
  # 5. Load Adapters (IP-Adapter & LoRA)
132
  print("Loading Adapters (IP-Adapter & LoRA)...")
 
160
 
161
  print("--- All models loaded successfully ---")
162
 
163
+ # --- MODIFIED: Renamed function and changed return value ---
164
+ def get_face_info(self, image):
165
+ """Extracts the largest face, returns insightface result object."""
166
  if not self.face_analysis_loaded:
167
  return None
168
 
 
173
  if len(faces) == 0:
174
  return None
175
 
176
+ # Sort by size (width * height) to find the main character
177
  faces = sorted(faces, key=lambda x: (x['bbox'][2]-x['bbox'][0])*(x['bbox'][3]-x['bbox'][1]), reverse=True)
178
 
179
+ # Return the largest face info
180
+ return faces[0]
181
  except Exception as e:
182
  print(f"Face embedding extraction failed: {e}")
183
  return None