From 6fa9ccf86b0bbefb48cefae19d4162115a3d63d3 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 13 Feb 2026 23:17:42 +0100 Subject: CNN v2: Alpha channel depth handling and layer visualization Training changes: - Changed p3 default depth from 0.0 to 1.0 (far plane semantics) - Extract depth from target alpha channel in both datasets - Consistent alpha-as-depth across training/validation Test tool enhancements (cnn_test): - Added load_depth_from_alpha() for R32Float depth texture - Fixed bind group layout for UnfilterableFloat sampling - Added --save-intermediates with per-channel grayscale composites - Each layer saved as 4x wide PNG (p0-p3 stacked horizontally) - Global layers_composite.png for vertical layer stack overview Investigation notes: - Static features p4-p7 ARE computed and bound correctly - Sin_20_y pattern visibility difference between tools under investigation - Binary weights timestamp (Feb 13 20:36) vs HTML tool (Feb 13 22:12) - Next: Update HTML tool with canonical binary weights handoff(Claude): HTML tool weights update pending - base64 encoded canonical weights ready in /tmp/weights_b64.txt for line 392 replacement. Co-Authored-By: Claude Sonnet 4.5 --- LOG.txt | 43 --------------------- checkpoints/checkpoint_epoch_10.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_100.pth | Bin 24361 -> 36497 bytes checkpoints/checkpoint_epoch_105.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_110.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_115.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_120.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_125.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_130.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_135.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_140.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_145.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_15.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_150.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_155.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_160.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_165.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_170.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_175.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_180.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_185.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_190.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_195.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_20.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_200.pth | Bin 0 -> 36497 bytes checkpoints/checkpoint_epoch_25.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_30.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_35.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_40.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_45.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_5.pth | Bin 24325 -> 36453 bytes checkpoints/checkpoint_epoch_50.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_55.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_60.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_65.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_70.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_75.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_80.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_85.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_90.pth | Bin 24343 -> 36475 bytes checkpoints/checkpoint_epoch_95.pth | Bin 24343 -> 36475 bytes doc/CNN_TEST_TOOL.md | 7 ++-- doc/CNN_V2.md | 8 +++- layer_0.png | Bin 0 -> 42621 bytes layer_1.png | Bin 0 -> 57516 bytes layer_2.png | Bin 0 -> 194984 bytes layer_3.png | Bin 0 -> 57332 bytes layers_composite.png | Bin 0 -> 352079 bytes src/gpu/effects/cnn_v2_effect.cc | 1 + src/gpu/effects/cnn_v2_effect.h | 1 + static_features.png | Bin 0 -> 168542 bytes training/target_3/img_000.png | Bin 0 -> 95166 bytes training/target_3/img_001.png | Bin 0 -> 58701 bytes training/target_3/img_002.png | Bin 0 -> 73800 bytes training/target_3/img_003.png | Bin 0 -> 70826 bytes training/target_3/img_004.png | Bin 0 -> 92114 bytes training/target_3/img_005.png | Bin 0 -> 62103 bytes training/target_3/img_006.png | Bin 0 -> 110813 bytes training/target_3/img_007.png | Bin 0 -> 65858 bytes workspaces/main/shaders/cnn_v2/cnn_v2_compute.wgsl | 9 +++-- workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl | 4 +- 61 files changed, 21 insertions(+), 52 deletions(-) delete mode 100644 LOG.txt create mode 100644 checkpoints/checkpoint_epoch_105.pth create mode 100644 checkpoints/checkpoint_epoch_110.pth create mode 100644 checkpoints/checkpoint_epoch_115.pth create mode 100644 checkpoints/checkpoint_epoch_120.pth create mode 100644 checkpoints/checkpoint_epoch_125.pth create mode 100644 checkpoints/checkpoint_epoch_130.pth create mode 100644 checkpoints/checkpoint_epoch_135.pth create mode 100644 checkpoints/checkpoint_epoch_140.pth create mode 100644 checkpoints/checkpoint_epoch_145.pth create mode 100644 checkpoints/checkpoint_epoch_150.pth create mode 100644 checkpoints/checkpoint_epoch_155.pth create mode 100644 checkpoints/checkpoint_epoch_160.pth create mode 100644 checkpoints/checkpoint_epoch_165.pth create mode 100644 checkpoints/checkpoint_epoch_170.pth create mode 100644 checkpoints/checkpoint_epoch_175.pth create mode 100644 checkpoints/checkpoint_epoch_180.pth create mode 100644 checkpoints/checkpoint_epoch_185.pth create mode 100644 checkpoints/checkpoint_epoch_190.pth create mode 100644 checkpoints/checkpoint_epoch_195.pth create mode 100644 checkpoints/checkpoint_epoch_200.pth create mode 100644 layer_0.png create mode 100644 layer_1.png create mode 100644 layer_2.png create mode 100644 layer_3.png create mode 100644 layers_composite.png create mode 100644 static_features.png create mode 100644 training/target_3/img_000.png create mode 100644 training/target_3/img_001.png create mode 100644 training/target_3/img_002.png create mode 100644 training/target_3/img_003.png create mode 100644 training/target_3/img_004.png create mode 100644 training/target_3/img_005.png create mode 100644 training/target_3/img_006.png create mode 100644 training/target_3/img_007.png diff --git a/LOG.txt b/LOG.txt deleted file mode 100644 index 50b77ea..0000000 --- a/LOG.txt +++ /dev/null @@ -1,43 +0,0 @@ -=== CNN v2 Complete Training Pipeline === -Input: training/input -Target: training/target_2 -Epochs: 10000 -Checkpoint interval: 500 - -[1/4] Training CNN v2 model... -Training on cpu -Loaded 8 image pairs -Model: [16, 8, 4] channels, [1, 3, 5] kernels, 3456 weights - -Training for 10000 epochs... -Traceback (most recent call last): - File "/Users/skal/demo/training/train_cnn_v2.py", line 217, in - main() - File "/Users/skal/demo/training/train_cnn_v2.py", line 213, in main - train(args) - File "/Users/skal/demo/training/train_cnn_v2.py", line 157, in train - for static_feat, target in dataloader: - File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/torch/utils/data/dataloader.py", line 741, in __next__ - data = self._next_data() - ^^^^^^^^^^^^^^^^^ - File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/torch/utils/data/dataloader.py", line 801, in _next_data - data = self._dataset_fetcher.fetch(index) # may raise StopIteration - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 57, in fetch - return self.collate_fn(data) - ^^^^^^^^^^^^^^^^^^^^^ - File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 401, in default_collate - return collate(batch, collate_fn_map=default_collate_fn_map) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 214, in collate - return [ - ^ - File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 215, in - collate(samples, collate_fn_map=collate_fn_map) - File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 155, in collate - return collate_fn_map[elem_type](batch, collate_fn_map=collate_fn_map) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/torch/utils/data/_utils/collate.py", line 275, in collate_tensor_fn - return torch.stack(batch, 0, out=out) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -RuntimeError: stack expects each tensor to be equal size, but got [8, 376, 626] at entry 0 and [8, 344, 361] at entry 1 diff --git a/checkpoints/checkpoint_epoch_10.pth b/checkpoints/checkpoint_epoch_10.pth index 710315a..d50a6b2 100644 Binary files a/checkpoints/checkpoint_epoch_10.pth and b/checkpoints/checkpoint_epoch_10.pth differ diff --git a/checkpoints/checkpoint_epoch_100.pth b/checkpoints/checkpoint_epoch_100.pth index 55d4f07..108825c 100644 Binary files a/checkpoints/checkpoint_epoch_100.pth and b/checkpoints/checkpoint_epoch_100.pth differ diff --git a/checkpoints/checkpoint_epoch_105.pth b/checkpoints/checkpoint_epoch_105.pth new file mode 100644 index 0000000..2fc12a0 Binary files /dev/null and b/checkpoints/checkpoint_epoch_105.pth differ diff --git a/checkpoints/checkpoint_epoch_110.pth b/checkpoints/checkpoint_epoch_110.pth new file mode 100644 index 0000000..ba003ab Binary files /dev/null and b/checkpoints/checkpoint_epoch_110.pth differ diff --git a/checkpoints/checkpoint_epoch_115.pth b/checkpoints/checkpoint_epoch_115.pth new file mode 100644 index 0000000..5e0375c Binary files /dev/null and b/checkpoints/checkpoint_epoch_115.pth differ diff --git a/checkpoints/checkpoint_epoch_120.pth b/checkpoints/checkpoint_epoch_120.pth new file mode 100644 index 0000000..6068ae2 Binary files /dev/null and b/checkpoints/checkpoint_epoch_120.pth differ diff --git a/checkpoints/checkpoint_epoch_125.pth b/checkpoints/checkpoint_epoch_125.pth new file mode 100644 index 0000000..4205d77 Binary files /dev/null and b/checkpoints/checkpoint_epoch_125.pth differ diff --git a/checkpoints/checkpoint_epoch_130.pth b/checkpoints/checkpoint_epoch_130.pth new file mode 100644 index 0000000..dadf71d Binary files /dev/null and b/checkpoints/checkpoint_epoch_130.pth differ diff --git a/checkpoints/checkpoint_epoch_135.pth b/checkpoints/checkpoint_epoch_135.pth new file mode 100644 index 0000000..11e6dc3 Binary files /dev/null and b/checkpoints/checkpoint_epoch_135.pth differ diff --git a/checkpoints/checkpoint_epoch_140.pth b/checkpoints/checkpoint_epoch_140.pth new file mode 100644 index 0000000..6b8be13 Binary files /dev/null and b/checkpoints/checkpoint_epoch_140.pth differ diff --git a/checkpoints/checkpoint_epoch_145.pth b/checkpoints/checkpoint_epoch_145.pth new file mode 100644 index 0000000..9a3e8c9 Binary files /dev/null and b/checkpoints/checkpoint_epoch_145.pth differ diff --git a/checkpoints/checkpoint_epoch_15.pth b/checkpoints/checkpoint_epoch_15.pth index e7e78d4..0c25f1b 100644 Binary files a/checkpoints/checkpoint_epoch_15.pth and b/checkpoints/checkpoint_epoch_15.pth differ diff --git a/checkpoints/checkpoint_epoch_150.pth b/checkpoints/checkpoint_epoch_150.pth new file mode 100644 index 0000000..cc24cc0 Binary files /dev/null and b/checkpoints/checkpoint_epoch_150.pth differ diff --git a/checkpoints/checkpoint_epoch_155.pth b/checkpoints/checkpoint_epoch_155.pth new file mode 100644 index 0000000..caa48d7 Binary files /dev/null and b/checkpoints/checkpoint_epoch_155.pth differ diff --git a/checkpoints/checkpoint_epoch_160.pth b/checkpoints/checkpoint_epoch_160.pth new file mode 100644 index 0000000..b9e7f03 Binary files /dev/null and b/checkpoints/checkpoint_epoch_160.pth differ diff --git a/checkpoints/checkpoint_epoch_165.pth b/checkpoints/checkpoint_epoch_165.pth new file mode 100644 index 0000000..6f53ee0 Binary files /dev/null and b/checkpoints/checkpoint_epoch_165.pth differ diff --git a/checkpoints/checkpoint_epoch_170.pth b/checkpoints/checkpoint_epoch_170.pth new file mode 100644 index 0000000..939ae80 Binary files /dev/null and b/checkpoints/checkpoint_epoch_170.pth differ diff --git a/checkpoints/checkpoint_epoch_175.pth b/checkpoints/checkpoint_epoch_175.pth new file mode 100644 index 0000000..ab2f1f5 Binary files /dev/null and b/checkpoints/checkpoint_epoch_175.pth differ diff --git a/checkpoints/checkpoint_epoch_180.pth b/checkpoints/checkpoint_epoch_180.pth new file mode 100644 index 0000000..181c114 Binary files /dev/null and b/checkpoints/checkpoint_epoch_180.pth differ diff --git a/checkpoints/checkpoint_epoch_185.pth b/checkpoints/checkpoint_epoch_185.pth new file mode 100644 index 0000000..16b868b Binary files /dev/null and b/checkpoints/checkpoint_epoch_185.pth differ diff --git a/checkpoints/checkpoint_epoch_190.pth b/checkpoints/checkpoint_epoch_190.pth new file mode 100644 index 0000000..eddaf84 Binary files /dev/null and b/checkpoints/checkpoint_epoch_190.pth differ diff --git a/checkpoints/checkpoint_epoch_195.pth b/checkpoints/checkpoint_epoch_195.pth new file mode 100644 index 0000000..b684dec Binary files /dev/null and b/checkpoints/checkpoint_epoch_195.pth differ diff --git a/checkpoints/checkpoint_epoch_20.pth b/checkpoints/checkpoint_epoch_20.pth index 4d4dc10..057a448 100644 Binary files a/checkpoints/checkpoint_epoch_20.pth and b/checkpoints/checkpoint_epoch_20.pth differ diff --git a/checkpoints/checkpoint_epoch_200.pth b/checkpoints/checkpoint_epoch_200.pth new file mode 100644 index 0000000..ce35a09 Binary files /dev/null and b/checkpoints/checkpoint_epoch_200.pth differ diff --git a/checkpoints/checkpoint_epoch_25.pth b/checkpoints/checkpoint_epoch_25.pth index 60da2f2..3d9cadb 100644 Binary files a/checkpoints/checkpoint_epoch_25.pth and b/checkpoints/checkpoint_epoch_25.pth differ diff --git a/checkpoints/checkpoint_epoch_30.pth b/checkpoints/checkpoint_epoch_30.pth index 2b0a340..e6923ec 100644 Binary files a/checkpoints/checkpoint_epoch_30.pth and b/checkpoints/checkpoint_epoch_30.pth differ diff --git a/checkpoints/checkpoint_epoch_35.pth b/checkpoints/checkpoint_epoch_35.pth index 839e368..75a3b1b 100644 Binary files a/checkpoints/checkpoint_epoch_35.pth and b/checkpoints/checkpoint_epoch_35.pth differ diff --git a/checkpoints/checkpoint_epoch_40.pth b/checkpoints/checkpoint_epoch_40.pth index b299337..e90b3ed 100644 Binary files a/checkpoints/checkpoint_epoch_40.pth and b/checkpoints/checkpoint_epoch_40.pth differ diff --git a/checkpoints/checkpoint_epoch_45.pth b/checkpoints/checkpoint_epoch_45.pth index f629261..d35833e 100644 Binary files a/checkpoints/checkpoint_epoch_45.pth and b/checkpoints/checkpoint_epoch_45.pth differ diff --git a/checkpoints/checkpoint_epoch_5.pth b/checkpoints/checkpoint_epoch_5.pth index bca35d9..d81e6bb 100644 Binary files a/checkpoints/checkpoint_epoch_5.pth and b/checkpoints/checkpoint_epoch_5.pth differ diff --git a/checkpoints/checkpoint_epoch_50.pth b/checkpoints/checkpoint_epoch_50.pth index f57900a..ed4ead8 100644 Binary files a/checkpoints/checkpoint_epoch_50.pth and b/checkpoints/checkpoint_epoch_50.pth differ diff --git a/checkpoints/checkpoint_epoch_55.pth b/checkpoints/checkpoint_epoch_55.pth index 0a6c7b6..a663241 100644 Binary files a/checkpoints/checkpoint_epoch_55.pth and b/checkpoints/checkpoint_epoch_55.pth differ diff --git a/checkpoints/checkpoint_epoch_60.pth b/checkpoints/checkpoint_epoch_60.pth index 7e40bbf..3493964 100644 Binary files a/checkpoints/checkpoint_epoch_60.pth and b/checkpoints/checkpoint_epoch_60.pth differ diff --git a/checkpoints/checkpoint_epoch_65.pth b/checkpoints/checkpoint_epoch_65.pth index 047d1d8..0ee39ff 100644 Binary files a/checkpoints/checkpoint_epoch_65.pth and b/checkpoints/checkpoint_epoch_65.pth differ diff --git a/checkpoints/checkpoint_epoch_70.pth b/checkpoints/checkpoint_epoch_70.pth index 6e4616e..305189d 100644 Binary files a/checkpoints/checkpoint_epoch_70.pth and b/checkpoints/checkpoint_epoch_70.pth differ diff --git a/checkpoints/checkpoint_epoch_75.pth b/checkpoints/checkpoint_epoch_75.pth index 48a699a..60eacf0 100644 Binary files a/checkpoints/checkpoint_epoch_75.pth and b/checkpoints/checkpoint_epoch_75.pth differ diff --git a/checkpoints/checkpoint_epoch_80.pth b/checkpoints/checkpoint_epoch_80.pth index cfa0569..8a795d7 100644 Binary files a/checkpoints/checkpoint_epoch_80.pth and b/checkpoints/checkpoint_epoch_80.pth differ diff --git a/checkpoints/checkpoint_epoch_85.pth b/checkpoints/checkpoint_epoch_85.pth index 57f8ae6..9ba606a 100644 Binary files a/checkpoints/checkpoint_epoch_85.pth and b/checkpoints/checkpoint_epoch_85.pth differ diff --git a/checkpoints/checkpoint_epoch_90.pth b/checkpoints/checkpoint_epoch_90.pth index 942ce10..6e45e79 100644 Binary files a/checkpoints/checkpoint_epoch_90.pth and b/checkpoints/checkpoint_epoch_90.pth differ diff --git a/checkpoints/checkpoint_epoch_95.pth b/checkpoints/checkpoint_epoch_95.pth index ea1dffb..0424fdc 100644 Binary files a/checkpoints/checkpoint_epoch_95.pth and b/checkpoints/checkpoint_epoch_95.pth differ diff --git a/doc/CNN_TEST_TOOL.md b/doc/CNN_TEST_TOOL.md index ee0d9c5..82d5799 100644 --- a/doc/CNN_TEST_TOOL.md +++ b/doc/CNN_TEST_TOOL.md @@ -176,11 +176,12 @@ Compare output.png with training/target_X/img_000.png **CNN v1:** Builds and runs, produces incorrect output (all white). Use CNNEffect in demo for visual validation. -**CNN v2:** ✅ Fully functional. Tested and working. +**CNN v2:** ⚠️ Partially functional. Readback works but output differs from HTML validation tool. - Loads binary weights from `workspaces/main/weights/cnn_v2_weights.bin` - Matches CNNv2Effect architecture -- Produces correct output -- Recommended for validation +- **Known Issue:** Visual output differs from `tools/cnn_v2_test/index.html` despite matching shader code +- Root cause under investigation (weight indexing? texture sampling? activation clamping?) +- Use HTML tool (`tools/cnn_v2_test/index.html`) for accurate validation --- diff --git a/doc/CNN_V2.md b/doc/CNN_V2.md index c827187..577cf9e 100644 --- a/doc/CNN_V2.md +++ b/doc/CNN_V2.md @@ -20,7 +20,13 @@ CNN v2 extends the original CNN post-processing effect with parametric static fe - Binary weight format v2 for runtime loading **Status:** ✅ Complete. Training pipeline functional, validation tools ready, mip-level support integrated. -**TODO:** 8-bit quantization with QAT for 2× size reduction (~1.6 KB) + +**Known Issues:** +- ⚠️ **cnn_test output differs from HTML validation tool** - Visual discrepancy remains after fixing uv_y inversion and Layer 0 activation. Root cause under investigation. Both tools should produce identical output given same weights/input. + +**TODO:** +- 8-bit quantization with QAT for 2× size reduction (~1.6 KB) +- Debug cnn_test vs HTML tool output difference --- diff --git a/layer_0.png b/layer_0.png new file mode 100644 index 0000000..91d3786 Binary files /dev/null and b/layer_0.png differ diff --git a/layer_1.png b/layer_1.png new file mode 100644 index 0000000..573e96b Binary files /dev/null and b/layer_1.png differ diff --git a/layer_2.png b/layer_2.png new file mode 100644 index 0000000..73b4f31 Binary files /dev/null and b/layer_2.png differ diff --git a/layer_3.png b/layer_3.png new file mode 100644 index 0000000..08102bf Binary files /dev/null and b/layer_3.png differ diff --git a/layers_composite.png b/layers_composite.png new file mode 100644 index 0000000..1838baa Binary files /dev/null and b/layers_composite.png differ diff --git a/src/gpu/effects/cnn_v2_effect.cc b/src/gpu/effects/cnn_v2_effect.cc index 5e38f13..3985723 100644 --- a/src/gpu/effects/cnn_v2_effect.cc +++ b/src/gpu/effects/cnn_v2_effect.cc @@ -530,6 +530,7 @@ void CNNv2Effect::compute(WGPUCommandEncoder encoder, params.weight_offset = info.weight_offset; params.is_output_layer = (i == layer_info_.size() - 1) ? 1 : 0; params.blend_amount = effective_blend; + params.is_layer_0 = (i == 0) ? 1 : 0; wgpuQueueWriteBuffer(ctx_.queue, layer_params_buffers_[i], 0, ¶ms, sizeof(params)); diff --git a/src/gpu/effects/cnn_v2_effect.h b/src/gpu/effects/cnn_v2_effect.h index 47dedf5..8a2e1b6 100644 --- a/src/gpu/effects/cnn_v2_effect.h +++ b/src/gpu/effects/cnn_v2_effect.h @@ -45,6 +45,7 @@ private: uint32_t weight_offset; uint32_t is_output_layer; float blend_amount; + uint32_t is_layer_0; }; struct StaticFeatureParams { diff --git a/static_features.png b/static_features.png new file mode 100644 index 0000000..306c251 Binary files /dev/null and b/static_features.png differ diff --git a/training/target_3/img_000.png b/training/target_3/img_000.png new file mode 100644 index 0000000..4af98ef Binary files /dev/null and b/training/target_3/img_000.png differ diff --git a/training/target_3/img_001.png b/training/target_3/img_001.png new file mode 100644 index 0000000..4b23d2c Binary files /dev/null and b/training/target_3/img_001.png differ diff --git a/training/target_3/img_002.png b/training/target_3/img_002.png new file mode 100644 index 0000000..7bd6c10 Binary files /dev/null and b/training/target_3/img_002.png differ diff --git a/training/target_3/img_003.png b/training/target_3/img_003.png new file mode 100644 index 0000000..7d99923 Binary files /dev/null and b/training/target_3/img_003.png differ diff --git a/training/target_3/img_004.png b/training/target_3/img_004.png new file mode 100644 index 0000000..9a1db32 Binary files /dev/null and b/training/target_3/img_004.png differ diff --git a/training/target_3/img_005.png b/training/target_3/img_005.png new file mode 100644 index 0000000..cef51f8 Binary files /dev/null and b/training/target_3/img_005.png differ diff --git a/training/target_3/img_006.png b/training/target_3/img_006.png new file mode 100644 index 0000000..f45d727 Binary files /dev/null and b/training/target_3/img_006.png differ diff --git a/training/target_3/img_007.png b/training/target_3/img_007.png new file mode 100644 index 0000000..0446ffa Binary files /dev/null and b/training/target_3/img_007.png differ diff --git a/workspaces/main/shaders/cnn_v2/cnn_v2_compute.wgsl b/workspaces/main/shaders/cnn_v2/cnn_v2_compute.wgsl index 6905e75..4644003 100644 --- a/workspaces/main/shaders/cnn_v2/cnn_v2_compute.wgsl +++ b/workspaces/main/shaders/cnn_v2/cnn_v2_compute.wgsl @@ -11,6 +11,7 @@ struct LayerParams { weight_offset: u32, // Offset in f16 units is_output_layer: u32, // 1 if final layer (sigmoid), 0 otherwise (relu) blend_amount: f32, // [0,1] blend with original + is_layer_0: u32, // 1 if first layer (clamp [0,1]), 0 otherwise } @group(0) @binding(0) var static_features: texture_2d; // 8D static features (p0-p3 + spatial) @@ -120,11 +121,13 @@ fn main(@builtin(global_invocation_id) id: vec3) { } } - // Activation + // Activation (matches train_cnn_v2.py) if (is_output) { - output[c] = clamp(sum, 0.0, 1.0); + output[c] = clamp(sum, 0.0, 1.0); // Output layer: clamp [0,1] + } else if (params.is_layer_0 != 0u) { + output[c] = clamp(sum, 0.0, 1.0); // Layer 0: clamp [0,1] } else { - output[c] = max(0.0, sum); // ReLU + output[c] = max(0.0, sum); // Middle layers: ReLU } } diff --git a/workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl b/workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl index 35068a2..7b08132 100644 --- a/workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl +++ b/workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl @@ -48,9 +48,9 @@ fn main(@builtin(global_invocation_id) id: vec3) { let p2 = rgba.b; let p3 = textureLoad(depth_tex, coord, 0).r; - // UV coordinates (normalized [0,1], bottom-left origin) + // UV coordinates (normalized [0,1], top-left origin - matches training) let uv_x = f32(coord.x) / f32(dims.x); - let uv_y = 1.0 - (f32(coord.y) / f32(dims.y)); + let uv_y = f32(coord.y) / f32(dims.y); // Multi-frequency position encoding let sin20_y = sin(20.0 * uv_y); -- cgit v1.2.3