feat(worker): 接口1 四庭七眼测量真实实现(替换 Mock)
worker 侧从 Mock 替换为真实算法: - face_analysis 包:detector(MediaPipe 478点) / pose(solvePnP 姿态) / calibration(虹膜直径法) / hair_segmenter+bisenet_model(方案B 头发分割) / measure(方案A兜底+B/A决策+七眼+换算) / annotation(numpy渐变线+中文标注) - app.py:/api/v1/face/measure 接真实实现,返回 annotated_image_base64 (不落盘不拼URL,落盘由网关做);加 X-Internal-Token 鉴权、/health 就绪态、 可配置分辨率门槛、异常兜底 - 部署:start.sh/run_worker.sh/hair-worker.service 监听 8187;worker_config 示例 - 测试 tests/:Tier1合成真值<1e-6 + Tier2缩放不变 + Tier3叠加 + 错误码集成 + 数值回归,pytest 24 项全绿 - 文档补实测基线表 + RTX5090/torch 说明 注:worker 为 RTX 5090(sm_120),pinned torch 2.2.2(cu121) 只到 sm_90, BiSeNet 已自动回退 CPU(方案B 正常);要用 GPU 需换 torch cu128(≥2.7)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""方案 B 定位逻辑的真值测试(合成 mask,纯 numpy,无需 torch)。"""
|
||||
import numpy as np
|
||||
|
||||
from face_analysis.hair_segmenter import locate_hairline_by_segmentation
|
||||
|
||||
|
||||
def test_locate_on_synthetic_mask():
|
||||
"""已知头发上沿 row=10、中轴线发际线 row=80,应被精确定位。"""
|
||||
H, W = 200, 100
|
||||
cx = W // 2
|
||||
mask = np.zeros((H, W), dtype=bool)
|
||||
mask[10:51, :] = True # 顶部头发块,最高点 row=10
|
||||
mask[10:81, cx - 1:cx + 2] = True # 中轴线碎发延伸到 row=80
|
||||
res = locate_hairline_by_segmentation(mask, cx, H)
|
||||
assert res is not None
|
||||
hairline_y, hair_top_y = res
|
||||
assert hairline_y == 80
|
||||
assert hair_top_y == 10
|
||||
assert hair_top_y < hairline_y
|
||||
|
||||
|
||||
def test_locate_none_on_empty():
|
||||
assert locate_hairline_by_segmentation(None, 50, 200) is None
|
||||
assert locate_hairline_by_segmentation(np.zeros((200, 100), bool), 50, 200) is None
|
||||
|
||||
|
||||
def test_locate_handles_out_of_range_x():
|
||||
"""brow_center_x 越界应被夹回,不抛异常。"""
|
||||
H, W = 100, 60
|
||||
mask = np.zeros((H, W), dtype=bool)
|
||||
mask[5:30, :] = True
|
||||
assert locate_hairline_by_segmentation(mask, 9999, H) is not None
|
||||
assert locate_hairline_by_segmentation(mask, -50, H) is not None
|
||||
Reference in New Issue
Block a user