Skip to content

feat: add detector training, realistic eval, and browser export pipeline - #16

Merged
tkgstrator merged 19 commits into
developfrom
docs/training-plan-w384-refresh
Jul 13, 2026
Merged

feat: add detector training, realistic eval, and browser export pipeline#16
tkgstrator merged 19 commits into
developfrom
docs/training-plan-w384-refresh

Conversation

@tkgstrator

@tkgstrator tkgstrator commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

What

  • Detector trainingmito_train/training/train_detector.py, HFDetectorDataset, augmented pipeline. runs/board-detector-v1 が 100ep で val iou_mean 0.99+ に到達 (仕様書との差分は DETECTOR_STATUS.md)。
  • Realistic evaluationscripts/eval/eval_realistic.py (OCR 単体, GT bbox → crop → OCR) と scripts/eval/eval_realistic_e2e.py (end-to-end: detector 予測 → crop → OCR)。1 backbone / 1 wandb run、section = device の構造。5 backbone × 4 device × 1000 SFEN 実測。
  • ONNX export + release pipelinemito_train/export/{to_onnx,to_fp16,quantize}.pyscripts/export/{export_all,verify_onnx,build_release,write_manifest,write_release_notes}.github/workflows/deployment.yml。detector + 3 OCR backbone を fp32/fp16 で export、MANIFEST に realistic 精度を焼き込み、GitHub Release として archive (本番配信は R2 別インフラ)。
  • Doc 再構成docs/w384-sweep-analysis.md (収束・train↔val gap + realistic 評価)、docs/resolution-tradeoff.md (w224 vs w384)、docs/browser-inference-outlook.md (iGPU / iOS / Android 端末別推論時間見積)、docs/model-export.md (export パイプライン)、docs/README.md の索引。TRAINING_PLAN.md の backbone 選定を realistic 反映で更新。

Why

  • w384 sweep 完了で val 側は 0.976〜0.999 まで飽和、val 分布の穴 (count≥11 が 0 件、飛の非ゼロ率が train の半分) で backbone 間の差が測れない状態。realistic 評価で本命 backbone を確定する必要があった。
  • realistic end-to-end で efficientnet_b1 (7M) 99.67% / convnext_nano (15M) 99.92% / mobilenet_v3_large (3.3M) 97.92% を実測。iPad14,10 は piyoshogi-eval の GT bbox が OCR 学習側 crop 規約と一致せず OCR 単体では board=0.00% だが、detector 予測 bbox で crop すると全 backbone 93.89〜100.00% に復活 (detector iou 0.842 が実測)。
  • ブラウザ WebGPU 用に ONNX を排出、GitHub Release で archive。int8 動的量子化は OCR で argmax 崩壊、fp16 は cvnano 以外通る → shipping 対応表 (fp32 全対応 / fp16 detector + mnv3l + effb1 / int8 detector 参考のみ) を release notes に明記。

Test plan

  • uv run python scripts/export/verify_onnx.py で全 ONNX が PyTorch と argmax 完全一致 (fp32/fp16)
  • realistic eval 5 backbone × 4 device × 1000 SFEN を wandb project mito-train-board-ocr-w384-v0.3.1-eval-realistic および ...-eval-realistic-e2e に同期、JSON runs/eval/*.json に保存
  • scripts/export/build_release.sh v0.1.0dist/models-v0.1.0.tar.gz + MANIFEST + SHA256SUMS + release notes 生成 (release notes に per-backbone realistic 精度と per-device 内訳)
  • detector 学習 wandb run os5vtwqm で val iou_mean 0.99+ / @0.9=1.000 (全 device 込み)
  • CI (lint / test) 通過

Version

Bump to v0.3.4 (pre-1.0 rule: feat = patch)

🤖 Generated with Claude Code

- add 2026-07-13 w384 backbone sweep results
  (5 backbones, val sfen 0.976-0.999)
- collapse A/B/C/D/E design discussions to a single 実装済み summary
  since regression head, class weight, hand_weight=1.0, cosine+warmup,
  and resume have all landed
- drop v3 修正結果/内訳/config tables that referenced data/ocr_v3/
  files never generated
- keep v3 as a compact fallback plan for the case realistic captures
  reveal hand-tail gaps
- rewrite the next-iteration priorities around realistic evaluation
  and backbone selection

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tkgstrator
tkgstrator force-pushed the docs/training-plan-w384-refresh branch from d50de5f to 9a1ffc8 Compare July 13, 2026 07:59
tkgstrator and others added 17 commits July 13, 2026 08:19
New document w384-sweep-analysis.md records convergence speed, epoch
efficiency, and train/val gap analysis from the 384-resolution backbone
sweep. Updates TRAINING_PLAN.md and docs/README.md with references.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add HFDetectorDataset to load detector datasets from Hugging Face Hub with
per-sample bboxes. Add --hf-repo-id/--hf-config to train_detector.py. Document
w224 vs w384 resolution tradeoffs with measured baselines and operational
guidance.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Add asymmetric letterboxing (CropAndPad) for board context preservation
- Introduce anisotropic Affine scaling (x/y independent) with adjusted transform ranges
- Replace single blur with OneOf mix (GaussNoise, MotionBlur, GaussianBlur)
- Increase min_visibility to 0.999 for stricter bbox inclusion in crops
- Strengthen image degradation (compression, downscale) and color jitter parameters

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Evaluate BoardOCR against ultemica/piyoshogi-eval (1k SFEN × 4 real
devices). Isolates domain gap between training-set tight crops and
actual device screenshots.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Allow --best-metric argument to specify which metric selects best.pt.
Checkpoints now store best_metric and best_metric_name for resume.
Best model is saved to best.pt when a new best is found.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Handle missing/corrupt images gracefully with skip tracking, extract batch flush logic
into a helper function, and support .env configuration loading.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds W&B logging for per-(backbone, device) metrics and summary statistics.
Introduces --wandb, --wandb-project, and --wandb-run-name arguments to
control logging behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
wandb-core only reads WANDB__EXTRA_HTTP_HEADERS from the environment, not from
wandb.Settings, so inject CF Access credentials early before wandb imports.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Enforce one backbone per invocation to map eval runs 1:1 to training runs
- Use backbone name as default run identifier for seamless label pairing
- Add --wandb-group for clustering parallel per-backbone eval runs
- Remove backbone prefix from metric keys (simplified per-run structure)
- Fix summary handling for single-backbone scalar values

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reference material documenting differences between the specification
(docs/ocr-model-interface.md §2) and the current BoardDetector implementation
in mito_train, including input/output interface, model architecture, training
results, and extension costs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Removes crop-convention mismatch between piyoshogi-eval's bboxes and OCR
training data by using detector-predicted crops. Logs per-device metrics
to W&B (one run per backbone).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Completed piyoshogi-eval across 5 backbones × 4 devices: convnext_nano/tiny reach 99.92%
(exceed val baseline), efficientnet_b1 at 99.67% (Pareto-efficient), mobilenet_v3_large at
97.92% (edge lower bound). iPad board=0% was GT bbox annotation mismatch; resolved with
detector bbox preprocessing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
MODEL_SPECS now uses factory functions that extract backbone, image_size,
and hand_mode from the loaded checkpoint, preserving these settings in the
exported ONNX model without requiring additional CLI arguments.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Detector training pipeline, realistic eval (OCR-only + end-to-end), ONNX
export/release pipeline, browser inference outlook doc.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tkgstrator tkgstrator changed the title docs(training-plan): refresh for w384 sweep, prune implemented items feat: add detector training, realistic eval, and browser export pipeline Jul 13, 2026
F401 in hf_detector_dataset and verify_onnx, F541 in write_release_notes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tkgstrator
tkgstrator force-pushed the docs/training-plan-w384-refresh branch from b2236d4 to 0b569fd Compare July 13, 2026 11:34
@tkgstrator tkgstrator self-assigned this Jul 13, 2026
@tkgstrator
tkgstrator merged commit 124c097 into develop Jul 13, 2026
3 checks passed
@tkgstrator
tkgstrator deleted the docs/training-plan-w384-refresh branch July 13, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant