Skip to content

Select production epoch from pooled EMA validation curve - #36

Draft
MaxLinCode wants to merge 1 commit into
mainfrom
codex/ema-pooled-epoch
Draft

MaxLinCode wants to merge 1 commit into
mainfrom
codex/ema-pooled-epoch

Conversation

@MaxLinCode

Copy link
Copy Markdown
Owner

Summary

  • Track an EMA of the full model state during training and validate the averaged weights after each epoch.
  • Pool per-fold validation BCE curves epoch by epoch instead of taking a median of per-fold minima.
  • Smooth the pooled curve with a centered three-epoch moving average and pick the argmin epoch for the all-sources production run.
  • Record pooled, smoothed, and per-fold curves in fold/production checkpoints and metrics.json; persist EMA state in recovery checkpoints.
  • Expose ema_decay in the training recipe and CLI (default 0.999 with warm-up).

Per-fold checkpoints still select their own best EMA validation epoch for the single held-out-camera evaluation; only production epoch selection is pooled.

Test plan

  • PYTHONPATH=. .venv/bin/python -m pytest -q — 460 passed.
  • Added tests for EMA update/swap semantics, EMA-weight validation, recovery round-trip with EMA state, pooled/smoothed argmin selection, and clean-run production wiring.

Track an EMA of the full model state during fold training and validate the averaged weights each epoch. Pool the per-fold validation BCE curves, smooth the pooled curve with a centered three-epoch moving average, and train the all-sources production checkpoint for the argmin epoch instead of the median of per-fold minima.

Record the pooled, smoothed, and per-fold curves in the fold and production checkpoints and metrics, persist EMA state in recovery checkpoints, and cover EMA validation plus pooled selection with tests.
@MaxLinCode

MaxLinCode commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner Author

Follow-up: the cross-decoder check changes the diagnosis.

I re-decoded the same saved held-out test predictions with the baseline decoder and with the new per-fold decoders (30 fps, same rows, same evaluation code):

test predictions decoder macro interval F1 boundary MAE false splits fragmentation
baseline baseline 0.7705 14.41 2.75 3.50
baseline new 0.6473 18.41 8.50 13.00
new baseline 0.8243 12.73 1.50 2.00
new new 0.7349 18.36 9.25 10.50

The new model predictions are better when decoded with the baseline decoder: +0.054 interval F1, -1.68 boundary MAE, false splits 2.75 -> 1.50. Conversely, the old predictions with the new decoder are much worse. So the interval regression is almost entirely decoder calibration/selection, not EMA or pooled epoch selection. Per camera with the fixed baseline decoder: Bothell 0.698 -> 0.699 (wash, boundary MAE 12.57 -> 14.45), Malaysia 0.783 -> 0.837, Max-vs-Lucas 0.796 -> 0.889, Max-vs-Nik 0.805 -> 0.872.

Why the decoder moved:

  • EMA improves probability calibration (Brier 0.0732 -> 0.0620, ECE 0.0574 -> 0.0354), which shifts the validation-optimal thresholds up: fold A 0.7 -> 0.9, B 0.85 -> 0.95, D 0.8 -> 0.95, while shrinking gap bridging: A 0.3 -> 0.1, C 0.5 -> 0.0. High thresholds plus no gap bridging fragment held-out rallies (false splits 2.75 -> 9.25; fragmentation 3.5 -> 10.5).
  • Fold C is the clearest example: its new decoder has max_gap_seconds=0.0; validation interval F1 and boundary MAE both improved, but held-out test collapsed to 0.667 with 16 false splits. The per-fold decoder is tuned on the other cameras' validation partition, so it can overfit the camera domain; the unregularized grid makes that more likely.
  • Fold A is partly a checkpoint issue as well: EMA BCE bottoms at epoch 4, but validation boundary MAE is 13.4 vs 9.06 for the baseline epoch 12, and the boundary-head training losses are much higher at epoch 4 (start 0.361 vs 0.188, end 0.484 vs 0.287 at epoch 12). In-play BCE is mostly frame classification and does not capture boundary convergence. Even so, with the fixed decoder fold A is a wash rather than a regression.
  • Production epoch 6 vs 10: production train BCE is higher (0.2597 vs 0.1862) simply because production stops four epochs earlier. The production model also sees more sources and more updates per epoch than the fold models, so the fold CV epoch may not transfer exactly. This is a separate risk from the decoder; production was not evaluated on held-out labels.

Corrected conclusion: do not reject EMA/pooled selection because of the interval regression. Under a fixed decoding rule the model is better. The decoder needs a robust calibration policy: pooled/leave-one-camera-out tuning instead of per-fold validation tuning, no max_gap_seconds=0, and regularization/penalties against extreme thresholds. I would rerun after fixing the decoder, then revisit whether the pooled production epoch should be later (e.g. a 1-SE/later-epoch rule) and whether production should be step-matched rather than epoch-matched.

Also, for the record: held-out frame BCE did not get worse. Macro raw BCE improved 0.2934 -> 0.2232; only Max-vs-Nik worsened (0.2092 -> 0.2277). The higher production train BCE is the earlier stop, not a worse held-out objective.

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