Upload 2 files
Browse files- api.py +6 -1
- face_classifier.py +20 -20
api.py
CHANGED
|
@@ -800,7 +800,12 @@ def process_video_job(job_id: str):
|
|
| 800 |
}
|
| 801 |
job["status"] = JobStatus.DONE
|
| 802 |
|
| 803 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 804 |
|
| 805 |
except Exception as e_detect:
|
| 806 |
# Si falla la detección, intentar modo fallback
|
|
|
|
| 800 |
}
|
| 801 |
job["status"] = JobStatus.DONE
|
| 802 |
|
| 803 |
+
# Log resumido sin embeddings
|
| 804 |
+
print(f"[{job_id}] ✓ Resultados guardados:")
|
| 805 |
+
print(f"[{job_id}] - Personatges: {len(characters)}")
|
| 806 |
+
print(f"[{job_id}] - Segments d'àudio: {len(audio_segments)}")
|
| 807 |
+
print(f"[{job_id}] - Face embeddings: {num_face_embeddings}")
|
| 808 |
+
print(f"[{job_id}] - Voice embeddings: {len(voice_embeddings)}")
|
| 809 |
|
| 810 |
except Exception as e_detect:
|
| 811 |
# Si falla la detección, intentar modo fallback
|
face_classifier.py
CHANGED
|
@@ -35,7 +35,7 @@ def validate_and_classify_face(image_path: str) -> Optional[Dict[str, Any]]:
|
|
| 35 |
try:
|
| 36 |
from deepface import DeepFace
|
| 37 |
|
| 38 |
-
|
| 39 |
|
| 40 |
# Analitzar gènere amb detecció de cara
|
| 41 |
result = DeepFace.analyze(
|
|
@@ -48,11 +48,11 @@ def validate_and_classify_face(image_path: str) -> Optional[Dict[str, Any]]:
|
|
| 48 |
|
| 49 |
# DeepFace pot retornar llista si detecta múltiples cares
|
| 50 |
if isinstance(result, list):
|
| 51 |
-
|
| 52 |
result = result[0] if result else None
|
| 53 |
|
| 54 |
if not result:
|
| 55 |
-
|
| 56 |
return {
|
| 57 |
'is_valid_face': False,
|
| 58 |
'face_confidence': 0.0,
|
|
@@ -63,37 +63,37 @@ def validate_and_classify_face(image_path: str) -> Optional[Dict[str, Any]]:
|
|
| 63 |
}
|
| 64 |
|
| 65 |
# LOG: Ver estructura completa del resultado
|
| 66 |
-
|
| 67 |
|
| 68 |
# Extreure informació de gènere
|
| 69 |
gender_info = result.get('gender', {})
|
| 70 |
-
|
| 71 |
|
| 72 |
if isinstance(gender_info, dict):
|
| 73 |
# DeepFace retorna percentatges, convertir a 0-1
|
| 74 |
man_prob = gender_info.get('Man', 0) / 100.0
|
| 75 |
woman_prob = gender_info.get('Woman', 0) / 100.0
|
| 76 |
-
|
| 77 |
else:
|
| 78 |
# Fallback si el format és diferent
|
| 79 |
-
|
| 80 |
man_prob = 0.5
|
| 81 |
woman_prob = 0.5
|
| 82 |
|
| 83 |
# Determinar gènere basat en les probabilitats
|
| 84 |
gender_diff = abs(man_prob - woman_prob)
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
# Si la diferència és petita (< threshold), considerar neutre
|
| 89 |
if gender_diff < GENDER_NEUTRAL_THRESHOLD:
|
| 90 |
gender = 'Neutral'
|
| 91 |
gender_confidence = 0.5
|
| 92 |
-
|
| 93 |
else:
|
| 94 |
gender = 'Man' if man_prob > woman_prob else 'Woman'
|
| 95 |
gender_confidence = max(man_prob, woman_prob)
|
| 96 |
-
|
| 97 |
|
| 98 |
# Confiança de detecció de cara
|
| 99 |
# DeepFace no proporciona score directamente en analyze(), pero si retornó resultado
|
|
@@ -103,14 +103,14 @@ def validate_and_classify_face(image_path: str) -> Optional[Dict[str, Any]]:
|
|
| 103 |
# Si DeepFace va retornar resultat, assumir que és cara vàlida
|
| 104 |
is_valid_face = True
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
|
| 115 |
return {
|
| 116 |
'is_valid_face': is_valid_face,
|
|
@@ -123,7 +123,7 @@ def validate_and_classify_face(image_path: str) -> Optional[Dict[str, Any]]:
|
|
| 123 |
|
| 124 |
except ValueError as e:
|
| 125 |
# ValueError significa que no es va detectar cara
|
| 126 |
-
|
| 127 |
return {
|
| 128 |
'is_valid_face': False,
|
| 129 |
'face_confidence': 0.0,
|
|
@@ -133,7 +133,7 @@ def validate_and_classify_face(image_path: str) -> Optional[Dict[str, Any]]:
|
|
| 133 |
'woman_prob': 0.0
|
| 134 |
}
|
| 135 |
except Exception as e:
|
| 136 |
-
|
| 137 |
return None
|
| 138 |
|
| 139 |
|
|
|
|
| 35 |
try:
|
| 36 |
from deepface import DeepFace
|
| 37 |
|
| 38 |
+
print(f"[DeepFace] Analitzant: {image_path}")
|
| 39 |
|
| 40 |
# Analitzar gènere amb detecció de cara
|
| 41 |
result = DeepFace.analyze(
|
|
|
|
| 48 |
|
| 49 |
# DeepFace pot retornar llista si detecta múltiples cares
|
| 50 |
if isinstance(result, list):
|
| 51 |
+
print(f"[DeepFace] Resultado es lista con {len(result)} elementos")
|
| 52 |
result = result[0] if result else None
|
| 53 |
|
| 54 |
if not result:
|
| 55 |
+
print(f"[DeepFace] No s'ha detectat cap cara")
|
| 56 |
return {
|
| 57 |
'is_valid_face': False,
|
| 58 |
'face_confidence': 0.0,
|
|
|
|
| 63 |
}
|
| 64 |
|
| 65 |
# LOG: Ver estructura completa del resultado
|
| 66 |
+
print(f"[DeepFace] Resultado completo de analyze: {result}")
|
| 67 |
|
| 68 |
# Extreure informació de gènere
|
| 69 |
gender_info = result.get('gender', {})
|
| 70 |
+
print(f"[DeepFace] gender_info type: {type(gender_info)}, value: {gender_info}")
|
| 71 |
|
| 72 |
if isinstance(gender_info, dict):
|
| 73 |
# DeepFace retorna percentatges, convertir a 0-1
|
| 74 |
man_prob = gender_info.get('Man', 0) / 100.0
|
| 75 |
woman_prob = gender_info.get('Woman', 0) / 100.0
|
| 76 |
+
print(f"[DeepFace] Extraído de dict - Man: {man_prob:.3f}, Woman: {woman_prob:.3f}")
|
| 77 |
else:
|
| 78 |
# Fallback si el format és diferent
|
| 79 |
+
print(f"[DeepFace] gender_info NO es dict, usando fallback 0.5/0.5")
|
| 80 |
man_prob = 0.5
|
| 81 |
woman_prob = 0.5
|
| 82 |
|
| 83 |
# Determinar gènere basat en les probabilitats
|
| 84 |
gender_diff = abs(man_prob - woman_prob)
|
| 85 |
|
| 86 |
+
print(f"[DeepFace] Diferencia Man-Woman: {gender_diff:.3f} (threshold neutral={GENDER_NEUTRAL_THRESHOLD})")
|
| 87 |
|
| 88 |
# Si la diferència és petita (< threshold), considerar neutre
|
| 89 |
if gender_diff < GENDER_NEUTRAL_THRESHOLD:
|
| 90 |
gender = 'Neutral'
|
| 91 |
gender_confidence = 0.5
|
| 92 |
+
print(f"[DeepFace] → Asignado NEUTRAL (diferencia {gender_diff:.3f} < {GENDER_NEUTRAL_THRESHOLD})")
|
| 93 |
else:
|
| 94 |
gender = 'Man' if man_prob > woman_prob else 'Woman'
|
| 95 |
gender_confidence = max(man_prob, woman_prob)
|
| 96 |
+
print(f"[DeepFace] → Asignado {gender.upper()} (man_prob={man_prob:.3f}, woman_prob={woman_prob:.3f})")
|
| 97 |
|
| 98 |
# Confiança de detecció de cara
|
| 99 |
# DeepFace no proporciona score directamente en analyze(), pero si retornó resultado
|
|
|
|
| 103 |
# Si DeepFace va retornar resultat, assumir que és cara vàlida
|
| 104 |
is_valid_face = True
|
| 105 |
|
| 106 |
+
print(f"[DeepFace] ===== RESUMEN FINAL =====")
|
| 107 |
+
print(f"[DeepFace] is_valid_face: {is_valid_face}")
|
| 108 |
+
print(f"[DeepFace] face_confidence: {face_confidence:.3f}")
|
| 109 |
+
print(f"[DeepFace] gender: {gender}")
|
| 110 |
+
print(f"[DeepFace] gender_confidence: {gender_confidence:.3f}")
|
| 111 |
+
print(f"[DeepFace] man_prob: {man_prob:.3f}")
|
| 112 |
+
print(f"[DeepFace] woman_prob: {woman_prob:.3f}")
|
| 113 |
+
print(f"[DeepFace] ==========================")
|
| 114 |
|
| 115 |
return {
|
| 116 |
'is_valid_face': is_valid_face,
|
|
|
|
| 123 |
|
| 124 |
except ValueError as e:
|
| 125 |
# ValueError significa que no es va detectar cara
|
| 126 |
+
print(f"[DeepFace] No s'ha detectat cara (ValueError): {e}")
|
| 127 |
return {
|
| 128 |
'is_valid_face': False,
|
| 129 |
'face_confidence': 0.0,
|
|
|
|
| 133 |
'woman_prob': 0.0
|
| 134 |
}
|
| 135 |
except Exception as e:
|
| 136 |
+
print(f"[DeepFace] Error validant cara: {e}")
|
| 137 |
return None
|
| 138 |
|
| 139 |
|