summaryrefslogtreecommitdiff
path: root/training
diff options
context:
space:
mode:
Diffstat (limited to 'training')
-rw-r--r--training/diagnose_255_to_253.md69
-rwxr-xr-xtraining/gen_identity_weights.py13
-rwxr-xr-xtraining/test_viz_precision.py38
3 files changed, 7 insertions, 113 deletions
diff --git a/training/diagnose_255_to_253.md b/training/diagnose_255_to_253.md
deleted file mode 100644
index 764d328..0000000
--- a/training/diagnose_255_to_253.md
+++ /dev/null
@@ -1,69 +0,0 @@
-# Diagnosis: 255 → 253 Loss (-2 LSBs)
-
-## Findings
-
-### F16 Precision
-✅ **No loss:** 1.0 → f16(0x3c00) → 1.0 (exact round-trip)
-
-### Visualization Scale
-⚠️ **Inconsistent:**
-- Layer 1 uses `vizScale = 0.5` (line 1530)
-- Should render as 128, not 253
-- **User seeing 253 suggests viewing Static Features (scale=1.0), not CNN output**
-
-### Suspected Issue: Input Alpha Channel
-
-**Code:** `tools/cnn_v2_test/index.html` line 1233
-```javascript
-depthData[i] = pixels[i * 4 + 3] / 255.0; // Alpha from canvas
-```
-
-**Hypothesis:** Input PNG alpha channel = 253 (not 255)
-- Browsers may set alpha < 255 for certain images
-- Pre-multiplied alpha corrections
-- PNG encoder compression artifacts
-
-### Test
-
-**Check input alpha:**
-```javascript
-// In HTML tool console:
-const canvas = document.createElement('canvas');
-canvas.width = tester.image.width;
-canvas.height = tester.image.height;
-const ctx = canvas.getContext('2d');
-ctx.drawImage(tester.image, 0, 0);
-const imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
-const alpha = imgData.data[3]; // First pixel alpha
-console.log('First pixel alpha:', alpha);
-```
-
-### Alternative: C++ Reference
-
-Check if `cnn_test` tool produces same -2 loss:
-```bash
-# Generate solid white 8×8 test image with alpha=255
-python3 -c "
-from PIL import Image
-import numpy as np
-img = np.ones((8, 8, 4), dtype=np.uint8) * 255
-Image.fromarray(img, 'RGBA').save('test_white_255.png')
-print('Created test_white_255.png: all pixels RGBA=(255,255,255,255)')
-"
-
-# Test with HTML tool → check if p3 = 1.0 or 0.9921875
-# Test with cnn_test → compare output
-./build/cnn_test test_white_255.png output.png --cnn-version 2 --debug-hex
-```
-
-### Next Steps
-
-1. **Verify input:** Check alpha channel of user's input image
-2. **Add debug:** Log first pixel RGBA values in HTML tool
-3. **Compare:** Run same image through C++ cnn_test
-4. **Isolate:** Test with synthetic 255 alpha image
-
-## Conclusion
-
-**Most likely:** Input image alpha ≠ 255, already 253 before CNN processing.
-**Verify:** User should check input PNG metadata and alpha channel values.
diff --git a/training/gen_identity_weights.py b/training/gen_identity_weights.py
index 5d83bfb..7865d68 100755
--- a/training/gen_identity_weights.py
+++ b/training/gen_identity_weights.py
@@ -4,8 +4,8 @@
Creates trivial .bin with 1 layer, 1×1 kernel, identity passthrough.
Output Ch{0,1,2,3} = Input Ch{0,1,2,3} (ignores static features).
-With --mix: Output Ch{i} = 0.5*Input Ch{i} + 0.5*Input Ch{i+4}
- (50-50 blend, avoids overflow)
+With --mix: Output Ch{i} = 0.5*prev[i] + 0.5*static_p{4+i}
+ (50-50 blend of prev layer with uv_x, uv_y, sin20_y, bias)
With --p47: Output Ch{i} = static p{4+i} (uv_x, uv_y, sin20_y, bias)
(p4/uv_x→ch0, p5/uv_y→ch1, p6/sin20_y→ch2, p7/bias→ch3)
@@ -69,10 +69,11 @@ def generate_identity_weights(output_path, kernel_size=1, mip_level=0, mix=False
for i in range(out_channels):
weights[i, i + 8, center, center] = 1.0
elif mix:
- # Mix mode: 50-50 blend to avoid overflow
+ # Mix mode: 50-50 blend (p0+p4, p1+p5, p2+p6, p3+p7)
+ # p0-p3 are at channels 0-3 (prev layer), p4-p7 at channels 8-11 (static)
for i in range(out_channels):
- weights[i, i, center, center] = 0.5 # 0.5*p{i}
- weights[i, i + 4, center, center] = 0.5 # 0.5*p{i+4}
+ weights[i, i, center, center] = 0.5 # 0.5*p{i} (prev layer)
+ weights[i, i + 8, center, center] = 0.5 # 0.5*p{i+4} (static)
else:
# Identity: output ch i = input ch i
for i in range(out_channels):
@@ -89,7 +90,7 @@ def generate_identity_weights(output_path, kernel_size=1, mip_level=0, mix=False
print(f" Weights: {weight_count}")
print(f" Mip level: {mip_level}")
if mix:
- print(f" Mode: 0.5*p0+0.5*p4, 0.5*p1+0.5*p5, 0.5*p2+0.5*p6, 0.5*p3+0.5*p7")
+ print(f" Mode: 0.5*prev[i] + 0.5*static_p{{4+i}} (blend with uv/sin/bias)")
elif p47:
print(f" Mode: p4→ch0, p5→ch1, p6→ch2, p7→ch3")
diff --git a/training/test_viz_precision.py b/training/test_viz_precision.py
deleted file mode 100755
index 143f4ea..0000000
--- a/training/test_viz_precision.py
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env python3
-"""Test WebGPU → Canvas → PNG precision loss
-
-Check if bgra8unorm → 2D canvas → PNG loses 2 LSBs.
-"""
-
-import numpy as np
-
-# Simulate WebGPU bgra8unorm conversion
-# Float [0, 1] → uint8 [0, 255]
-
-test_values = [
- 1.0, # Perfect white
- 0.9999, # Near-white
- 254.5/255, # Exactly 254.5
- 253.5/255, # Exactly 253.5
-]
-
-for val in test_values:
- # WebGPU bgra8unorm: round(val * 255)
- gpu_u8 = int(np.round(val * 255))
-
- # Convert back to normalized
- gpu_f32 = gpu_u8 / 255.0
-
- # JavaScript canvas getImageData: uint8
- canvas_u8 = int(np.round(gpu_f32 * 255))
-
- print(f"Input: {val:.6f} → GPU u8: {gpu_u8} → Canvas: {canvas_u8}")
- if canvas_u8 != 255:
- print(f" ⚠️ Lost {255 - canvas_u8} LSBs")
-
-print("\nConclusion:")
-print("If WebGPU stores 1.0 as 255, canvas should read 255.")
-print("If user sees 253, likely:")
-print(" a) Not viewing CNN layer (viewing static features at scale=1.0)")
-print(" b) Value in texture is already 253/255 = 0.9921875")
-print(" c) F16 storage or unpacking issue")