summaryrefslogtreecommitdiff
path: root/cnn_v3/tools/tester.js
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-03-22 13:25:20 +0100
committerskal <pascal.massimino@gmail.com>2026-03-22 13:25:20 +0100
commitc8d5c02bae82e506f6bb507c9ed07aeba3a1bb87 (patch)
tree418ed484f94fe4d1d3c676d112fde3e64a94d412 /cnn_v3/tools/tester.js
parent568852fcece343b65c74a44ac8a331c51a98349a (diff)
fix(cnn_v3/tools): fix getElementById illegal invocation + auto-preload weights
- 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
Diffstat (limited to 'cnn_v3/tools/tester.js')
-rw-r--r--cnn_v3/tools/tester.js36
1 files changed, 35 insertions, 1 deletions
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 {