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,42 @@
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel # pydantic v1
|
||||
|
||||
|
||||
class DefectBoxSchema(BaseModel):
|
||||
class_id: int
|
||||
class_name: str
|
||||
class_name_zh: str
|
||||
confidence: float
|
||||
severity: str
|
||||
box_xyxy: List[float]
|
||||
|
||||
|
||||
class DetectResponse(BaseModel):
|
||||
task_id: str
|
||||
verdict: str # pass | fail
|
||||
defect_count: int
|
||||
max_severity: str
|
||||
avg_confidence: float
|
||||
duration_ms: float
|
||||
image_width: int
|
||||
image_height: int
|
||||
model_version: str
|
||||
defects: List[DefectBoxSchema]
|
||||
annotated_image_base64: Optional[str] = None
|
||||
|
||||
|
||||
class ReloadRequest(BaseModel):
|
||||
model_path: str
|
||||
runtime: str = "ultralytics"
|
||||
|
||||
|
||||
class ReloadResponse(BaseModel):
|
||||
status: str
|
||||
model_version: str
|
||||
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
status: str
|
||||
model_version: str
|
||||
runtime: str
|
||||
device: str
|
||||
|
||||
Reference in New Issue
Block a user