diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-13 16:48:02 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-13 16:48:02 +0100 |
| commit | ced248b0a8973db6d11b79e8290e2f5bb17ffcaa (patch) | |
| tree | 938899c02408895124fb8e9751dbd36b50d4a0ba /training/export_cnn_v2_weights.py | |
| parent | 3eed58f0cd602298681a2313946ba2a5824d6c6e (diff) | |
CNN v2: Add mip-level support to runtime effect
Binary format v2 includes mip_level in header (20 bytes, was 16).
Effect reads mip_level and passes to static features shader via uniform.
Shader samples from correct mip texture based on mip_level.
Changes:
- export_cnn_v2_weights.py: Header v2 with mip_level field
- cnn_v2_effect.h: Add StaticFeatureParams, mip_level member, params buffer
- cnn_v2_effect.cc: Read mip_level from weights, create/bind params buffer, update per-frame
- cnn_v2_static.wgsl: Accept params uniform, sample from selected mip level
Binary format v2:
- Header: 20 bytes (magic, version=2, num_layers, total_weights, mip_level)
- Backward compatible: v1 weights load with mip_level=0
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'training/export_cnn_v2_weights.py')
| -rwxr-xr-x | training/export_cnn_v2_weights.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/training/export_cnn_v2_weights.py b/training/export_cnn_v2_weights.py index 9e9e352..1086516 100755 --- a/training/export_cnn_v2_weights.py +++ b/training/export_cnn_v2_weights.py @@ -16,11 +16,12 @@ def export_weights_binary(checkpoint_path, output_path): """Export CNN v2 weights to binary format. Binary format: - Header (16 bytes): + Header (20 bytes): uint32 magic ('CNN2') - uint32 version (1) + uint32 version (2) uint32 num_layers uint32 total_weights (f16 count) + uint32 mip_level (0-3) LayerInfo × num_layers (20 bytes each): uint32 kernel_size @@ -107,19 +108,20 @@ def export_weights_binary(checkpoint_path, output_path): print(f" Total layers: {len(layers)}") print(f" Total weights: {len(all_weights_f16)} (f16)") print(f" Packed: {len(weights_u32)} u32") - print(f" Binary size: {16 + len(layers) * 20 + len(weights_u32) * 4} bytes") + print(f" Binary size: {20 + len(layers) * 20 + len(weights_u32) * 4} bytes") # Write binary file output_path = Path(output_path) output_path.parent.mkdir(parents=True, exist_ok=True) with open(output_path, 'wb') as f: - # Header (16 bytes) - f.write(struct.pack('<4sIII', + # Header (20 bytes) - version 2 with mip_level + f.write(struct.pack('<4sIIII', b'CNN2', # magic - 1, # version + 2, # version (bumped to 2) len(layers), # num_layers - len(all_weights_f16))) # total_weights (f16 count) + len(all_weights_f16), # total_weights (f16 count) + mip_level)) # mip_level # Layer info (20 bytes per layer) for layer in layers: |
