MacBook pro commited on
Commit
8caf3b0
·
1 Parent(s): 320ec50

feat: add detailed swap diagnostics counters & logging

Browse files
Files changed (1) hide show
  1. swap_pipeline.py +14 -1
swap_pipeline.py CHANGED
@@ -52,7 +52,13 @@ class FaceSwapPipeline:
52
  'last_latency_ms': None,
53
  'avg_latency_ms': None,
54
  'swap_faces_last': 0,
55
- 'enhanced_frames': 0
 
 
 
 
 
 
56
  }
57
  self._lat_hist: List[float] = []
58
  self._codeformer_lat_hist: List[float] = []
@@ -288,10 +294,12 @@ class FaceSwapPipeline:
288
 
289
  def process_frame(self, frame: np.ndarray) -> np.ndarray:
290
  if not self.initialized or self.swapper is None or self.app is None:
 
291
  if self.swap_debug:
292
  logger.debug('process_frame: pipeline not fully initialized yet')
293
  return frame
294
  if self.source_face is None:
 
295
  if self.swap_debug:
296
  logger.debug('process_frame: no source_face set yet')
297
  return frame
@@ -303,10 +311,13 @@ class FaceSwapPipeline:
303
  logger.debug('process_frame: no faces detected in incoming frame')
304
  self._record_latency(time.time() - t0)
305
  self._stats['swap_faces_last'] = 0
 
306
  # Count processed frame even if no faces detected
307
  self._stats['frames'] += 1
308
  self._frame_index += 1
309
  return frame
 
 
310
  # Sort faces by area and keep top-N
311
  def _area(face):
312
  x1,y1,x2,y2 = face.bbox.astype(int)
@@ -320,6 +331,7 @@ class FaceSwapPipeline:
320
  count += 1
321
  except Exception as e:
322
  logger.debug(f"Swap failed for face: {e}")
 
323
  if self.swap_debug:
324
  logger.debug(f'process_frame: detected={len(faces)} swapped={count} stride={self.codeformer_frame_stride} apply_cf={count>0 and (self._frame_index % self.codeformer_frame_stride == 0)}')
325
  # CodeFormer stride / face-region logic
@@ -378,6 +390,7 @@ class FaceSwapPipeline:
378
  codeformer_frame_stride=self.codeformer_frame_stride,
379
  codeformer_face_only=self.codeformer_face_only,
380
  codeformer_avg_latency_ms=cf_avg,
 
381
  )
382
  # Provider diagnostics (best-effort)
383
  try: # pragma: no cover
 
52
  'last_latency_ms': None,
53
  'avg_latency_ms': None,
54
  'swap_faces_last': 0,
55
+ 'enhanced_frames': 0,
56
+ # New diagnostic counters
57
+ 'early_no_source': 0,
58
+ 'early_uninitialized': 0,
59
+ 'frames_no_faces': 0,
60
+ 'total_faces_detected': 0,
61
+ 'total_faces_swapped': 0
62
  }
63
  self._lat_hist: List[float] = []
64
  self._codeformer_lat_hist: List[float] = []
 
294
 
295
  def process_frame(self, frame: np.ndarray) -> np.ndarray:
296
  if not self.initialized or self.swapper is None or self.app is None:
297
+ self._stats['early_uninitialized'] += 1
298
  if self.swap_debug:
299
  logger.debug('process_frame: pipeline not fully initialized yet')
300
  return frame
301
  if self.source_face is None:
302
+ self._stats['early_no_source'] += 1
303
  if self.swap_debug:
304
  logger.debug('process_frame: no source_face set yet')
305
  return frame
 
311
  logger.debug('process_frame: no faces detected in incoming frame')
312
  self._record_latency(time.time() - t0)
313
  self._stats['swap_faces_last'] = 0
314
+ self._stats['frames_no_faces'] += 1
315
  # Count processed frame even if no faces detected
316
  self._stats['frames'] += 1
317
  self._frame_index += 1
318
  return frame
319
+ # Accumulate total faces detected (pre top-N filter)
320
+ self._stats['total_faces_detected'] += len(faces)
321
  # Sort faces by area and keep top-N
322
  def _area(face):
323
  x1,y1,x2,y2 = face.bbox.astype(int)
 
331
  count += 1
332
  except Exception as e:
333
  logger.debug(f"Swap failed for face: {e}")
334
+ self._stats['total_faces_swapped'] += count
335
  if self.swap_debug:
336
  logger.debug(f'process_frame: detected={len(faces)} swapped={count} stride={self.codeformer_frame_stride} apply_cf={count>0 and (self._frame_index % self.codeformer_frame_stride == 0)}')
337
  # CodeFormer stride / face-region logic
 
390
  codeformer_frame_stride=self.codeformer_frame_stride,
391
  codeformer_face_only=self.codeformer_face_only,
392
  codeformer_avg_latency_ms=cf_avg,
393
+ max_faces=self.max_faces,
394
  )
395
  # Provider diagnostics (best-effort)
396
  try: # pragma: no cover