apocaliss92's picture
camstack-train 0.1.0: YOLOv9 root detector fine-tune (job.json in, result.json + bundle.tar out)
ebeed67 verified
Raw History Blame Contribute Delete
796 Bytes
"""ArcFace face embedding postprocessor.
Input: raw embedding tensor from ArcFace model
Output: {"kind": "embedding", "embedding": [...], "embeddingNorm": [...]}
"""
import numpy as np
def postprocess_arcface(
predictions: dict,
config: dict,
orig_w: int,
orig_h: int,
scale: float,
pad: tuple[int, int],
) -> dict:
"""L2-normalize the embedding vector."""
# Get the first output tensor (usually named "fc1" or similar)
raw = np.array(list(predictions.values())[0]).flatten().astype(np.float32)
norm = np.linalg.norm(raw)
if norm == 0:
normalized = np.zeros_like(raw)
else:
normalized = raw / norm
return {
"kind": "embedding",
"embedding": raw.tolist(),
"embeddingNorm": normalized.tolist(),
}