monitor-de-mesas / source /scripts /smoke-node.mjs
Segizu's picture
Monitor de Mesas: estado de mesas con OWLv2 en el navegador
e176226 verified
Raw History Blame Contribute Delete
1.17 kB
// Node smoke: runs REAL inference with onnxruntime-node (not WASM/browser). Does not replace browser verification.
import { pipeline, env, RawImage } from '@huggingface/transformers';
import { readFileSync } from 'node:fs';
import { MODEL_ID, MODEL_REVISION, MODEL_DTYPE, EXAMPLES } from '../src/config.js';
env.allowLocalModels = false;
const t0 = performance.now();
const det = await pipeline('zero-shot-object-detection', MODEL_ID, { revision: MODEL_REVISION, dtype: MODEL_DTYPE, device: 'cpu' });
console.log('load_ms', Math.round(performance.now() - t0));
for (const ex of EXAMPLES) {
const img = await RawImage.read(new URL('../public/examples/' + ex.file, import.meta.url).pathname);
const t = performance.now();
const out = await det(img, ex.labels, { threshold: ex.threshold, percentage: false });
const ms = Math.round(performance.now() - t);
const counts = {};
for (const d of out) counts[d.label] = (counts[d.label] || 0) + 1;
console.log(JSON.stringify({ id: ex.id, size: [img.width, img.height], ms, n: out.length, counts, top: out.slice(0, 4).map(d => ({ l: d.label, s: +d.score.toFixed(3), b: Object.values(d.box).map(Math.round) })) }));
}