diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-13 16:50:52 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-13 16:50:52 +0100 |
| commit | 250491dc3044549edee8418d680d1e47920833f4 (patch) | |
| tree | 66b2f21a7538821f3d50c573b4409fa4a901f4c2 /tools/cnn_v2_test | |
| parent | ced248b0a8973db6d11b79e8290e2f5bb17ffcaa (diff) | |
CNN v2 HTML tool: Support binary format v2 with mip_level
Parse v2 header (20 bytes) and read mip_level field.
Display mip_level in metadata panel, set UI dropdown on load.
Changes:
- parseWeights(): Handle v1 (16-byte) and v2 (20-byte) headers
- Read mip_level from header[4] for version 2
- Return mipLevel in parsed weights object
- updateWeightsPanel(): Display mip level in metadata
- loadWeights(): Set this.mipLevel and update UI dropdown
Backward compatible: v1 weights → mipLevel=0
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/cnn_v2_test')
| -rw-r--r-- | tools/cnn_v2_test/index.html | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/tools/cnn_v2_test/index.html b/tools/cnn_v2_test/index.html index c112905..88c4733 100644 --- a/tools/cnn_v2_test/index.html +++ b/tools/cnn_v2_test/index.html @@ -723,11 +723,22 @@ class CNNTester { const numLayers = view.getUint32(8, true); const totalWeights = view.getUint32(12, true); - this.log(`Binary header: version=${version}, layers=${numLayers}, weights=${totalWeights}`); + // Version 2: added mip_level field (20-byte header) + let mipLevel = 0; + let headerSize = 16; + if (version === 2) { + mipLevel = view.getUint32(16, true); + headerSize = 20; + this.log(`Binary header: version=${version}, layers=${numLayers}, weights=${totalWeights}, mip_level=${mipLevel}`); + } else if (version === 1) { + this.log(`Binary header: version=${version}, layers=${numLayers}, weights=${totalWeights}`); + } else { + throw new Error(`Unsupported binary version: ${version}`); + } const layers = []; for (let i = 0; i < numLayers; i++) { - const offset = 16 + i * 20; + const offset = headerSize + i * 20; const layer = { kernelSize: view.getUint32(offset, true), inChannels: view.getUint32(offset + 4, true), @@ -739,7 +750,7 @@ class CNNTester { this.log(` Layer ${i}: ${layer.inChannels}→${layer.outChannels}, kernel=${layer.kernelSize}×${layer.kernelSize}, weights=${layer.weightCount}`); } - const weightsOffset = 16 + numLayers * 20; + const weightsOffset = headerSize + numLayers * 20; const weights = new Uint32Array(buffer.slice(weightsOffset)); // Calculate min/max per layer @@ -769,7 +780,7 @@ class CNNTester { } this.log(` Weight buffer: ${weights.length} u32 (${nonZero} non-zero)`); - return { layers, weights, fileSize: buffer.byteLength }; + return { layers, weights, mipLevel, fileSize: buffer.byteLength }; } unpackF16(packed) { @@ -883,7 +894,15 @@ class CNNTester { const buffer = await file.arrayBuffer(); this.weights = this.parseWeights(buffer); this.weightsBuffer = buffer; + this.mipLevel = this.weights.mipLevel; // Set mip level from binary format this.log(`Loaded weights: ${file.name} (${this.weights.layers.length} layers, ${(buffer.byteLength/1024).toFixed(1)} KB)`); + + // Update UI dropdown to reflect loaded mip level + const mipLevelSelect = document.getElementById('mipLevel'); + if (mipLevelSelect) { + mipLevelSelect.value = this.mipLevel.toString(); + } + this.updateWeightsPanel(); if (this.image) { this.setStatus(`Ready: ${this.image.width}×${this.image.height}`); @@ -895,12 +914,13 @@ class CNNTester { updateWeightsPanel() { const panel = document.getElementById('weightsInfo'); - const { layers, fileSize } = this.weights; + const { layers, mipLevel, fileSize } = this.weights; let html = ` <div style="margin-bottom: 12px;"> <div><strong>File Size:</strong> ${(fileSize / 1024).toFixed(2)} KB</div> <div><strong>CNN Layers:</strong> ${layers.length}</div> + <div><strong>Mip Level:</strong> ${mipLevel} (p0-p3 features)</div> <div style="font-size: 9px; color: #808080; margin-top: 4px;">Static features (input) + ${layers.length} conv layers</div> </div> <table> |
