From 2a2369e38fbe1bf8261968dafc88dac73bdda7ce Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 10 Feb 2026 20:00:26 +0100 Subject: fix: CNN training normalization pipeline consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Training changes:** - Final layer now outputs [0,1] directly with torch.clamp() - Removed denormalization step (was converting [-1,1] to [0,1]) - Network learns [0,1] output natively **Shader generation fixes:** - Layer 0 uses _src variant (5 params, normalizes [0,1] input internally) - Removed pre-normalization of input texture (handled by _src) - Final layer blending: gray_out already [0,1], no denormalization needed - Added generate_conv_src_function() for all kernel sizes - Auto-generates _src variants when exporting (skips if exists) **Cleanup:** - Removed obsolete 4-channel functions from cnn_conv5x5.wgsl - Keep only 7-channel variants (_7to4, _7to1, _7to4_src) **Normalization flow:** [0,1] texture → _src normalizes to [-1,1] → tanh [-1,1] → ... → final conv [0,1] clipped handoff(Claude): CNN normalization pipeline fixed and consistent with training --- workspaces/main/shaders/cnn/cnn_conv3x3.wgsl | 2 +- workspaces/main/shaders/cnn/cnn_conv5x5.wgsl | 56 +--------------------------- 2 files changed, 2 insertions(+), 56 deletions(-) (limited to 'workspaces/main/shaders/cnn') diff --git a/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl b/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl index ebb87b5..96ddf5b 100644 --- a/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl +++ b/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl @@ -144,5 +144,5 @@ fn cnn_conv3x3_7to1( } } - return sum; // Output in [-1,1], needs denormalization + return sum; // Output in [-1,1] } diff --git a/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl b/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl index bfb4ebb..5136740 100644 --- a/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl +++ b/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl @@ -1,57 +1,3 @@ -// 5x5 convolution with 25 samples -// Applies mat4 weights per sample - -fn cnn_conv5x5( - tex: texture_2d, - samp: sampler, - uv: vec2, - resolution: vec2, - weights: array, 25>, - bias: vec4 -) -> vec4 { - let step = 1.0 / resolution; - var sum = bias; - var idx = 0; - - for (var dy = -2; dy <= 2; dy++) { - for (var dx = -2; dx <= 2; dx++) { - let offset = vec2(f32(dx), f32(dy)) * step; - let sample = textureSample(tex, samp, uv + offset); - sum += weights[idx] * sample; - idx++; - } - } - - return sum; -} - -fn cnn_conv5x5_with_coord( - tex: texture_2d, - samp: sampler, - uv: vec2, - resolution: vec2, - rgba_weights: array, 25>, - coord_weights: mat2x4, - bias: vec4 -) -> vec4 { - let step = 1.0 / resolution; - var sum = bias; - - sum += coord_weights * uv; - - var idx = 0; - for (var dy = -2; dy <= 2; dy++) { - for (var dx = -2; dx <= 2; dx++) { - let offset = vec2(f32(dx), f32(dy)) * step; - let rgba = textureSample(tex, samp, uv + offset); - sum += rgba_weights[idx] * rgba; - idx++; - } - } - - return sum; -} - // 5×5 variant for 7→4 channels (RGBD output) // Assumes 'tex' and 'original' are already normalized to [-1,1] // UV coordinates remain in [0,1] and are normalized internally @@ -135,5 +81,5 @@ fn cnn_conv5x5_7to1( } } - return sum; + return sum; // Output in [-1,1] } -- cgit v1.2.3