Files
hair/requirements.txt
T
xslandClaude Opus 4.8 554b64a916 feat(接口2): C端生发发际线预览(真实实现,替换Mock)
第一步:按性别把发际线类型贴图渲染到照片,输出 N 张发际线叠加预览图。

- hairline/render.py: 解析 face_ext.obj(502 UV + 64 ribbon扩展面) + OpenCV 逐三角
  仿射 warp 渲染器;关键修复——face_ext.obj 是 OBJ序,用 INDEX_MAP_468 把 MP序
  502点重排成 OBJ序后再投影,否则 ribbon 会错贴到中脸
- hairline/service.py: FaceLandmarker+SegFormer 单例 + 性别贴图映射(扫描去空格)
  + generate_previews 管线(female5/male4)
- 集成点修复: face_landmarks DEFAULT_MODEL_PATH 改 hairline/models/;
  constants HF_FACE_PARSER_MODEL 改本地路径(离线)
- app.py: /api/v1/hair/grow 接真实实现,gender 必填(非法→1004),返回
  results[].image_base64(不落盘),校验/鉴权同接口1;lifespan 预热接口2单例;
  补 logging.basicConfig
- 依赖: transformers==4.45.2;SegFormer 权重走 hf-mirror 下载(见 OFFLINE_ASSETS)
- 测试: tests/test_hairline.py(mesh/重排/贴图映射) + test_api 接口2用例,31 全绿

注:SegFormer 受 5090/torch 限制走 CPU(~2.5s/张),换 cu128 可 SEG_DEVICE=cuda。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-14 20:31:41 +08:00

27 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
fastapi==0.115.12
uvicorn[standard]==0.34.2
python-multipart==0.0.31
httpx==0.28.1
# 接口1:四庭七眼测量(worker 侧算法依赖)
mediapipe==0.10.14 # MediaPipe Face Mesh(经典 Solutions API,模型内置)
opencv-python==4.10.0.84 # 图片读取/处理 + solvePnP 姿态估计
Pillow==11.0.0 # 标注图生成(PNG 透明图层)
numpy==1.26.4 # 必须 <2,否则 mediapipe 0.10.x import 崩溃
# 方案 B:头发分割(BiSeNet face-parsing
# 国内安装可走 Tsinghua 镜像(PyPI 的 linux wheel 即 CUDA 12.1 构建):
# ./venv/bin/pip install torch==2.2.2 torchvision==0.17.2 -i https://pypi.tuna.tsinghua.edu.cn/simple/
# ⚠️ 本 worker 是 RTX 5090sm_120/Blackwell),torch 2.2.2(cu121) 只编到 sm_90
# GPU 上跑算子会报 "no kernel image",代码已自动回退 CPU(方案B 仍可用)。
# 要真正用 5090 GPU,请换 torch cu128(≥2.7+ 对应 torchvision,代码无需改。
torch==2.2.2 # 当前在 5090 上仅 CPU 可用;GPU 需 cu128(≥2.7)
torchvision==0.17.2
# 接口2C端生发(发际线预览)
# MediaPipe Tasks(FaceLandmarker) 用已装的 mediapipe;新增 SegFormer 人脸分割:
transformers==4.45.2 # SegFormer 人脸分割(jonathandinu/face-parsing,本地权重)
# 测试
pytest==8.3.3