code wiki / _hdl_build / nx_vcodec_nf_train.nx
nx_vcodec_nf_train.nx
buildroot/runtime/_hdl_build/nx_vcodec_nf_train.nx
about
nx_vcodec_nf_train.nx -- TRAINER for the learned decoder-side restoration filter (NEURAL track rung 1).
Sovereign, integer-only, no floats anywhere. For every (codec-mode in {legacy tf=1, t8-rich}, qp in
{12,20,32}) it runs OUR real codec (key + P chain, in-loop deblock -- exactly the live display path)
over the REAL frames 0..7 of bframe_test_decoded.yuv (576x1024 luma; frames 8..11 stay HELD OUT for
the gate), accumulates per (qp-band, gradient-class) integer normal equations over (3x3 deblocked-recon
context -> source pixel) pairs, then solves each class's 3x3+bias Q12 filter:
step 1 CLOSED FORM: the center-vs-3x3-mean Wiener blend a* = S_cm_s / S_cm2 (scale-free integer)
step 2 REFINE: damped diagonally-preconditioned integer gradient descent on the full 10-tap
least squares (J tracked from the moments; a step that raises J is reverted + step halved),
starting AT the blend -> the result can only match or beat it on the training distribution.
Classes with too few pairs keep the IDENTITY filter (never invent weights from noise). Emits the table
as GENERATED SOURCE runtime/nx_vcodec_nf_table.nx (vc_nf_load) -- generators, not hand-authored data.
license_tier: ORIGINAL
dependencies 4 imports · 0 importers
imports: nx_syscalls.nxnx_video_codec_wasm.nxnx_vcodec_nf.nxnx_quality_metric.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 18 | const MIN_MAGIC_4096: i64 = 4096 |
| 19 | const MIN_MAGIC_3078: i64 = 3078 |
| 20 | const MIN_MAGIC_4194304: i64 = 4194304 |
| 21 | const MIN_MAGIC_5120: i64 = 5120 |
| 22 | const MIN_MAGIC_5000: i64 = 5000 |
| 23 | const MIN_MAGIC_65536: i64 = 65536 |
| 25 | const TW: i64 = 576 |
| 26 | const TH: i64 = 1024 |
| 27 | const TFRAMES: i64 = 8 |
| 28 | const MIN_PAIRS: i64 = 20000 // below this a class keeps identity (no training on noise) |
| 29 | const GD_ITERS: i64 = 240 |
| 39 | const A_ATA: i64 = 0 |
| 40 | const A_ATB: i64 = 2700 |
| 41 | const A_BTB: i64 = 2970 |
| 42 | const A_CNT: i64 = 2997 |
| 43 | const A_SCM2: i64 = 3024 |
| 44 | const A_SCMS: i64 = 3051 |
functions
| 31 | func tw_(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 32 | func tn(v: i64) -> i64 |
| 49 | func nf_run(yuv: *u8, mode: i64, qp: i64, accT: *i64, accV: *i64, fsplit: i64, enc: *u8, dprev: *u8, dout: *u8, stream: *u8, blk: *i64, mv: *i64, rctx: *i64) -> i64 |
| 183 | func nf_mirror(acc: *i64, bc: i64, M: *i64) -> i64 called by 1: main |
| 201 | func nf_j(M: *i64, atb: *i64, w: *i64) -> i64 called by 1: main |
| 220 | func main() -> i64 |