summaryrefslogtreecommitdiff
path: root/tools/cnn_v2_test/index.html
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-14 02:12:12 +0100
committerskal <pascal.massimino@gmail.com>2026-02-14 02:12:12 +0100
commit043044ae7563c2f92760c428765e35b411da82ea (patch)
tree0d640fec1517169d195747707b6c589c92fe7161 /tools/cnn_v2_test/index.html
parent4d119a1b6a6f460ca6d5a8ef85176c45663fd40a (diff)
Replace hard clamp with sigmoid activation in CNN v2
Fixes training collapse where p1/p2 channels saturate due to gradient blocking at clamp boundaries. Sigmoid provides smooth [0,1] mapping with continuous gradients. Changes: - Layer 0: clamp(x, 0, 1) → sigmoid(x) - Final layer: clamp(x, 0, 1) → sigmoid(x) - Middle layers: ReLU unchanged (already stable) Updated files: - training/train_cnn_v2.py: PyTorch model activations - workspaces/main/shaders/cnn_v2/cnn_v2_compute.wgsl: WGSL shader - tools/cnn_v2_test/index.html: HTML validation tool - doc/CNN_V2.md: Documentation Validation: - Build clean (no shader errors) - 34/36 tests pass (2 unrelated script tests fail) - 10-epoch training: loss 0.153 → 0.088 (good convergence) - cnn_test processes images successfully Breaking change: Old checkpoints trained with clamp() incompatible. Retrain from scratch required. handoff(Claude): CNN v2 sigmoid activation implemented and validated.
Diffstat (limited to 'tools/cnn_v2_test/index.html')
-rw-r--r--tools/cnn_v2_test/index.html8
1 files changed, 3 insertions, 5 deletions
diff --git a/tools/cnn_v2_test/index.html b/tools/cnn_v2_test/index.html
index 1dd2e78..2ec934d 100644
--- a/tools/cnn_v2_test/index.html
+++ b/tools/cnn_v2_test/index.html
@@ -543,12 +543,10 @@ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
}
}
- if (is_output) {
- output[c] = clamp(sum, 0.0, 1.0);
- } else if (params.is_layer_0 != 0u) {
- output[c] = clamp(sum, 0.0, 1.0); // Layer 0: clamp [0,1]
+ if (is_output || params.is_layer_0 != 0u) {
+ output[c] = 1.0 / (1.0 + exp(-sum)); // Sigmoid [0,1]
} else {
- output[c] = max(0.0, sum); // Middle layers: ReLU
+ output[c] = max(0.0, sum); // ReLU
}
}