refactor(lib): remove legacy generator.py / coord.py / scroll module

Drop the pre-migration PyTorch inference pipeline now that the ONNX-backed
MouseModel/ScrollModel in mouse.py and scroll.py are wired up through the
public ai_mouse API.

Deleted:
  * src/ai_mouse/generator.py        (legacy torch flow ODE + post-processing)
  * src/ai_mouse/coord.py            (legacy public coord transforms,
                                      superseded by ai_mouse._coord)
  * src/ai_mouse/_scroll_legacy.py   (legacy torch scroll VAE inference)
  * scripts/build_golden_*.py        (one-shot capture scripts, no longer
                                      needed once goldens are committed)
  * tests/unit/test_generator.py     (legacy module gone)
  * tests/unit/test_scroll_generator.py (legacy module gone)
  * tests/unit/test_coord.py         (legacy module gone; ai_mouse._coord is
                                      tested by test__coord.py)
  * scripts/                         (empty, removed)

Tools migrations:
  * tools/trainer.py: import encode_trajectory from ai_mouse._coord
    instead of the deleted ai_mouse.coord
  * tools/server/routes_verify.py, tools/server/routes_scroll.py: route to
    the public ai_mouse.generate / generate_scroll. They no longer accept
    a model_dir override — the bundled ONNX is the source of truth, and a
    fresh export goes through `python -m tools.export_onnx`.
  * tools/eval/__main__.py: same migration; model_dir CLI arg retained as
    a deprecation shim but ignored.

Final src/ai_mouse/ layout (matches plan):
  __init__.py, _assets.py, _coord.py, _model_cache.py, _postprocess.py,
  errors.py, mouse.py, py.typed, scroll.py, assets/

Test suite: 188 passed (was 188 before deletion; obsolete suites cleaned
out alongside the modules they covered).
This commit is contained in:
2026-05-12 01:23:52 +08:00
parent 525e555884
commit 31fd884dfd
12 changed files with 20 additions and 1018 deletions

View File

@@ -182,21 +182,17 @@ async def scroll_train(req: ScrollTrainRequest) -> StreamingResponse:
@router.post("/verify")
def scroll_verify(req: ScrollVerifyRequest) -> dict:
from ai_mouse.scroll.generator import generate_scroll
# Uses the bundled ONNX scroll model exposed via the public ai_mouse API.
# The legacy scroll_model.pt path is no longer wired in; export a fresh
# scroll_decoder.onnx via `python -m tools.export_onnx` to update.
from ai_mouse import generate_scroll
_, models_dir = _paths()
if not (models_dir / "scroll_model.pt").exists():
raise HTTPException(
status_code=400,
detail="滚轮模型尚未训练,请先在「训练模型 → 滚轮模型」中完成训练。",
)
paths = []
for _ in range(min(req.n_paths, 12)):
events = generate_scroll(
req.start_scrollY,
req.target_scrollY,
mode=req.mode,
model_dir=str(models_dir),
)
paths.append(events)
return {"paths": paths}

View File

@@ -7,8 +7,6 @@ import logging
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from .deps import get_data_dir
logger = logging.getLogger(__name__)
router = APIRouter()
@@ -32,18 +30,19 @@ class VerifyRequest(BaseModel):
@router.post("/verify")
def verify(req: VerifyRequest) -> dict:
from ai_mouse.generator import generate
# Uses the bundled ONNX model exposed via the public ai_mouse API.
# The legacy req.model_dir / data/models_v2 .pt path is no longer wired
# in; export a fresh .onnx via `python -m tools.export_onnx` to update.
from ai_mouse import generate
n = max(1, min(req.n_paths, 12))
models_dir = get_data_dir() / "models_v2"
model_dir_arg = req.model_dir if req.model_dir else str(models_dir)
start = tuple(req.start) # type: ignore[arg-type]
end = tuple(req.end) # type: ignore[arg-type]
paths = []
try:
for _ in range(n):
pts = generate(start=start, end=end, model_dir=model_dir_arg)
pts = generate(start=start, end=end)
paths.append([[x, y, t] for x, y, t in pts])
except FileNotFoundError as exc:
raise HTTPException(status_code=404, detail=str(exc)) from exc