Skip to content

预标注流水线(Prediction Pipeline)

v0.9.8 引入 prediction_jobs 表后,AI 预标注从"无状态触发"升级为有状态的流水线。本页讲清状态机、写入时点、与下游表的关系。

决策依据:ADR 0014 — Prediction Jobs 历史表

状态机

状态何时进入关键字段
createdAPI 入队 Celery 时created_at, celery_task_id, prompt, ml_backend_id
runningworker 在 task body 第一步写入started_at
succeededtask 正常返回finished_at, succeeded_count, failed_count
failed_BatchPredictTask.on_failure 兜底finished_at, error

端到端时序

predictions 表的边界

用途查哪张表
列出"现在能采纳的候选框"predictions(按 task 过滤)
列出"AI 跑了哪几次、成功失败、谁触发"prediction_jobs
重置批次后回看历史只能 prediction_jobspredictions 已被清)
工作台读取候选 → 渲染紫框predictionsto_internal_shape adapter

详见 API Schema 边界

工具单位 (tool_unit) 维度 (v0.10.17+)

v0.10.17 起 predictions.tool_unit_id String(30) 列必填:

  • 写入时由 PredictionService.create_from_ml_resultderive_tool_unit_from_resultresult[0].type 派生:
    • polygonlabels / brushlabels / multi_polygonregion
    • rectanglelabelsbbox
    • 其它(keypointlabels / linelabels)→ bbox 占位
  • to_internal_shape() 出参也带 tool_unit_id, 供前端候选层 / AAP JSON 导出消费
  • accept_prediction() 创建的 annotation 沿用 prediction 的 tool_unit_id (与项目 tool_bindings[unit].classes 软校验保一致)

详见 annotation-module · 工具单位ADR-0026

WebSocket 通道

通道谁订阅内容
project:{id}:preannotate该项目工作台单项目进度 / 错误
global:prediction-jobs任何 admin全局 in-flight job 进度(Topbar Badge)

后者解决 v0.9.7 的痛点:admin 切换项目后,旧项目的 in-flight 进度从屏幕上消失。

失败兜底(B-1 教训)

_BatchPredictTask.on_failure 把所有未捕获异常(包括 dispatch 阶段的 TypeError)推到 project:{id}:preannotate,前端 progress.error 分支可见——避免再出现"已排队后无响应"。

详见 Docker rebuild vs restart

代码索引

  • 模型:apps/api/app/db/models/prediction_job.py
  • Worker:apps/api/app/workers/tasks.py::batch_predict
  • 端点:apps/api/app/api/v1/predictions.py
  • 前端:apps/web/src/pages/AIPreAnnotate/hooks/useGlobalPreannotationJobs.ts
  • 迁移:apps/api/alembic/versions/0052_*.py

Released under the MIT License.