Skip to content
This repository was archived by the owner on Apr 18, 2023. It is now read-only.

Commit 2ba8ac4

Browse files
committed
[Example] Recommit changes
1 parent d30f695 commit 2ba8ac4

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

examples/semantic_segmentation/utils.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,48 @@ class Utils {
161161
this.outputTensor = new Float32Array(newModel.outputSize.reduce((x,y) => x*y));
162162
this.tfModel = null;
163163
}
164+
165+
// for debugging
166+
async iterateLayers(configs, layerList) {
167+
if (!this.initialized) return;
168+
169+
let iterators = [];
170+
for (let config of configs) {
171+
let model = await new TFliteModelImporter({
172+
rawModel: this.tfModel,
173+
backend: config.backend,
174+
prefer: config.prefer || null,
175+
});
176+
iterators.push(model.layerIterator([this.inputTensor], layerList));
177+
}
178+
179+
while (true) {
180+
181+
let layerOutputs = [];
182+
for (let it of iterators) {
183+
layerOutputs.push(await it.next());
184+
}
185+
186+
let refOutput = layerOutputs[0];
187+
if (refOutput.done) {
188+
break;
189+
}
190+
191+
console.debug(`\n\n\nLayer(${refOutput.value.layerId}) ${refOutput.value.outputName}`);
192+
193+
for (let i = 0; i < configs.length; ++i) {
194+
console.debug(`\n${configs[i].backend}:`);
195+
console.debug(`\n${layerOutputs[i].value.tensor}`);
196+
197+
if (i > 0) {
198+
let sum = 0;
199+
for (let j = 0; j < refOutput.value.tensor.length; j++) {
200+
sum += Math.pow(layerOutputs[i].value.tensor[j] - refOutput.value.tensor[j], 2);
201+
}
202+
let variance = sum / refOutput.value.tensor.length;
203+
console.debug(`var with ${configs[0].backend}: ${variance}`);
204+
}
205+
}
206+
}
207+
}
164208
}

0 commit comments

Comments
 (0)