feat: Face JSON v2 schema - add schema_version, bbox x2/y2/center, keep embeddings, update clustering

This commit is contained in:
Accusys
2026-11-02 14:34:02 +08:00
parent 2fca49b120
commit 5d18183d82
566 changed files with 321788 additions and 1662 deletions
+16 -3
View File
@@ -37,7 +37,9 @@ from qdrant_faces import push_face_embeddings_batch
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
SWIFT_BIN = os.path.join(SCRIPT_DIR, "swift_processors", ".build", "release", "swift_face")
SWIFT_BIN_DEBUG = os.path.join(SCRIPT_DIR, "swift_processors", ".build", "debug", "swift_face")
FACENET_PATH = os.path.join(SCRIPT_DIR, "..", "models", "facenet512.mlpackage")
# FIX: Correct path to facenet512.mlpackage (project root models/)
# SCRIPT_DIR = tools/script/face/, so we need ../../.. to reach project root
FACENET_PATH = os.path.join(SCRIPT_DIR, "..", "..", "..", "models", "facenet512.mlpackage")
# Pose angle classification from roll/yaw
def classify_pose(roll: float, yaw: float) -> str:
@@ -120,11 +122,17 @@ class FaceProcessorVision:
input_array = np.expand_dims(normalized, axis=0)
result = self.coreml_model.predict({"input": input_array})
# Find output key (var_xxx)
emb_key = [k for k in result.keys() if k.startswith("var_")][0]
var_keys = [k for k in result.keys() if k.startswith("var_")]
if not var_keys:
print(f"[FACE_V2] WARNING: No var_ output key found, keys={list(result.keys())}", file=sys.stderr)
return None
emb_key = var_keys[0]
emb = result[emb_key].flatten().tolist()
return emb
except Exception as e:
print(f"[FACE_V2] Embedding error: {e}")
import traceback
print(f"[FACE_V2] Embedding error: {e}", file=sys.stderr)
print(f"[FACE_V2] Traceback: {traceback.format_exc()}", file=sys.stderr)
return None
def process_with_swift(self) -> Dict:
@@ -252,19 +260,24 @@ class FaceProcessorVision:
self.video.set(cv2.CAP_PROP_POS_FRAMES, frame_num)
ret, frame = self.video.read()
if not ret:
print(f"[FACE_V2] WARNING: video.read() failed at frame {frame_num}", file=sys.stderr)
continue
# Crop face
x1, y1 = max(0, x), max(0, y)
x2, y2 = min(self.width, x + w), min(self.height, y + h)
if x2 <= x1 or y2 <= y1:
print(f"[FACE_V2] WARNING: invalid crop at frame {frame_num}: bbox={bb}", file=sys.stderr)
continue
face_img = frame[y1:y2, x1:x2]
if face_img.size == 0:
print(f"[FACE_V2] WARNING: empty crop at frame {frame_num}", file=sys.stderr)
continue
# CoreML embedding - push to Qdrant _faces collection
emb = self.extract_face_embedding(face_img)
if emb is None:
print(f"[FACE_V2] WARNING: embedding failed at frame {frame_num}", file=sys.stderr)
if emb is not None:
embed_count += 1
# Collect for batch Qdrant push