feat(vision): 实现 mingxi-vision 推理服务核心功能
- engine/defect_classes: HRIPCB 6类缺陷定义 + 4类扩展 + severity排序 - engine/base: DefectBox / DetectResult 数据类 + BaseInferenceEngine 抽象基类 - engine/ultralytics_adapter: YOLOv8 .pt 推理适配器 + warmup - engine/annotator: 按 severity 着色的标注图生成 + base64 编码 - engine/loader: 单例管理 + asyncio.Lock 推理串行化 + 热重载支持 - config: Pydantic v1 BaseSettings,读取 .env - schema: DetectResponse / HealthResponse / ReloadRequest 等响应模型 - api/detect: POST /api/detect,内存读图,推理锁保护 - api/health: GET /api/health - api/model: POST /api/model/reload 热重载接口 - main: FastAPI lifespan 启动加载模型 测试通过:/api/health 200,/api/detect 空图返回 pass,标注图 base64 正常 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
from typing import Dict
|
||||
|
||||
DEFECT_CLASSES: Dict[int, dict] = {
|
||||
# HRIPCB 数据集原始 6 类
|
||||
0: {"name": "missing_hole", "zh": "缺孔", "severity": "fatal"},
|
||||
1: {"name": "mouse_bite", "zh": "鼠咬", "severity": "major"},
|
||||
2: {"name": "open_circuit", "zh": "断路", "severity": "fatal"},
|
||||
3: {"name": "short_circuit", "zh": "短路", "severity": "fatal"},
|
||||
4: {"name": "spur", "zh": "毛刺", "severity": "minor"},
|
||||
5: {"name": "spurious_copper", "zh": "余铜", "severity": "major"},
|
||||
# 扩展类(Phase 2 标注后加入训练)
|
||||
6: {"name": "oxidation", "zh": "氧化", "severity": "minor"},
|
||||
7: {"name": "solder_ball", "zh": "锡珠", "severity": "rework"},
|
||||
8: {"name": "scratch", "zh": "划痕", "severity": "minor"},
|
||||
9: {"name": "label_error", "zh": "标签错贴","severity": "rework"},
|
||||
}
|
||||
|
||||
# 严重程度从低到高,用于比较 max_severity
|
||||
SEVERITY_ORDER = ["none", "rework", "minor", "major", "fatal"]
|
||||
|
||||
|
||||
def get_class_info(class_id: int) -> dict:
|
||||
return DEFECT_CLASSES.get(class_id, {
|
||||
"name": f"unknown_{class_id}",
|
||||
"zh": f"未知_{class_id}",
|
||||
"severity": "minor",
|
||||
})
|
||||
|
||||
|
||||
def max_severity(severities) -> str:
|
||||
if not severities:
|
||||
return "none"
|
||||
return max(severities, key=lambda s: SEVERITY_ORDER.index(s) if s in SEVERITY_ORDER else 0)
|
||||
|
||||
Reference in New Issue
Block a user