Spaces:
Paused
Paused
Update reid.py
Browse files
reid.py
CHANGED
|
@@ -408,31 +408,32 @@ class SQLiteEnhancedReID:
|
|
| 408 |
"""
|
| 409 |
if not features_list:
|
| 410 |
return None
|
| 411 |
-
|
| 412 |
# Extract embeddings and qualities
|
| 413 |
embeddings = []
|
| 414 |
qualities = []
|
| 415 |
-
|
| 416 |
for feat in features_list[-20:]: # Use last 20
|
| 417 |
embeddings.append(feat.features)
|
| 418 |
qualities.append(feat.quality)
|
| 419 |
-
|
| 420 |
embeddings = np.array(embeddings)
|
| 421 |
qualities = np.array(qualities)
|
| 422 |
-
|
| 423 |
# Quality-weighted mean
|
|
|
|
| 424 |
if np.sum(qualities) > 0:
|
| 425 |
weights = qualities / np.sum(qualities)
|
| 426 |
mean_embedding = np.average(embeddings, axis=0, weights=weights)
|
| 427 |
else:
|
| 428 |
mean_embedding = np.mean(embeddings, axis=0)
|
| 429 |
-
|
| 430 |
# Normalize
|
| 431 |
mean_embedding = mean_embedding / (np.linalg.norm(mean_embedding) + 1e-7)
|
| 432 |
-
|
| 433 |
# Track aggregation stats
|
| 434 |
self.aggregation_stats['mean_computations'] += 1
|
| 435 |
-
|
| 436 |
if DEBUG_CONFIG['LOG_AGGREGATION']:
|
| 437 |
variance = np.var(embeddings, axis=0).mean()
|
| 438 |
self.debug_log.append(DebugInfo(
|
|
@@ -440,13 +441,14 @@ class SQLiteEnhancedReID:
|
|
| 440 |
operation="mean_aggregation",
|
| 441 |
details={
|
| 442 |
'num_embeddings': len(embeddings),
|
| 443 |
-
'avg_quality': float(np.mean(qualities)),
|
| 444 |
'embedding_variance': float(variance),
|
| 445 |
-
'weight_range': [float(weights.min()), float(weights.max())] if
|
| 446 |
}
|
| 447 |
))
|
| 448 |
-
|
| 449 |
return mean_embedding
|
|
|
|
| 450 |
|
| 451 |
def check_session(self, features: np.ndarray, threshold: float = None) -> Optional[int]:
|
| 452 |
"""
|
|
|
|
| 408 |
"""
|
| 409 |
if not features_list:
|
| 410 |
return None
|
| 411 |
+
|
| 412 |
# Extract embeddings and qualities
|
| 413 |
embeddings = []
|
| 414 |
qualities = []
|
| 415 |
+
|
| 416 |
for feat in features_list[-20:]: # Use last 20
|
| 417 |
embeddings.append(feat.features)
|
| 418 |
qualities.append(feat.quality)
|
| 419 |
+
|
| 420 |
embeddings = np.array(embeddings)
|
| 421 |
qualities = np.array(qualities)
|
| 422 |
+
|
| 423 |
# Quality-weighted mean
|
| 424 |
+
weights = np.array([]) # ✅ ensure weights always exists
|
| 425 |
if np.sum(qualities) > 0:
|
| 426 |
weights = qualities / np.sum(qualities)
|
| 427 |
mean_embedding = np.average(embeddings, axis=0, weights=weights)
|
| 428 |
else:
|
| 429 |
mean_embedding = np.mean(embeddings, axis=0)
|
| 430 |
+
|
| 431 |
# Normalize
|
| 432 |
mean_embedding = mean_embedding / (np.linalg.norm(mean_embedding) + 1e-7)
|
| 433 |
+
|
| 434 |
# Track aggregation stats
|
| 435 |
self.aggregation_stats['mean_computations'] += 1
|
| 436 |
+
|
| 437 |
if DEBUG_CONFIG['LOG_AGGREGATION']:
|
| 438 |
variance = np.var(embeddings, axis=0).mean()
|
| 439 |
self.debug_log.append(DebugInfo(
|
|
|
|
| 441 |
operation="mean_aggregation",
|
| 442 |
details={
|
| 443 |
'num_embeddings': len(embeddings),
|
| 444 |
+
'avg_quality': float(np.mean(qualities)) if qualities.size > 0 else 0,
|
| 445 |
'embedding_variance': float(variance),
|
| 446 |
+
'weight_range': [float(weights.min()), float(weights.max())] if weights.size > 0 else [0, 0]
|
| 447 |
}
|
| 448 |
))
|
| 449 |
+
|
| 450 |
return mean_embedding
|
| 451 |
+
|
| 452 |
|
| 453 |
def check_session(self, features: np.ndarray, threshold: float = None) -> Optional[int]:
|
| 454 |
"""
|