From c8d5c02bae82e506f6bb507c9ed07aeba3a1bb87 Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 22 Mar 2026 13:25:20 +0100 Subject: fix(cnn_v3/tools): fix getElementById illegal invocation + auto-preload weights MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Bind document.getElementById in filmParams() to fix 'Illegal invocation' error - Add preload() that auto-fetches cnn_v3_weights.bin + cnn_v3_film_mlp.bin from workspaces/main/weights/ on init; skips silently if files not found - Add '↺ Reload from workspace weights/' button for manual re-fetch handoff(Gemini): cnn_v3 web tool fixed; serve from repo root via http.server --- cnn_v3/tools/index.html | 1 + cnn_v3/tools/tester.js | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/cnn_v3/tools/index.html b/cnn_v3/tools/index.html index eba532e..8494fef 100644 --- a/cnn_v3/tools/index.html +++ b/cnn_v3/tools/index.html @@ -67,6 +67,7 @@ video{display:none}
Drop cnn_v3_weights.bin
Drop cnn_v3_film_mlp.bin (optional)
+
Input Mode
diff --git a/cnn_v3/tools/tester.js b/cnn_v3/tools/tester.js index aa765a1..f056444 100644 --- a/cnn_v3/tools/tester.js +++ b/cnn_v3/tools/tester.js @@ -44,9 +44,43 @@ class CNNv3Tester { this.format = navigator.gpu.getPreferredCanvasFormat(); this.linearSampler = this.device.createSampler({magFilter:'linear',minFilter:'linear',mipmapFilter:'linear'}); this.log('WebGPU ready'); + this.preload(); } catch(e) { this.setStatus(`GPU error: ${e.message}`,true); } } + async preload() { + const base = '../../workspaces/main/weights/'; + const files = [ + {url: base+'cnn_v3_weights.bin', isFilm: false}, + {url: base+'cnn_v3_film_mlp.bin', isFilm: true}, + ]; + for (const {url, isFilm} of files) { + try { + const r = await fetch(url); + if (!r.ok) { this.log(`preload skip: ${url.split('/').pop()} (${r.status})`); continue; } + const buf = await r.arrayBuffer(); + const name = url.split('/').pop(); + if (isFilm) { + this.filmMlp = this.parseFilm(buf); + const el = document.getElementById('fDrop'); + el.textContent = `✓ ${name}`; el.classList.add('ok'); + document.getElementById('fSt').textContent = 'FiLM MLP loaded'; + document.getElementById('fSt').style.color = '#28a745'; + } else { + this.weightsU32 = this.parseWeights(buf); this.weightsBuffer = buf; + if (this.weightsGPU) { this.weightsGPU.destroy(); this.weightsGPU = null; } + const el = document.getElementById('wDrop'); + el.textContent = `✓ ${name}`; el.classList.add('ok'); + } + this.log(`Preloaded: ${name}`); + } catch(e) { this.log(`preload error (${url.split('/').pop()}): ${e.message}`, 'err'); } + } + if (this.weightsU32) { + if (this.image || this.isVideo) this.run(); + else this.setStatus('Weights loaded — drop image/video'); + } + } + getDims() { return this.isVideo ? {w:this.video.videoWidth, h:this.video.videoHeight} @@ -106,7 +140,7 @@ class CNNv3Tester { filmParams() { const I4=[1,1,1,1],Z4=[0,0,0,0],I8=[1,1,1,1,1,1,1,1],Z8=[0,0,0,0,0,0,0,0]; if (!this.filmMlp) return {ge0:I4,be0:Z4,ge1:I8,be1:Z8,gd1:I4,bd1:Z4,gd0:I4,bd0:Z4}; - const v=document.getElementById; + const v=document.getElementById.bind(document); const cond=[v('sBP').value,v('sBN').value,v('sAI').value,v('sP0').value,v('sP1').value].map(Number); const f=this.filmFwd(cond); return { -- cgit v1.2.3