code wiki / _hdl_build / nx_cross_genre.nx

nx_cross_genre.nx source

↩ module page · 45 lines · 2692 B

1// nx_cross_genre.nx -- "cross genres WITH fidelity": reproduce a source (e.g. an anime frame) in a 2// different genre (e.g. photoreal) while PRESERVING the content -- pose, identity, composition, 3// action. The proof is a MEASUREMENT, content-neutral and genre-pair-agnostic (anime<->realism, 4// photo<->painting, 2D<->3D), built on the classic CONTENT/STYLE decomposition (Gatys 2015): 5// - CONTENT fidelity: structure/pose/identity preserved, STYLE-INVARIANT. Must stay HIGH. 6// - STYLE match: does the output read as the TARGET genre? Must reach the target. 7// - STYLE residual: does it still read as the SOURCE genre? Should be LOW (the genre crossed). 8// A cross-genre reproduction SUCCEEDS iff content is preserved AND the target genre is reached. 9// This is the scorecard that proves the system can carry a subject across genres at >= our current 10// realism level, without quietly losing the subject. license_tier: ORIGINAL Refs: Gatys et al. 11// neural style transfer (content loss vs style loss); domain-translation fidelity. 12 13import "nx_syscalls.nx" 14 15const CG_SUCCESS: i64 = 0 // content preserved AND target genre reached 16const CG_LOST_CONTENT: i64 = 1 // genre crossed but the subject/structure was wrecked 17const CG_WRONG_STYLE: i64 = 2 // content kept but it did not reach the target genre 18 19// the verdict for one cross-genre reproduction. all scores in permil (0..1000). 20func cg_verdict(content_fid: i64, style_target: i64, content_floor: i64, style_floor: i64) -> i64 { 21 if content_fid < content_floor { return CG_LOST_CONTENT } 22 if style_target < style_floor { return CG_WRONG_STYLE } 23 return CG_SUCCESS 24} 25 26// the headline capability: crossed the genre WITHOUT losing fidelity. 27func cg_crossed_with_fidelity(content_fid: i64, style_target: i64, content_floor: i64, style_floor: i64) -> i64 { 28 if cg_verdict(content_fid, style_target, content_floor, style_floor) == CG_SUCCESS { return 1 } 29 return 0 30} 31 32// did the genre actually MOVE? (target reached AND source residual dropped) -- guards against a 33// repaint that claims a new genre while still looking like the old one. 34func cg_genre_moved(style_target: i64, style_source_residual: i64, style_floor: i64) -> i64 { 35 if style_target < style_floor { return 0 } 36 if style_source_residual >= (1000 - style_floor) { return 0 } 37 return 1 38} 39 40// overall cross-genre QUALITY: the min of (content kept, target reached) -- a chain is only as 41// strong as its weakest of the two requirements, so optimizing one at the cost of the other shows. 42func cg_quality(content_fid: i64, style_target: i64) -> i64 { 43 if content_fid < style_target { return content_fid } 44 return style_target 45}