Spaces:
Running
Running
Deploy Visionary in-browser app (YOLOv8n + CLAHE gate + ConvNeXt INT8)
Browse files- README.md +16 -4
- app.js +283 -0
- coi-serviceworker.js +2 -0
- data/classes.json +1 -0
- data/eval_results.json +348 -0
- index.html +56 -17
- models/convnext_small_320_int8.onnx +3 -0
- models/convnext_tiny_224_int8.onnx +3 -0
- models/models.json +28 -0
- models/yolov8n.onnx +3 -0
- pipeline.js +352 -0
- styles.css +105 -0
- vendor/opencv.js +0 -0
- vendor/ort-wasm-simd-threaded.mjs +70 -0
- vendor/ort-wasm-simd-threaded.wasm +3 -0
- vendor/ort.wasm.min.js +8 -0
README.md
CHANGED
|
@@ -1,10 +1,22 @@
|
|
| 1 |
---
|
| 2 |
title: Visionary
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
|
|
|
| 7 |
pinned: false
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: Visionary
|
| 3 |
+
emoji: 🚗
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: static
|
| 7 |
+
app_file: index.html
|
| 8 |
pinned: false
|
| 9 |
+
short_description: Car make/model/year recognition, 196 classes, in-browser
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Visionary — fine-grained vehicle recognition (runs in your browser)
|
| 13 |
+
|
| 14 |
+
Upload a car photo → **YOLOv8n** localises the vehicle → an adaptive **CLAHE**
|
| 15 |
+
illumination gate (OpenCV.js) normalises dark or flat images → an INT8
|
| 16 |
+
**ConvNeXt** fine-tuned on Stanford Cars identifies **make, model and year**
|
| 17 |
+
(196 classes) with temperature-calibrated confidence. Intermediate classical-CV
|
| 18 |
+
stages (CLAHE, bilateral filter, Canny, contours) are shown for every image.
|
| 19 |
+
|
| 20 |
+
Everything runs locally via ONNX Runtime Web + OpenCV.js; photos never leave the device.
|
| 21 |
+
|
| 22 |
+
Official test set (8,041 unseen images): **94.1% Top-1 / 99.1% Top-5** (Lite model).
|
app.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Visionary — browser UI. Inference runs locally via web/pipeline.js. */
|
| 2 |
+
import { Pipeline } from "./pipeline.js";
|
| 3 |
+
|
| 4 |
+
const $ = s => document.querySelector(s);
|
| 5 |
+
const chat = $("#chat"), fileIn = $("#file"), drop = $("#drop");
|
| 6 |
+
const esc = s => String(s).replace(/[&<>"']/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]));
|
| 7 |
+
const tick = () => new Promise(r => setTimeout(r, 16));
|
| 8 |
+
const MAX_BYTES = 15 * 1024 * 1024;
|
| 9 |
+
const CACHE = "visionary-v1";
|
| 10 |
+
|
| 11 |
+
let reg, classes, pipe = null, current = null, busy = false, ready = null;
|
| 12 |
+
const loadedClassifiers = {};
|
| 13 |
+
|
| 14 |
+
/* ------------------------------------------------ cached download w/ progress */
|
| 15 |
+
async function fetchCached(url, onProgress) {
|
| 16 |
+
let cache = null;
|
| 17 |
+
try { cache = await caches.open(CACHE); const hit = await cache.match(url); if (hit) { onProgress(1, 1); return new Uint8Array(await hit.arrayBuffer()); } } catch (e) { cache = null; }
|
| 18 |
+
const r = await fetch(url);
|
| 19 |
+
if (!r.ok) throw new Error(`Could not download ${url} (${r.status})`);
|
| 20 |
+
const total = +r.headers.get("content-length") || 0;
|
| 21 |
+
const reader = r.body.getReader(), parts = [];
|
| 22 |
+
let got = 0;
|
| 23 |
+
for (;;) {
|
| 24 |
+
const { done, value } = await reader.read();
|
| 25 |
+
if (done) break;
|
| 26 |
+
parts.push(value); got += value.length; onProgress(got, total || got);
|
| 27 |
+
}
|
| 28 |
+
const buf = new Uint8Array(got);
|
| 29 |
+
let o = 0; for (const p of parts) { buf.set(p, o); o += p.length; }
|
| 30 |
+
try { if (cache) await cache.put(url, new Response(buf, { headers: { "content-type": "application/octet-stream" } })); } catch (e) { /* quota: fine */ }
|
| 31 |
+
return buf;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
async function downloadAll(items) {
|
| 35 |
+
const totals = items.map(i => i.size || 1), done = items.map(() => 0);
|
| 36 |
+
const T = totals.reduce((a, b) => a + b, 0);
|
| 37 |
+
const show = label => {
|
| 38 |
+
const pct = Math.min(100, (done.reduce((a, b) => a + b, 0) / T) * 100);
|
| 39 |
+
$("#loaderBar").style.width = pct.toFixed(1) + "%";
|
| 40 |
+
$("#loaderText").textContent = `${label} · ${pct.toFixed(0)}% of ${(T / 1048576).toFixed(0)} MB (first visit only, then cached)`;
|
| 41 |
+
};
|
| 42 |
+
return Promise.all(items.map((it, k) => fetchCached(it.url, (g, t) => { done[k] = (g / t) * totals[k]; show(it.label); })));
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
async function loadOpenCV(bytes) {
|
| 46 |
+
const url = URL.createObjectURL(new Blob([bytes], { type: "text/javascript" }));
|
| 47 |
+
await new Promise((res, rej) => { const s = document.createElement("script"); s.src = url; s.onload = res; s.onerror = rej; document.head.appendChild(s); });
|
| 48 |
+
// Emscripten's Module object defines .then(), so `await cv` (or returning cv
|
| 49 |
+
// from an async function) makes the browser resolve a self-referencing
|
| 50 |
+
// thenable forever and freezes the tab. Poll for readiness instead, then
|
| 51 |
+
// strip .then and hand the module back wrapped in an object.
|
| 52 |
+
for (let i = 0; !(window.cv && window.cv.Mat); i++) {
|
| 53 |
+
if (i > 1200) throw new Error("OpenCV.js failed to initialise");
|
| 54 |
+
await new Promise(r => setTimeout(r, 50));
|
| 55 |
+
}
|
| 56 |
+
const cv = window.cv;
|
| 57 |
+
if (typeof cv.then === "function") delete cv.then;
|
| 58 |
+
return { cv };
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/* --------------------------------------------------------------- bootstrap */
|
| 62 |
+
async function init() {
|
| 63 |
+
try {
|
| 64 |
+
[reg, classes] = await Promise.all([fetch("models/models.json").then(r => r.json()), fetch("data/classes.json").then(r => r.json())]);
|
| 65 |
+
let saved = null; try { saved = localStorage.getItem("visionary-model"); } catch (e) {}
|
| 66 |
+
current = reg.models[saved] ? saved : reg.default;
|
| 67 |
+
renderMenu();
|
| 68 |
+
const spec = reg.models[current];
|
| 69 |
+
const A = reg.assets;
|
| 70 |
+
const [cvBytes, wasm, yolo, cls] = await downloadAll([
|
| 71 |
+
{ url: "vendor/opencv.js", label: "OpenCV.js", size: A.opencv },
|
| 72 |
+
{ url: "vendor/ort-wasm-simd-threaded.wasm", label: "ONNX Runtime", size: A.wasm },
|
| 73 |
+
{ url: "models/yolov8n.onnx", label: "YOLOv8 detector", size: A.yolo },
|
| 74 |
+
{ url: spec.file, label: spec.name, size: spec.size },
|
| 75 |
+
]);
|
| 76 |
+
$("#loaderText").textContent = "Initialising models…";
|
| 77 |
+
await tick();
|
| 78 |
+
ort.env.wasm.wasmPaths = new URL("vendor/", location.href).href;
|
| 79 |
+
try { ort.env.wasm.wasmBinary = wasm.buffer; } catch (e) {}
|
| 80 |
+
ort.env.wasm.numThreads = self.crossOriginIsolated ? Math.min(4, navigator.hardwareConcurrency || 2) : 1;
|
| 81 |
+
// Run inference in a Web Worker so the page (spinner, scrolling) stays responsive.
|
| 82 |
+
ort.env.wasm.proxy = true;
|
| 83 |
+
const { cv } = await loadOpenCV(cvBytes);
|
| 84 |
+
pipe = new Pipeline(ort, cv, { classes, temperature: spec.temperature, imgSize: spec.imgSize });
|
| 85 |
+
// In proxy (worker) mode ORT *transfers* the buffer to the worker, detaching
|
| 86 |
+
// it — so always hand ORT a copy and keep the original for model switching.
|
| 87 |
+
await pipe.load(yolo, cls.slice());
|
| 88 |
+
loadedClassifiers[current] = cls;
|
| 89 |
+
// warm-up so the first real request is fast
|
| 90 |
+
await pipe.analyze({ data: new Uint8ClampedArray(64 * 64 * 4).fill(128), width: 64, height: 64 }, { withStages: false });
|
| 91 |
+
$("#loader")?.classList.add("done");
|
| 92 |
+
} catch (e) {
|
| 93 |
+
console.error(e);
|
| 94 |
+
$("#loaderText").textContent = "Could not load the models: " + (e.message || e) + ". Please reload the page.";
|
| 95 |
+
throw e;
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
ready = init();
|
| 99 |
+
|
| 100 |
+
/* -------------------------------------------------------------- model menu */
|
| 101 |
+
function renderMenu() {
|
| 102 |
+
const m = reg.models[current];
|
| 103 |
+
$("#modelName").textContent = m ? m.name : "Model";
|
| 104 |
+
$("#menu").innerHTML = Object.entries(reg.models).map(([k, x]) => `<button data-k="${esc(k)}" class="${k === current ? "sel" : ""}">
|
| 105 |
+
${esc(x.name)}${k === current ? " ✓" : ""}<small>${esc(x.desc || "")}${x.top1 ? ` · ${x.top1}% top-1` : ""} · ${(x.size / 1048576).toFixed(0)} MB</small></button>`).join("");
|
| 106 |
+
}
|
| 107 |
+
$("#pickerBtn").onclick = e => { e.stopPropagation(); $("#menu").classList.toggle("open"); };
|
| 108 |
+
$("#menu").onclick = async e => {
|
| 109 |
+
const b = e.target.closest("button[data-k]"); if (!b || busy) return;
|
| 110 |
+
const k = b.dataset.k; $("#menu").classList.remove("open");
|
| 111 |
+
if (k === current) return;
|
| 112 |
+
busy = true; $("#sendBtn").disabled = true;
|
| 113 |
+
const prev = current;
|
| 114 |
+
$("#modelName").textContent = "Loading " + reg.models[k].name + "…";
|
| 115 |
+
try {
|
| 116 |
+
await ready;
|
| 117 |
+
const spec = reg.models[k];
|
| 118 |
+
const bytes = loadedClassifiers[k] || await fetchCached(spec.file, (g, t) => { $("#modelName").textContent = `Loading ${Math.round(g / t * 100)}%`; });
|
| 119 |
+
loadedClassifiers[k] = bytes;
|
| 120 |
+
await pipe.setClassifier(bytes.slice(), {}, { temperature: spec.temperature, imgSize: spec.imgSize });
|
| 121 |
+
current = k; try { localStorage.setItem("visionary-model", k); } catch (e) {}
|
| 122 |
+
} catch (err) { current = prev; addError("Could not switch model: " + (err.message || err)); }
|
| 123 |
+
finally { renderMenu(); busy = false; $("#sendBtn").disabled = false; }
|
| 124 |
+
};
|
| 125 |
+
document.addEventListener("click", () => $("#menu").classList.remove("open"));
|
| 126 |
+
|
| 127 |
+
/* ------------------------------------------------------------------ input */
|
| 128 |
+
document.querySelectorAll("[data-pick]").forEach(el => (el.onclick = () => !busy && fileIn.click()));
|
| 129 |
+
fileIn.onchange = () => { if (fileIn.files[0]) send(fileIn.files[0]); fileIn.value = ""; };
|
| 130 |
+
["dragenter", "dragover"].forEach(ev => document.addEventListener(ev, e => { e.preventDefault(); drop.classList.add("drag"); }));
|
| 131 |
+
["dragleave", "drop"].forEach(ev => document.addEventListener(ev, e => { e.preventDefault(); drop.classList.remove("drag"); }));
|
| 132 |
+
document.addEventListener("drop", e => { const f = e.dataTransfer.files[0]; if (f) send(f); });
|
| 133 |
+
document.addEventListener("paste", e => { const it = [...e.clipboardData.items].find(i => i.type.startsWith("image/")); if (it) send(it.getAsFile()); });
|
| 134 |
+
const scrollEnd = () => window.scrollTo({ top: document.body.scrollHeight, behavior: "smooth" });
|
| 135 |
+
|
| 136 |
+
async function decode(file) {
|
| 137 |
+
let bmp;
|
| 138 |
+
try { bmp = await createImageBitmap(file, { imageOrientation: "from-image" }); }
|
| 139 |
+
catch (e) { throw new Error("That file isn't a readable image. Please upload a JPG, PNG or WEBP."); }
|
| 140 |
+
if (Math.min(bmp.width, bmp.height) < 32) throw new Error("Image is too small (minimum 32×32 pixels).");
|
| 141 |
+
const s = Math.min(1, 1600 / Math.max(bmp.width, bmp.height));
|
| 142 |
+
const w = Math.round(bmp.width * s), h = Math.round(bmp.height * s);
|
| 143 |
+
const c = document.createElement("canvas"); c.width = w; c.height = h;
|
| 144 |
+
const g = c.getContext("2d", { willReadFrequently: true });
|
| 145 |
+
g.drawImage(bmp, 0, 0, w, h); bmp.close && bmp.close();
|
| 146 |
+
return g.getImageData(0, 0, w, h);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
function imgURL(id) {
|
| 150 |
+
const c = document.createElement("canvas"); c.width = id.width; c.height = id.height;
|
| 151 |
+
c.getContext("2d").putImageData(new ImageData(id.data, id.width, id.height), 0, 0);
|
| 152 |
+
return c.toDataURL("image/jpeg", 0.85);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
async function send(file) {
|
| 156 |
+
if (busy) return;
|
| 157 |
+
$("#hero")?.classList.add("compact");
|
| 158 |
+
if (!file.type.startsWith("image/")) { $("#hero")?.remove(); addError("That file isn't an image. Please upload a JPG, PNG or WEBP."); return; }
|
| 159 |
+
if (file.size > MAX_BYTES) { $("#hero")?.remove(); addError("Image is larger than 15 MB. Please upload a smaller image."); return; }
|
| 160 |
+
busy = true; $("#sendBtn").disabled = true;
|
| 161 |
+
const hero = $("#hero"); if (hero) { if (pipe) hero.remove(); else hero.querySelector(".samples")?.remove(); }
|
| 162 |
+
chat.insertAdjacentHTML("beforeend", `<div class="msg user"><img src="${URL.createObjectURL(file)}" alt="Uploaded image"></div>`);
|
| 163 |
+
const pending = document.createElement("div");
|
| 164 |
+
pending.className = "msg bot";
|
| 165 |
+
pending.innerHTML = `<div class="dot"></div><div class="body"><div class="typing"><span><i></i> <i></i> <i></i></span><span class="phase">Reading image…</span></div></div>`;
|
| 166 |
+
chat.appendChild(pending); scrollEnd();
|
| 167 |
+
const phase = t => { const p = pending.querySelector(".phase"); if (p) p.textContent = t; };
|
| 168 |
+
try {
|
| 169 |
+
const img = await decode(file);
|
| 170 |
+
if (!pipe) { phase("Waiting for models to finish loading…"); await ready; }
|
| 171 |
+
$("#hero")?.remove();
|
| 172 |
+
phase("Locating vehicle, normalising illumination, classifying…"); await tick(); await tick();
|
| 173 |
+
const d = await pipe.analyze(img);
|
| 174 |
+
d.model = reg.models[current];
|
| 175 |
+
pending.remove();
|
| 176 |
+
renderResult(d);
|
| 177 |
+
} catch (e) {
|
| 178 |
+
console.error(e); pending.remove();
|
| 179 |
+
addError(e.message || "Something went wrong. Please try another image.");
|
| 180 |
+
} finally { busy = false; $("#sendBtn").disabled = false; scrollEnd(); }
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
function addError(msg) {
|
| 184 |
+
chat.insertAdjacentHTML("beforeend", `<div class="msg bot"><div class="dot"></div><div class="body"><div class="notice bad">${esc(msg)}</div></div></div>`);
|
| 185 |
+
scrollEnd();
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
/* ----------------------------------------------------------------- render */
|
| 189 |
+
function renderResult(d) {
|
| 190 |
+
const el = document.createElement("div"); el.className = "msg bot";
|
| 191 |
+
const p = d.prediction, c = d.confidence, t = d.timings;
|
| 192 |
+
const cls = c >= 75 ? "ok" : c >= 50 ? "warn" : "bad";
|
| 193 |
+
const head = d.status === "no_vehicle" ? `<div class="notice bad">${esc(d.message)}</div>` : `
|
| 194 |
+
${d.status === "low_confidence" ? `<div class="notice warn">${esc(d.message)}</div>` : ""}
|
| 195 |
+
<div class="title">${esc(p.year)} ${esc(p.make)} ${esc(p.model)}</div>
|
| 196 |
+
<div class="sub">${esc(p.body_style || "")}${p.body_style ? " · " : ""}${d.status === "low_confidence" ? "best guess" : "most likely match"}</div>
|
| 197 |
+
<span class="badge ${cls}">● ${c.toFixed(1)}% confidence</span>
|
| 198 |
+
${d.detection.box ? `<span class="badge">▢ ${esc(d.detection.label)} detected ${(d.detection.conf * 100).toFixed(0)}%</span>` : `<span class="badge warn">No box: full frame</span>`}
|
| 199 |
+
${d.illumination.clahe_applied ? `<span class="badge">☀ CLAHE applied (dark/flat image)</span>` : ""}
|
| 200 |
+
<span class="badge">⏱ ${Math.round(t.total_ms)} ms on this device</span>`;
|
| 201 |
+
el.innerHTML = `<div class="dot"></div><div class="body">${head}
|
| 202 |
+
<div class="canvaswrap" style="margin-top:10px"><canvas></canvas></div>
|
| 203 |
+
${d.status !== "no_vehicle" ? `
|
| 204 |
+
<div class="card"><h3>Top-5 predictions</h3>
|
| 205 |
+
${d.top5.map((x, i) => `<div class="row ${i ? "alt" : ""}"><span class="n">${esc(x.year)} ${esc(x.make)} ${esc(x.model)}</span><span class="v">${x.confidence.toFixed(1)}%</span><div class="track"><div class="fill" data-w="${Math.max(1, x.confidence)}"></div></div></div>`).join("")}
|
| 206 |
+
</div>
|
| 207 |
+
<details><summary>How Visionary got this answer</summary>
|
| 208 |
+
<div class="card"><h3>Pipeline (ran on your device)</h3><div class="kv">
|
| 209 |
+
<div><small>Detection (YOLOv8n)</small><b>${Math.round(t.detection_ms)} ms</b></div>
|
| 210 |
+
<div><small>Classical CV gate</small><b>${Math.round(t.classical_ms)} ms</b></div>
|
| 211 |
+
<div><small>Classifier (${esc(d.model.name)})</small><b>${Math.round(t.classifier_ms)} ms</b></div>
|
| 212 |
+
<div><small>Brightness / contrast</small><b>${d.illumination.mean_luma} / ${d.illumination.contrast}</b></div>
|
| 213 |
+
<div><small>Top-1 vs Top-2 margin</small><b>${d.margin.toFixed(1)} pts</b></div>
|
| 214 |
+
</div>
|
| 215 |
+
<div class="stages">${d.stages.map(s => `<div class="stage"><img src="${imgURL(s.img)}" alt="${esc(s.name)}"><b>${esc(s.name)}</b><span>${esc(s.desc)}</span></div>`).join("")}</div>
|
| 216 |
+
</div></details>` : ""}
|
| 217 |
+
</div>`;
|
| 218 |
+
chat.appendChild(el);
|
| 219 |
+
drawBoxes(el.querySelector("canvas"), d);
|
| 220 |
+
requestAnimationFrame(() => el.querySelectorAll(".fill").forEach(f => (f.style.width = f.dataset.w + "%")));
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
function drawBoxes(cv, d) {
|
| 224 |
+
const im = d.image;
|
| 225 |
+
cv.width = im.width; cv.height = im.height;
|
| 226 |
+
const g = cv.getContext("2d");
|
| 227 |
+
g.putImageData(new ImageData(im.data, im.width, im.height), 0, 0);
|
| 228 |
+
const accent = getComputedStyle(document.documentElement).getPropertyValue("--accent").trim() || "#c96442";
|
| 229 |
+
const lw = Math.max(2, cv.width / 260);
|
| 230 |
+
for (const b of d.detection.all || []) {
|
| 231 |
+
const [x1, y1, x2, y2] = b.box;
|
| 232 |
+
const primary = d.detection.box && b.box === d.detection.box || (d.detection.box && Math.abs(x1 - d.detection.box[0]) < 1 && Math.abs(y1 - d.detection.box[1]) < 1);
|
| 233 |
+
g.lineWidth = primary ? lw * 1.6 : lw; g.strokeStyle = primary ? accent : "rgba(255,255,255,.75)";
|
| 234 |
+
g.strokeRect(x1, y1, x2 - x1, y2 - y1);
|
| 235 |
+
if (primary && d.status !== "no_vehicle") {
|
| 236 |
+
const label = `${d.prediction.year} ${d.prediction.make} ${d.prediction.model} · ${d.confidence.toFixed(0)}%`;
|
| 237 |
+
const fs = Math.max(13, cv.width / 45); g.font = `600 ${fs}px system-ui,sans-serif`;
|
| 238 |
+
const tw = g.measureText(label).width + fs * 0.8, th = fs * 1.6;
|
| 239 |
+
const ly = y1 - th < 0 ? y1 : y1 - th;
|
| 240 |
+
g.fillStyle = accent; g.fillRect(x1 - lw * 0.8, ly, Math.min(tw, cv.width - x1), th);
|
| 241 |
+
g.fillStyle = "#fff"; g.fillText(label, x1 + fs * 0.4 - lw * 0.8, ly + th * 0.7);
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
/* -------------------------------------------------------------- benchmarks */
|
| 247 |
+
async function openBench() {
|
| 248 |
+
$("#overlay").classList.add("open");
|
| 249 |
+
const sheet = $("#sheet");
|
| 250 |
+
sheet.innerHTML = `<button class="close" id="closeB">Close</button><h2>Benchmarks</h2><p class="sub">Loading…</p>`;
|
| 251 |
+
$("#closeB").onclick = closeBench;
|
| 252 |
+
try {
|
| 253 |
+
const b = await (await fetch("data/eval_results.json")).json();
|
| 254 |
+
const row = r => `<tr>${r.map(v => `<td>${esc(v ?? "–")}</td>`).join("")}</tr>`;
|
| 255 |
+
sheet.innerHTML = `<button class="close" id="closeB">Close</button>
|
| 256 |
+
<h2>Benchmarks</h2><p class="sub">Official Stanford Cars test set: ${esc(b.n_test)} images never seen in training. Server latency is CPU, 2 threads.</p>
|
| 257 |
+
<div class="card"><h3>Classical vs deep learning vs hybrid</h3><div class="tablewrap"><table>
|
| 258 |
+
<tr><th>Approach</th><th>Top-1 %</th><th>Top-5 %</th><th>Latency ms</th><th>Size MB</th></tr>
|
| 259 |
+
${b.comparison.map(r => row([r.name, r.top1, r.top5, r.latency_ms, r.size_mb])).join("")}</table></div></div>
|
| 260 |
+
${b.browser ? `<div class="card"><h3>This in-browser app</h3><div class="kv">
|
| 261 |
+
<div><small>Top-1 (test set)</small><b>${b.browser.top1}%</b></div><div><small>Top-5</small><b>${b.browser.top5}%</b></div>
|
| 262 |
+
<div><small>Agreement with Python</small><b>${b.browser.parity}%</b></div></div></div>` : ""}
|
| 263 |
+
<div class="card"><h3>Ablation: what each component adds</h3><div class="tablewrap"><table>
|
| 264 |
+
<tr><th>Config</th><th>Top-1 %</th><th>Top-5 %</th><th>Δ Top-1</th></tr>
|
| 265 |
+
${b.ablation.map(r => row([r.name, r.top1, r.top5, r.delta])).join("")}</table></div></div>
|
| 266 |
+
<div class="card"><h3>Detection</h3><div class="kv">
|
| 267 |
+
<div><small>Mean IoU</small><b>${b.detection.mean_iou}</b></div><div><small>mAP@50</small><b>${b.detection.map50}</b></div>
|
| 268 |
+
<div><small>mAP@50:95</small><b>${b.detection.map50_95}</b></div><div><small>Detection rate</small><b>${b.detection.recall}%</b></div></div></div>
|
| 269 |
+
<div class="card"><h3>Robustness (Top-1 %)</h3><div class="tablewrap"><table>
|
| 270 |
+
<tr><th>Condition</th>${b.robustness.methods.map(m => `<th>${esc(m)}</th>`).join("")}</tr>
|
| 271 |
+
${b.robustness.rows.map(r => row([r.condition, ...r.values])).join("")}</table></div></div>
|
| 272 |
+
<div class="card"><h3>Confidence</h3><div class="kv">
|
| 273 |
+
<div><small>Calibration error (ECE)</small><b>${b.confidence.ece_hybrid}%</b></div>
|
| 274 |
+
<div><small>Accuracy when confident (≥50%)</small><b>${b.confidence.acc_when_confident}%</b></div>
|
| 275 |
+
<div><small>Accuracy when flagged (<50%)</small><b>${b.confidence.acc_when_flagged}%</b></div>
|
| 276 |
+
<div><small>Flag rate</small><b>${b.confidence.low_conf_rate}%</b></div></div></div>`;
|
| 277 |
+
$("#closeB").onclick = closeBench;
|
| 278 |
+
} catch (e) { sheet.innerHTML += `<div class="notice bad">Could not load benchmarks.</div>`; }
|
| 279 |
+
}
|
| 280 |
+
function closeBench() { $("#overlay").classList.remove("open"); }
|
| 281 |
+
$("#benchBtn").onclick = openBench; $("#benchSample").onclick = openBench;
|
| 282 |
+
$("#overlay").onclick = e => { if (e.target.id === "overlay") closeBench(); };
|
| 283 |
+
document.addEventListener("keydown", e => { if (e.key === "Escape") closeBench(); });
|
coi-serviceworker.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*! coi-serviceworker v0.1.7 - Guido Zuidhof and contributors, licensed under MIT */
|
| 2 |
+
let coepCredentialless=!1;"undefined"==typeof window?(self.addEventListener("install",(()=>self.skipWaiting())),self.addEventListener("activate",(e=>e.waitUntil(self.clients.claim()))),self.addEventListener("message",(e=>{e.data&&("deregister"===e.data.type?self.registration.unregister().then((()=>self.clients.matchAll())).then((e=>{e.forEach((e=>e.navigate(e.url)))})):"coepCredentialless"===e.data.type&&(coepCredentialless=e.data.value))})),self.addEventListener("fetch",(function(e){const r=e.request;if("only-if-cached"===r.cache&&"same-origin"!==r.mode)return;const s=coepCredentialless&&"no-cors"===r.mode?new Request(r,{credentials:"omit"}):r;e.respondWith(fetch(s).then((e=>{if(0===e.status)return e;const r=new Headers(e.headers);return r.set("Cross-Origin-Embedder-Policy",coepCredentialless?"credentialless":"require-corp"),coepCredentialless||r.set("Cross-Origin-Resource-Policy","cross-origin"),r.set("Cross-Origin-Opener-Policy","same-origin"),new Response(e.body,{status:e.status,statusText:e.statusText,headers:r})})).catch((e=>console.error(e))))}))):(()=>{const e={shouldRegister:()=>!0,shouldDeregister:()=>!1,coepCredentialless:()=>!(window.chrome||window.netscape),doReload:()=>window.location.reload(),quiet:!1,...window.coi},r=navigator;r.serviceWorker&&r.serviceWorker.controller&&(r.serviceWorker.controller.postMessage({type:"coepCredentialless",value:e.coepCredentialless()}),e.shouldDeregister()&&r.serviceWorker.controller.postMessage({type:"deregister"})),!1===window.crossOriginIsolated&&e.shouldRegister()&&(window.isSecureContext?r.serviceWorker&&r.serviceWorker.register(window.document.currentScript.src).then((s=>{!e.quiet&&console.log("COOP/COEP Service Worker registered",s.scope),s.addEventListener("updatefound",(()=>{!e.quiet&&console.log("Reloading page to make use of updated COOP/COEP Service Worker."),e.doReload()})),s.active&&!r.serviceWorker.controller&&(!e.quiet&&console.log("Reloading page to make use of COOP/COEP Service Worker."),e.doReload())}),(r=>{!e.quiet&&console.error("COOP/COEP Service Worker failed to register:",r)})):!e.quiet&&console.log("COOP/COEP Service Worker not registered, a secure context is required."))})();
|
data/classes.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
[{"make": "AM General", "model": "Hummer SUV", "year": 2000, "body_style": "SUV", "name": "AM General Hummer SUV 2000"}, {"make": "Acura", "model": "RL Sedan", "year": 2012, "body_style": "Sedan", "name": "Acura RL Sedan 2012"}, {"make": "Acura", "model": "TL Sedan", "year": 2012, "body_style": "Sedan", "name": "Acura TL Sedan 2012"}, {"make": "Acura", "model": "TL Type-S", "year": 2008, "body_style": "Unknown", "name": "Acura TL Type-S 2008"}, {"make": "Acura", "model": "TSX Sedan", "year": 2012, "body_style": "Sedan", "name": "Acura TSX Sedan 2012"}, {"make": "Acura", "model": "Integra Type R", "year": 2001, "body_style": "Unknown", "name": "Acura Integra Type R 2001"}, {"make": "Acura", "model": "ZDX Hatchback", "year": 2012, "body_style": "Hatchback", "name": "Acura ZDX Hatchback 2012"}, {"make": "Aston Martin", "model": "V8 Vantage Convertible", "year": 2012, "body_style": "Convertible", "name": "Aston Martin V8 Vantage Convertible 2012"}, {"make": "Aston Martin", "model": "V8 Vantage Coupe", "year": 2012, "body_style": "Coupe", "name": "Aston Martin V8 Vantage Coupe 2012"}, {"make": "Aston Martin", "model": "Virage Convertible", "year": 2012, "body_style": "Convertible", "name": "Aston Martin Virage Convertible 2012"}, {"make": "Aston Martin", "model": "Virage Coupe", "year": 2012, "body_style": "Coupe", "name": "Aston Martin Virage Coupe 2012"}, {"make": "Audi", "model": "RS 4 Convertible", "year": 2008, "body_style": "Convertible", "name": "Audi RS 4 Convertible 2008"}, {"make": "Audi", "model": "A5 Coupe", "year": 2012, "body_style": "Coupe", "name": "Audi A5 Coupe 2012"}, {"make": "Audi", "model": "TTS Coupe", "year": 2012, "body_style": "Coupe", "name": "Audi TTS Coupe 2012"}, {"make": "Audi", "model": "R8 Coupe", "year": 2012, "body_style": "Coupe", "name": "Audi R8 Coupe 2012"}, {"make": "Audi", "model": "V8 Sedan", "year": 1994, "body_style": "Sedan", "name": "Audi V8 Sedan 1994"}, {"make": "Audi", "model": "100 Sedan", "year": 1994, "body_style": "Sedan", "name": "Audi 100 Sedan 1994"}, {"make": "Audi", "model": "100 Wagon", "year": 1994, "body_style": "Wagon", "name": "Audi 100 Wagon 1994"}, {"make": "Audi", "model": "TT Hatchback", "year": 2011, "body_style": "Hatchback", "name": "Audi TT Hatchback 2011"}, {"make": "Audi", "model": "S6 Sedan", "year": 2011, "body_style": "Sedan", "name": "Audi S6 Sedan 2011"}, {"make": "Audi", "model": "S5 Convertible", "year": 2012, "body_style": "Convertible", "name": "Audi S5 Convertible 2012"}, {"make": "Audi", "model": "S5 Coupe", "year": 2012, "body_style": "Coupe", "name": "Audi S5 Coupe 2012"}, {"make": "Audi", "model": "S4 Sedan", "year": 2012, "body_style": "Sedan", "name": "Audi S4 Sedan 2012"}, {"make": "Audi", "model": "S4 Sedan", "year": 2007, "body_style": "Sedan", "name": "Audi S4 Sedan 2007"}, {"make": "Audi", "model": "TT RS Coupe", "year": 2012, "body_style": "Coupe", "name": "Audi TT RS Coupe 2012"}, {"make": "BMW", "model": "ActiveHybrid 5 Sedan", "year": 2012, "body_style": "Sedan", "name": "BMW ActiveHybrid 5 Sedan 2012"}, {"make": "BMW", "model": "1 Series Convertible", "year": 2012, "body_style": "Convertible", "name": "BMW 1 Series Convertible 2012"}, {"make": "BMW", "model": "1 Series Coupe", "year": 2012, "body_style": "Coupe", "name": "BMW 1 Series Coupe 2012"}, {"make": "BMW", "model": "3 Series Sedan", "year": 2012, "body_style": "Sedan", "name": "BMW 3 Series Sedan 2012"}, {"make": "BMW", "model": "3 Series Wagon", "year": 2012, "body_style": "Wagon", "name": "BMW 3 Series Wagon 2012"}, {"make": "BMW", "model": "6 Series Convertible", "year": 2007, "body_style": "Convertible", "name": "BMW 6 Series Convertible 2007"}, {"make": "BMW", "model": "X5 SUV", "year": 2007, "body_style": "SUV", "name": "BMW X5 SUV 2007"}, {"make": "BMW", "model": "X6 SUV", "year": 2012, "body_style": "SUV", "name": "BMW X6 SUV 2012"}, {"make": "BMW", "model": "M3 Coupe", "year": 2012, "body_style": "Coupe", "name": "BMW M3 Coupe 2012"}, {"make": "BMW", "model": "M5 Sedan", "year": 2010, "body_style": "Sedan", "name": "BMW M5 Sedan 2010"}, {"make": "BMW", "model": "M6 Convertible", "year": 2010, "body_style": "Convertible", "name": "BMW M6 Convertible 2010"}, {"make": "BMW", "model": "X3 SUV", "year": 2012, "body_style": "SUV", "name": "BMW X3 SUV 2012"}, {"make": "BMW", "model": "Z4 Convertible", "year": 2012, "body_style": "Convertible", "name": "BMW Z4 Convertible 2012"}, {"make": "Bentley", "model": "Continental Supersports Conv. Convertible", "year": 2012, "body_style": "Convertible", "name": "Bentley Continental Supersports Conv. Convertible 2012"}, {"make": "Bentley", "model": "Arnage Sedan", "year": 2009, "body_style": "Sedan", "name": "Bentley Arnage Sedan 2009"}, {"make": "Bentley", "model": "Mulsanne Sedan", "year": 2011, "body_style": "Sedan", "name": "Bentley Mulsanne Sedan 2011"}, {"make": "Bentley", "model": "Continental GT Coupe", "year": 2012, "body_style": "Coupe", "name": "Bentley Continental GT Coupe 2012"}, {"make": "Bentley", "model": "Continental GT Coupe", "year": 2007, "body_style": "Coupe", "name": "Bentley Continental GT Coupe 2007"}, {"make": "Bentley", "model": "Continental Flying Spur Sedan", "year": 2007, "body_style": "Sedan", "name": "Bentley Continental Flying Spur Sedan 2007"}, {"make": "Bugatti", "model": "Veyron 16.4 Convertible", "year": 2009, "body_style": "Convertible", "name": "Bugatti Veyron 16.4 Convertible 2009"}, {"make": "Bugatti", "model": "Veyron 16.4 Coupe", "year": 2009, "body_style": "Coupe", "name": "Bugatti Veyron 16.4 Coupe 2009"}, {"make": "Buick", "model": "Regal GS", "year": 2012, "body_style": "Unknown", "name": "Buick Regal GS 2012"}, {"make": "Buick", "model": "Rainier SUV", "year": 2007, "body_style": "SUV", "name": "Buick Rainier SUV 2007"}, {"make": "Buick", "model": "Verano Sedan", "year": 2012, "body_style": "Sedan", "name": "Buick Verano Sedan 2012"}, {"make": "Buick", "model": "Enclave SUV", "year": 2012, "body_style": "SUV", "name": "Buick Enclave SUV 2012"}, {"make": "Cadillac", "model": "CTS-V Sedan", "year": 2012, "body_style": "Sedan", "name": "Cadillac CTS-V Sedan 2012"}, {"make": "Cadillac", "model": "SRX SUV", "year": 2012, "body_style": "SUV", "name": "Cadillac SRX SUV 2012"}, {"make": "Cadillac", "model": "Escalade EXT Crew Cab", "year": 2007, "body_style": "Crew Cab", "name": "Cadillac Escalade EXT Crew Cab 2007"}, {"make": "Chevrolet", "model": "Silverado 1500 Hybrid Crew Cab", "year": 2012, "body_style": "Crew Cab", "name": "Chevrolet Silverado 1500 Hybrid Crew Cab 2012"}, {"make": "Chevrolet", "model": "Corvette Convertible", "year": 2012, "body_style": "Convertible", "name": "Chevrolet Corvette Convertible 2012"}, {"make": "Chevrolet", "model": "Corvette ZR1", "year": 2012, "body_style": "Unknown", "name": "Chevrolet Corvette ZR1 2012"}, {"make": "Chevrolet", "model": "Corvette Ron Fellows Edition Z06", "year": 2007, "body_style": "Unknown", "name": "Chevrolet Corvette Ron Fellows Edition Z06 2007"}, {"make": "Chevrolet", "model": "Traverse SUV", "year": 2012, "body_style": "SUV", "name": "Chevrolet Traverse SUV 2012"}, {"make": "Chevrolet", "model": "Camaro Convertible", "year": 2012, "body_style": "Convertible", "name": "Chevrolet Camaro Convertible 2012"}, {"make": "Chevrolet", "model": "HHR SS", "year": 2010, "body_style": "Unknown", "name": "Chevrolet HHR SS 2010"}, {"make": "Chevrolet", "model": "Impala Sedan", "year": 2007, "body_style": "Sedan", "name": "Chevrolet Impala Sedan 2007"}, {"make": "Chevrolet", "model": "Tahoe Hybrid SUV", "year": 2012, "body_style": "SUV", "name": "Chevrolet Tahoe Hybrid SUV 2012"}, {"make": "Chevrolet", "model": "Sonic Sedan", "year": 2012, "body_style": "Sedan", "name": "Chevrolet Sonic Sedan 2012"}, {"make": "Chevrolet", "model": "Express Cargo Van", "year": 2007, "body_style": "Van", "name": "Chevrolet Express Cargo Van 2007"}, {"make": "Chevrolet", "model": "Avalanche Crew Cab", "year": 2012, "body_style": "Crew Cab", "name": "Chevrolet Avalanche Crew Cab 2012"}, {"make": "Chevrolet", "model": "Cobalt SS", "year": 2010, "body_style": "Unknown", "name": "Chevrolet Cobalt SS 2010"}, {"make": "Chevrolet", "model": "Malibu Hybrid Sedan", "year": 2010, "body_style": "Sedan", "name": "Chevrolet Malibu Hybrid Sedan 2010"}, {"make": "Chevrolet", "model": "TrailBlazer SS", "year": 2009, "body_style": "Unknown", "name": "Chevrolet TrailBlazer SS 2009"}, {"make": "Chevrolet", "model": "Silverado 2500HD Regular Cab", "year": 2012, "body_style": "Regular Cab", "name": "Chevrolet Silverado 2500HD Regular Cab 2012"}, {"make": "Chevrolet", "model": "Silverado 1500 Classic Extended Cab", "year": 2007, "body_style": "Extended Cab", "name": "Chevrolet Silverado 1500 Classic Extended Cab 2007"}, {"make": "Chevrolet", "model": "Express Van", "year": 2007, "body_style": "Van", "name": "Chevrolet Express Van 2007"}, {"make": "Chevrolet", "model": "Monte Carlo Coupe", "year": 2007, "body_style": "Coupe", "name": "Chevrolet Monte Carlo Coupe 2007"}, {"make": "Chevrolet", "model": "Malibu Sedan", "year": 2007, "body_style": "Sedan", "name": "Chevrolet Malibu Sedan 2007"}, {"make": "Chevrolet", "model": "Silverado 1500 Extended Cab", "year": 2012, "body_style": "Extended Cab", "name": "Chevrolet Silverado 1500 Extended Cab 2012"}, {"make": "Chevrolet", "model": "Silverado 1500 Regular Cab", "year": 2012, "body_style": "Regular Cab", "name": "Chevrolet Silverado 1500 Regular Cab 2012"}, {"make": "Chrysler", "model": "Aspen SUV", "year": 2009, "body_style": "SUV", "name": "Chrysler Aspen SUV 2009"}, {"make": "Chrysler", "model": "Sebring Convertible", "year": 2010, "body_style": "Convertible", "name": "Chrysler Sebring Convertible 2010"}, {"make": "Chrysler", "model": "Town and Country Minivan", "year": 2012, "body_style": "Minivan", "name": "Chrysler Town and Country Minivan 2012"}, {"make": "Chrysler", "model": "300 SRT-8", "year": 2010, "body_style": "Unknown", "name": "Chrysler 300 SRT-8 2010"}, {"make": "Chrysler", "model": "Crossfire Convertible", "year": 2008, "body_style": "Convertible", "name": "Chrysler Crossfire Convertible 2008"}, {"make": "Chrysler", "model": "PT Cruiser Convertible", "year": 2008, "body_style": "Convertible", "name": "Chrysler PT Cruiser Convertible 2008"}, {"make": "Daewoo", "model": "Nubira Wagon", "year": 2002, "body_style": "Wagon", "name": "Daewoo Nubira Wagon 2002"}, {"make": "Dodge", "model": "Caliber Wagon", "year": 2012, "body_style": "Wagon", "name": "Dodge Caliber Wagon 2012"}, {"make": "Dodge", "model": "Caliber Wagon", "year": 2007, "body_style": "Wagon", "name": "Dodge Caliber Wagon 2007"}, {"make": "Dodge", "model": "Caravan Minivan", "year": 1997, "body_style": "Minivan", "name": "Dodge Caravan Minivan 1997"}, {"make": "Dodge", "model": "Ram Pickup 3500 Crew Cab", "year": 2010, "body_style": "Crew Cab", "name": "Dodge Ram Pickup 3500 Crew Cab 2010"}, {"make": "Dodge", "model": "Ram Pickup 3500 Quad Cab", "year": 2009, "body_style": "Cab", "name": "Dodge Ram Pickup 3500 Quad Cab 2009"}, {"make": "Dodge", "model": "Sprinter Cargo Van", "year": 2009, "body_style": "Van", "name": "Dodge Sprinter Cargo Van 2009"}, {"make": "Dodge", "model": "Journey SUV", "year": 2012, "body_style": "SUV", "name": "Dodge Journey SUV 2012"}, {"make": "Dodge", "model": "Dakota Crew Cab", "year": 2010, "body_style": "Crew Cab", "name": "Dodge Dakota Crew Cab 2010"}, {"make": "Dodge", "model": "Dakota Club Cab", "year": 2007, "body_style": "Cab", "name": "Dodge Dakota Club Cab 2007"}, {"make": "Dodge", "model": "Magnum Wagon", "year": 2008, "body_style": "Wagon", "name": "Dodge Magnum Wagon 2008"}, {"make": "Dodge", "model": "Challenger SRT8", "year": 2011, "body_style": "Unknown", "name": "Dodge Challenger SRT8 2011"}, {"make": "Dodge", "model": "Durango SUV", "year": 2012, "body_style": "SUV", "name": "Dodge Durango SUV 2012"}, {"make": "Dodge", "model": "Durango SUV", "year": 2007, "body_style": "SUV", "name": "Dodge Durango SUV 2007"}, {"make": "Dodge", "model": "Charger Sedan", "year": 2012, "body_style": "Sedan", "name": "Dodge Charger Sedan 2012"}, {"make": "Dodge", "model": "Charger SRT-8", "year": 2009, "body_style": "Unknown", "name": "Dodge Charger SRT-8 2009"}, {"make": "Eagle", "model": "Talon Hatchback", "year": 1998, "body_style": "Hatchback", "name": "Eagle Talon Hatchback 1998"}, {"make": "FIAT", "model": "500 Abarth", "year": 2012, "body_style": "Unknown", "name": "FIAT 500 Abarth 2012"}, {"make": "FIAT", "model": "500 Convertible", "year": 2012, "body_style": "Convertible", "name": "FIAT 500 Convertible 2012"}, {"make": "Ferrari", "model": "FF Coupe", "year": 2012, "body_style": "Coupe", "name": "Ferrari FF Coupe 2012"}, {"make": "Ferrari", "model": "California Convertible", "year": 2012, "body_style": "Convertible", "name": "Ferrari California Convertible 2012"}, {"make": "Ferrari", "model": "458 Italia Convertible", "year": 2012, "body_style": "Convertible", "name": "Ferrari 458 Italia Convertible 2012"}, {"make": "Ferrari", "model": "458 Italia Coupe", "year": 2012, "body_style": "Coupe", "name": "Ferrari 458 Italia Coupe 2012"}, {"make": "Fisker", "model": "Karma Sedan", "year": 2012, "body_style": "Sedan", "name": "Fisker Karma Sedan 2012"}, {"make": "Ford", "model": "F-450 Super Duty Crew Cab", "year": 2012, "body_style": "Crew Cab", "name": "Ford F-450 Super Duty Crew Cab 2012"}, {"make": "Ford", "model": "Mustang Convertible", "year": 2007, "body_style": "Convertible", "name": "Ford Mustang Convertible 2007"}, {"make": "Ford", "model": "Freestar Minivan", "year": 2007, "body_style": "Minivan", "name": "Ford Freestar Minivan 2007"}, {"make": "Ford", "model": "Expedition EL SUV", "year": 2009, "body_style": "SUV", "name": "Ford Expedition EL SUV 2009"}, {"make": "Ford", "model": "Edge SUV", "year": 2012, "body_style": "SUV", "name": "Ford Edge SUV 2012"}, {"make": "Ford", "model": "Ranger SuperCab", "year": 2011, "body_style": "SuperCab", "name": "Ford Ranger SuperCab 2011"}, {"make": "Ford", "model": "GT Coupe", "year": 2006, "body_style": "Coupe", "name": "Ford GT Coupe 2006"}, {"make": "Ford", "model": "F-150 Regular Cab", "year": 2012, "body_style": "Regular Cab", "name": "Ford F-150 Regular Cab 2012"}, {"make": "Ford", "model": "F-150 Regular Cab", "year": 2007, "body_style": "Regular Cab", "name": "Ford F-150 Regular Cab 2007"}, {"make": "Ford", "model": "Focus Sedan", "year": 2007, "body_style": "Sedan", "name": "Ford Focus Sedan 2007"}, {"make": "Ford", "model": "E-Series Wagon Van", "year": 2012, "body_style": "Wagon", "name": "Ford E-Series Wagon Van 2012"}, {"make": "Ford", "model": "Fiesta Sedan", "year": 2012, "body_style": "Sedan", "name": "Ford Fiesta Sedan 2012"}, {"make": "GMC", "model": "Terrain SUV", "year": 2012, "body_style": "SUV", "name": "GMC Terrain SUV 2012"}, {"make": "GMC", "model": "Savana Van", "year": 2012, "body_style": "Van", "name": "GMC Savana Van 2012"}, {"make": "GMC", "model": "Yukon Hybrid SUV", "year": 2012, "body_style": "SUV", "name": "GMC Yukon Hybrid SUV 2012"}, {"make": "GMC", "model": "Acadia SUV", "year": 2012, "body_style": "SUV", "name": "GMC Acadia SUV 2012"}, {"make": "GMC", "model": "Canyon Extended Cab", "year": 2012, "body_style": "Extended Cab", "name": "GMC Canyon Extended Cab 2012"}, {"make": "Geo", "model": "Metro Convertible", "year": 1993, "body_style": "Convertible", "name": "Geo Metro Convertible 1993"}, {"make": "HUMMER", "model": "H3T Crew Cab", "year": 2010, "body_style": "Crew Cab", "name": "HUMMER H3T Crew Cab 2010"}, {"make": "HUMMER", "model": "H2 SUT Crew Cab", "year": 2009, "body_style": "Crew Cab", "name": "HUMMER H2 SUT Crew Cab 2009"}, {"make": "Honda", "model": "Odyssey Minivan", "year": 2012, "body_style": "Minivan", "name": "Honda Odyssey Minivan 2012"}, {"make": "Honda", "model": "Odyssey Minivan", "year": 2007, "body_style": "Minivan", "name": "Honda Odyssey Minivan 2007"}, {"make": "Honda", "model": "Accord Coupe", "year": 2012, "body_style": "Coupe", "name": "Honda Accord Coupe 2012"}, {"make": "Honda", "model": "Accord Sedan", "year": 2012, "body_style": "Sedan", "name": "Honda Accord Sedan 2012"}, {"make": "Hyundai", "model": "Veloster Hatchback", "year": 2012, "body_style": "Hatchback", "name": "Hyundai Veloster Hatchback 2012"}, {"make": "Hyundai", "model": "Santa Fe SUV", "year": 2012, "body_style": "SUV", "name": "Hyundai Santa Fe SUV 2012"}, {"make": "Hyundai", "model": "Tucson SUV", "year": 2012, "body_style": "SUV", "name": "Hyundai Tucson SUV 2012"}, {"make": "Hyundai", "model": "Veracruz SUV", "year": 2012, "body_style": "SUV", "name": "Hyundai Veracruz SUV 2012"}, {"make": "Hyundai", "model": "Sonata Hybrid Sedan", "year": 2012, "body_style": "Sedan", "name": "Hyundai Sonata Hybrid Sedan 2012"}, {"make": "Hyundai", "model": "Elantra Sedan", "year": 2007, "body_style": "Sedan", "name": "Hyundai Elantra Sedan 2007"}, {"make": "Hyundai", "model": "Accent Sedan", "year": 2012, "body_style": "Sedan", "name": "Hyundai Accent Sedan 2012"}, {"make": "Hyundai", "model": "Genesis Sedan", "year": 2012, "body_style": "Sedan", "name": "Hyundai Genesis Sedan 2012"}, {"make": "Hyundai", "model": "Sonata Sedan", "year": 2012, "body_style": "Sedan", "name": "Hyundai Sonata Sedan 2012"}, {"make": "Hyundai", "model": "Elantra Touring Hatchback", "year": 2012, "body_style": "Hatchback", "name": "Hyundai Elantra Touring Hatchback 2012"}, {"make": "Hyundai", "model": "Azera Sedan", "year": 2012, "body_style": "Sedan", "name": "Hyundai Azera Sedan 2012"}, {"make": "Infiniti", "model": "G Coupe IPL", "year": 2012, "body_style": "Coupe", "name": "Infiniti G Coupe IPL 2012"}, {"make": "Infiniti", "model": "QX56 SUV", "year": 2011, "body_style": "SUV", "name": "Infiniti QX56 SUV 2011"}, {"make": "Isuzu", "model": "Ascender SUV", "year": 2008, "body_style": "SUV", "name": "Isuzu Ascender SUV 2008"}, {"make": "Jaguar", "model": "XK XKR", "year": 2012, "body_style": "Unknown", "name": "Jaguar XK XKR 2012"}, {"make": "Jeep", "model": "Patriot SUV", "year": 2012, "body_style": "SUV", "name": "Jeep Patriot SUV 2012"}, {"make": "Jeep", "model": "Wrangler SUV", "year": 2012, "body_style": "SUV", "name": "Jeep Wrangler SUV 2012"}, {"make": "Jeep", "model": "Liberty SUV", "year": 2012, "body_style": "SUV", "name": "Jeep Liberty SUV 2012"}, {"make": "Jeep", "model": "Grand Cherokee SUV", "year": 2012, "body_style": "SUV", "name": "Jeep Grand Cherokee SUV 2012"}, {"make": "Jeep", "model": "Compass SUV", "year": 2012, "body_style": "SUV", "name": "Jeep Compass SUV 2012"}, {"make": "Lamborghini", "model": "Reventon Coupe", "year": 2008, "body_style": "Coupe", "name": "Lamborghini Reventon Coupe 2008"}, {"make": "Lamborghini", "model": "Aventador Coupe", "year": 2012, "body_style": "Coupe", "name": "Lamborghini Aventador Coupe 2012"}, {"make": "Lamborghini", "model": "Gallardo LP 570-4 Superleggera", "year": 2012, "body_style": "Unknown", "name": "Lamborghini Gallardo LP 570-4 Superleggera 2012"}, {"make": "Lamborghini", "model": "Diablo Coupe", "year": 2001, "body_style": "Coupe", "name": "Lamborghini Diablo Coupe 2001"}, {"make": "Land Rover", "model": "Range Rover SUV", "year": 2012, "body_style": "SUV", "name": "Land Rover Range Rover SUV 2012"}, {"make": "Land Rover", "model": "LR2 SUV", "year": 2012, "body_style": "SUV", "name": "Land Rover LR2 SUV 2012"}, {"make": "Lincoln", "model": "Town Car Sedan", "year": 2011, "body_style": "Sedan", "name": "Lincoln Town Car Sedan 2011"}, {"make": "MINI", "model": "Cooper Roadster Convertible", "year": 2012, "body_style": "Convertible", "name": "MINI Cooper Roadster Convertible 2012"}, {"make": "Maybach", "model": "Landaulet Convertible", "year": 2012, "body_style": "Convertible", "name": "Maybach Landaulet Convertible 2012"}, {"make": "Mazda", "model": "Tribute SUV", "year": 2011, "body_style": "SUV", "name": "Mazda Tribute SUV 2011"}, {"make": "McLaren", "model": "MP4-12C Coupe", "year": 2012, "body_style": "Coupe", "name": "McLaren MP4-12C Coupe 2012"}, {"make": "Mercedes-Benz", "model": "300-Class Convertible", "year": 1993, "body_style": "Convertible", "name": "Mercedes-Benz 300-Class Convertible 1993"}, {"make": "Mercedes-Benz", "model": "C-Class Sedan", "year": 2012, "body_style": "Sedan", "name": "Mercedes-Benz C-Class Sedan 2012"}, {"make": "Mercedes-Benz", "model": "SL-Class Coupe", "year": 2009, "body_style": "Coupe", "name": "Mercedes-Benz SL-Class Coupe 2009"}, {"make": "Mercedes-Benz", "model": "E-Class Sedan", "year": 2012, "body_style": "Sedan", "name": "Mercedes-Benz E-Class Sedan 2012"}, {"make": "Mercedes-Benz", "model": "S-Class Sedan", "year": 2012, "body_style": "Sedan", "name": "Mercedes-Benz S-Class Sedan 2012"}, {"make": "Mercedes-Benz", "model": "Sprinter Van", "year": 2012, "body_style": "Van", "name": "Mercedes-Benz Sprinter Van 2012"}, {"make": "Mitsubishi", "model": "Lancer Sedan", "year": 2012, "body_style": "Sedan", "name": "Mitsubishi Lancer Sedan 2012"}, {"make": "Nissan", "model": "Leaf Hatchback", "year": 2012, "body_style": "Hatchback", "name": "Nissan Leaf Hatchback 2012"}, {"make": "Nissan", "model": "NV Passenger Van", "year": 2012, "body_style": "Van", "name": "Nissan NV Passenger Van 2012"}, {"make": "Nissan", "model": "Juke Hatchback", "year": 2012, "body_style": "Hatchback", "name": "Nissan Juke Hatchback 2012"}, {"make": "Nissan", "model": "240SX Coupe", "year": 1998, "body_style": "Coupe", "name": "Nissan 240SX Coupe 1998"}, {"make": "Plymouth", "model": "Neon Coupe", "year": 1999, "body_style": "Coupe", "name": "Plymouth Neon Coupe 1999"}, {"make": "Porsche", "model": "Panamera Sedan", "year": 2012, "body_style": "Sedan", "name": "Porsche Panamera Sedan 2012"}, {"make": "Ram", "model": "C/V Cargo Van Minivan", "year": 2012, "body_style": "Minivan", "name": "Ram C/V Cargo Van Minivan 2012"}, {"make": "Rolls-Royce", "model": "Phantom Drophead Coupe Convertible", "year": 2012, "body_style": "Convertible", "name": "Rolls-Royce Phantom Drophead Coupe Convertible 2012"}, {"make": "Rolls-Royce", "model": "Ghost Sedan", "year": 2012, "body_style": "Sedan", "name": "Rolls-Royce Ghost Sedan 2012"}, {"make": "Rolls-Royce", "model": "Phantom Sedan", "year": 2012, "body_style": "Sedan", "name": "Rolls-Royce Phantom Sedan 2012"}, {"make": "Scion", "model": "xD Hatchback", "year": 2012, "body_style": "Hatchback", "name": "Scion xD Hatchback 2012"}, {"make": "Spyker", "model": "C8 Convertible", "year": 2009, "body_style": "Convertible", "name": "Spyker C8 Convertible 2009"}, {"make": "Spyker", "model": "C8 Coupe", "year": 2009, "body_style": "Coupe", "name": "Spyker C8 Coupe 2009"}, {"make": "Suzuki", "model": "Aerio Sedan", "year": 2007, "body_style": "Sedan", "name": "Suzuki Aerio Sedan 2007"}, {"make": "Suzuki", "model": "Kizashi Sedan", "year": 2012, "body_style": "Sedan", "name": "Suzuki Kizashi Sedan 2012"}, {"make": "Suzuki", "model": "SX4 Hatchback", "year": 2012, "body_style": "Hatchback", "name": "Suzuki SX4 Hatchback 2012"}, {"make": "Suzuki", "model": "SX4 Sedan", "year": 2012, "body_style": "Sedan", "name": "Suzuki SX4 Sedan 2012"}, {"make": "Tesla", "model": "Model S Sedan", "year": 2012, "body_style": "Sedan", "name": "Tesla Model S Sedan 2012"}, {"make": "Toyota", "model": "Sequoia SUV", "year": 2012, "body_style": "SUV", "name": "Toyota Sequoia SUV 2012"}, {"make": "Toyota", "model": "Camry Sedan", "year": 2012, "body_style": "Sedan", "name": "Toyota Camry Sedan 2012"}, {"make": "Toyota", "model": "Corolla Sedan", "year": 2012, "body_style": "Sedan", "name": "Toyota Corolla Sedan 2012"}, {"make": "Toyota", "model": "4Runner SUV", "year": 2012, "body_style": "SUV", "name": "Toyota 4Runner SUV 2012"}, {"make": "Volkswagen", "model": "Golf Hatchback", "year": 2012, "body_style": "Hatchback", "name": "Volkswagen Golf Hatchback 2012"}, {"make": "Volkswagen", "model": "Golf Hatchback", "year": 1991, "body_style": "Hatchback", "name": "Volkswagen Golf Hatchback 1991"}, {"make": "Volkswagen", "model": "Beetle Hatchback", "year": 2012, "body_style": "Hatchback", "name": "Volkswagen Beetle Hatchback 2012"}, {"make": "Volvo", "model": "C30 Hatchback", "year": 2012, "body_style": "Hatchback", "name": "Volvo C30 Hatchback 2012"}, {"make": "Volvo", "model": "240 Sedan", "year": 1993, "body_style": "Sedan", "name": "Volvo 240 Sedan 1993"}, {"make": "Volvo", "model": "XC90 SUV", "year": 2007, "body_style": "SUV", "name": "Volvo XC90 SUV 2007"}, {"make": "smart", "model": "fortwo Convertible", "year": 2012, "body_style": "Convertible", "name": "smart fortwo Convertible 2012"}]
|
data/eval_results.json
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"n_test": 8041,
|
| 3 |
+
"model": "convnext_tiny_224",
|
| 4 |
+
"params_m": 27.97,
|
| 5 |
+
"hybrid_weights": {
|
| 6 |
+
"w_full": 0.0,
|
| 7 |
+
"w_classical": 0.1,
|
| 8 |
+
"fusion_t": 1.05
|
| 9 |
+
},
|
| 10 |
+
"comparison": [
|
| 11 |
+
{
|
| 12 |
+
"name": "Classical only",
|
| 13 |
+
"top1": 19.02,
|
| 14 |
+
"top5": 41.49,
|
| 15 |
+
"latency_ms": 18.5,
|
| 16 |
+
"size_mb": 2.3
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"name": "Deep learning only",
|
| 20 |
+
"top1": 92.35,
|
| 21 |
+
"top5": 98.86,
|
| 22 |
+
"latency_ms": 70.8,
|
| 23 |
+
"size_mb": 53.4
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"name": "Hybrid (FP32, ONNX Runtime)",
|
| 27 |
+
"top1": 93.99,
|
| 28 |
+
"top5": 99.08,
|
| 29 |
+
"latency_ms": 206.3,
|
| 30 |
+
"size_mb": 115.4
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"name": "Hybrid INT8 (ONNX Runtime)",
|
| 34 |
+
"top1": 93.94,
|
| 35 |
+
"top5": 99.09,
|
| 36 |
+
"latency_ms": 138.7,
|
| 37 |
+
"size_mb": 40.9
|
| 38 |
+
}
|
| 39 |
+
],
|
| 40 |
+
"ablation": [
|
| 41 |
+
{
|
| 42 |
+
"name": "A. Classical only (YOLO ROI + HOG/LBP/HSV + LogReg)",
|
| 43 |
+
"top1": 19.02,
|
| 44 |
+
"top5": 41.49,
|
| 45 |
+
"delta": ""
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"name": "B. Deep learning only (full image)",
|
| 49 |
+
"top1": 92.35,
|
| 50 |
+
"top5": 98.86,
|
| 51 |
+
"delta": ""
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"name": "C. B + adaptive CLAHE gate",
|
| 55 |
+
"top1": 92.29,
|
| 56 |
+
"top5": 98.83,
|
| 57 |
+
"delta": "-0.06"
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"name": "D. YOLO ROI crop + deep learning",
|
| 61 |
+
"top1": 94.01,
|
| 62 |
+
"top5": 99.09,
|
| 63 |
+
"delta": "+1.72"
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"name": "E. D + horizontal-flip TTA",
|
| 67 |
+
"top1": 94.17,
|
| 68 |
+
"top5": 99.09,
|
| 69 |
+
"delta": "+0.16"
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"name": "F. E + full-frame context fusion",
|
| 73 |
+
"top1": 94.17,
|
| 74 |
+
"top5": 99.09,
|
| 75 |
+
"delta": "+0.00"
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"name": "G. F + adaptive CLAHE gate",
|
| 79 |
+
"top1": 94.17,
|
| 80 |
+
"top5": 99.07,
|
| 81 |
+
"delta": "+0.00"
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"name": "H. G + classical late fusion (full hybrid)",
|
| 85 |
+
"top1": 93.99,
|
| 86 |
+
"top5": 99.08,
|
| 87 |
+
"delta": "-0.18"
|
| 88 |
+
}
|
| 89 |
+
],
|
| 90 |
+
"upper_bound_gt_crop": [
|
| 91 |
+
94.01,
|
| 92 |
+
99.23
|
| 93 |
+
],
|
| 94 |
+
"detection": {
|
| 95 |
+
"n": 8000,
|
| 96 |
+
"mean_iou": 0.9302,
|
| 97 |
+
"median_iou": 0.9522,
|
| 98 |
+
"iou_ge_0.5": 98.76,
|
| 99 |
+
"recall": 99.03,
|
| 100 |
+
"map50": 0.7769,
|
| 101 |
+
"map50_95": 0.7128
|
| 102 |
+
},
|
| 103 |
+
"int8": {
|
| 104 |
+
"top1": 93.94,
|
| 105 |
+
"top5": 99.09,
|
| 106 |
+
"size_mb": 32.4
|
| 107 |
+
},
|
| 108 |
+
"latency": {
|
| 109 |
+
"threads": 2,
|
| 110 |
+
"n_images": 40,
|
| 111 |
+
"dl_only": {
|
| 112 |
+
"detection_ms": 0.0,
|
| 113 |
+
"classical_ms": 1.1,
|
| 114 |
+
"classifier_ms": 69.8,
|
| 115 |
+
"total_ms": 70.8,
|
| 116 |
+
"p90_ms": 77.4
|
| 117 |
+
},
|
| 118 |
+
"torch_fp32": {
|
| 119 |
+
"detection_ms": 11.4,
|
| 120 |
+
"classical_ms": 0.9,
|
| 121 |
+
"classifier_ms": 134.1,
|
| 122 |
+
"classical_head_ms": 16.2,
|
| 123 |
+
"total_ms": 165.6,
|
| 124 |
+
"p90_ms": 188.4
|
| 125 |
+
},
|
| 126 |
+
"fp32": {
|
| 127 |
+
"detection_ms": 62.0,
|
| 128 |
+
"classical_ms": 0.9,
|
| 129 |
+
"classifier_ms": 127.1,
|
| 130 |
+
"classical_head_ms": 16.1,
|
| 131 |
+
"total_ms": 206.3,
|
| 132 |
+
"p90_ms": 211.3
|
| 133 |
+
},
|
| 134 |
+
"int8": {
|
| 135 |
+
"detection_ms": 53.2,
|
| 136 |
+
"classical_ms": 0.9,
|
| 137 |
+
"classifier_ms": 66.7,
|
| 138 |
+
"classical_head_ms": 16.4,
|
| 139 |
+
"total_ms": 138.7,
|
| 140 |
+
"p90_ms": 149.5
|
| 141 |
+
},
|
| 142 |
+
"classical_ms": 18.5
|
| 143 |
+
},
|
| 144 |
+
"confidence": {
|
| 145 |
+
"avg_conf_all": 94.96,
|
| 146 |
+
"avg_conf_correct": 96.47,
|
| 147 |
+
"avg_conf_wrong": 71.34,
|
| 148 |
+
"low_conf_rate": 2.44,
|
| 149 |
+
"acc_when_flagged": 46.94,
|
| 150 |
+
"acc_when_confident": 95.17,
|
| 151 |
+
"ece_hybrid": 1.79,
|
| 152 |
+
"temperature": 0.55,
|
| 153 |
+
"sweep": [
|
| 154 |
+
{
|
| 155 |
+
"threshold": 0.3,
|
| 156 |
+
"coverage": 99.39,
|
| 157 |
+
"accuracy_on_accepted": 94.33
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"threshold": 0.4,
|
| 161 |
+
"coverage": 98.57,
|
| 162 |
+
"accuracy_on_accepted": 94.79
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"threshold": 0.5,
|
| 166 |
+
"coverage": 97.56,
|
| 167 |
+
"accuracy_on_accepted": 95.17
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"threshold": 0.6,
|
| 171 |
+
"coverage": 95.86,
|
| 172 |
+
"accuracy_on_accepted": 95.8
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"threshold": 0.7,
|
| 176 |
+
"coverage": 93.86,
|
| 177 |
+
"accuracy_on_accepted": 96.5
|
| 178 |
+
},
|
| 179 |
+
{
|
| 180 |
+
"threshold": 0.8,
|
| 181 |
+
"coverage": 91.28,
|
| 182 |
+
"accuracy_on_accepted": 97.15
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"threshold": 0.9,
|
| 186 |
+
"coverage": 87.1,
|
| 187 |
+
"accuracy_on_accepted": 97.69
|
| 188 |
+
}
|
| 189 |
+
]
|
| 190 |
+
},
|
| 191 |
+
"robustness": {
|
| 192 |
+
"methods": [
|
| 193 |
+
"Classical",
|
| 194 |
+
"DL only",
|
| 195 |
+
"Hybrid",
|
| 196 |
+
"Detect %"
|
| 197 |
+
],
|
| 198 |
+
"rows": [
|
| 199 |
+
{
|
| 200 |
+
"condition": "clean",
|
| 201 |
+
"values": [
|
| 202 |
+
17.65,
|
| 203 |
+
92.35,
|
| 204 |
+
93.27,
|
| 205 |
+
99.0
|
| 206 |
+
]
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"condition": "low light",
|
| 210 |
+
"values": [
|
| 211 |
+
6.02,
|
| 212 |
+
86.73,
|
| 213 |
+
87.65,
|
| 214 |
+
89.0
|
| 215 |
+
]
|
| 216 |
+
},
|
| 217 |
+
{
|
| 218 |
+
"condition": "over exposure",
|
| 219 |
+
"values": [
|
| 220 |
+
10.1,
|
| 221 |
+
88.37,
|
| 222 |
+
90.71,
|
| 223 |
+
96.3
|
| 224 |
+
]
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"condition": "motion blur",
|
| 228 |
+
"values": [
|
| 229 |
+
10.92,
|
| 230 |
+
84.69,
|
| 231 |
+
88.06,
|
| 232 |
+
97.9
|
| 233 |
+
]
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"condition": "gaussian noise",
|
| 237 |
+
"values": [
|
| 238 |
+
9.18,
|
| 239 |
+
88.88,
|
| 240 |
+
90.71,
|
| 241 |
+
86.8
|
| 242 |
+
]
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"condition": "occlusion",
|
| 246 |
+
"values": [
|
| 247 |
+
3.98,
|
| 248 |
+
82.55,
|
| 249 |
+
83.88,
|
| 250 |
+
98.4
|
| 251 |
+
]
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"condition": "viewpoint",
|
| 255 |
+
"values": [
|
| 256 |
+
17.14,
|
| 257 |
+
90.31,
|
| 258 |
+
92.86,
|
| 259 |
+
98.8
|
| 260 |
+
]
|
| 261 |
+
},
|
| 262 |
+
{
|
| 263 |
+
"condition": "low resolution",
|
| 264 |
+
"values": [
|
| 265 |
+
9.29,
|
| 266 |
+
66.53,
|
| 267 |
+
64.49,
|
| 268 |
+
89.6
|
| 269 |
+
]
|
| 270 |
+
}
|
| 271 |
+
],
|
| 272 |
+
"n": 980
|
| 273 |
+
},
|
| 274 |
+
"failures": {
|
| 275 |
+
"top_confusions": {
|
| 276 |
+
"Audi TTS Coupe 2012 -> Audi TT Hatchback 2011": 13,
|
| 277 |
+
"Chevrolet Express Van 2007 -> Chevrolet Express Cargo Van 2007": 12,
|
| 278 |
+
"Audi S5 Coupe 2012 -> Audi A5 Coupe 2012": 12,
|
| 279 |
+
"Bentley Continental GT Coupe 2012 -> Bentley Continental GT Coupe 2007": 11,
|
| 280 |
+
"Audi V8 Sedan 1994 -> Audi 100 Sedan 1994": 11,
|
| 281 |
+
"BMW 6 Series Convertible 2007 -> BMW M6 Convertible 2010": 10,
|
| 282 |
+
"Dodge Caliber Wagon 2012 -> Dodge Caliber Wagon 2007": 9,
|
| 283 |
+
"Suzuki SX4 Sedan 2012 -> Suzuki Aerio Sedan 2007": 9,
|
| 284 |
+
"Audi TT Hatchback 2011 -> Audi TTS Coupe 2012": 9,
|
| 285 |
+
"Chevrolet Express Cargo Van 2007 -> Chevrolet Express Van 2007": 8
|
| 286 |
+
},
|
| 287 |
+
"worst_classes": {
|
| 288 |
+
"Chevrolet Express Van 2007": 48.6,
|
| 289 |
+
"Chevrolet Express Cargo Van 2007": 58.6,
|
| 290 |
+
"Audi TTS Coupe 2012": 64.3,
|
| 291 |
+
"Audi TT Hatchback 2011": 67.5,
|
| 292 |
+
"Bentley Continental GT Coupe 2012": 67.6,
|
| 293 |
+
"Audi S5 Coupe 2012": 71.4,
|
| 294 |
+
"Chevrolet Silverado 2500HD Regular Cab 2012": 73.7,
|
| 295 |
+
"Audi V8 Sedan 1994": 74.4
|
| 296 |
+
},
|
| 297 |
+
"n_errors": 483,
|
| 298 |
+
"high_conf_examples": [
|
| 299 |
+
{
|
| 300 |
+
"path": "images/test/test_00032.jpg",
|
| 301 |
+
"true": "Toyota Corolla Sedan 2012",
|
| 302 |
+
"pred": "Toyota Camry Sedan 2012",
|
| 303 |
+
"conf": 100.0,
|
| 304 |
+
"iou": 0.86
|
| 305 |
+
},
|
| 306 |
+
{
|
| 307 |
+
"path": "images/test/test_01275.jpg",
|
| 308 |
+
"true": "Ferrari 458 Italia Coupe 2012",
|
| 309 |
+
"pred": "Ferrari 458 Italia Convertible 2012",
|
| 310 |
+
"conf": 100.0,
|
| 311 |
+
"iou": 0.944
|
| 312 |
+
},
|
| 313 |
+
{
|
| 314 |
+
"path": "images/test/test_07585.jpg",
|
| 315 |
+
"true": "Chevrolet Silverado 1500 Regular Cab 2012",
|
| 316 |
+
"pred": "Chevrolet Silverado 2500HD Regular Cab 2012",
|
| 317 |
+
"conf": 100.0,
|
| 318 |
+
"iou": 0.973
|
| 319 |
+
},
|
| 320 |
+
{
|
| 321 |
+
"path": "images/test/test_02541.jpg",
|
| 322 |
+
"true": "BMW 6 Series Convertible 2007",
|
| 323 |
+
"pred": "BMW M6 Convertible 2010",
|
| 324 |
+
"conf": 100.0,
|
| 325 |
+
"iou": 0.97
|
| 326 |
+
},
|
| 327 |
+
{
|
| 328 |
+
"path": "images/test/test_05220.jpg",
|
| 329 |
+
"true": "Dodge Durango SUV 2007",
|
| 330 |
+
"pred": "Chrysler Aspen SUV 2009",
|
| 331 |
+
"conf": 100.0,
|
| 332 |
+
"iou": 0.921
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"path": "images/test/test_01999.jpg",
|
| 336 |
+
"true": "Bentley Continental GT Coupe 2012",
|
| 337 |
+
"pred": "Bentley Continental GT Coupe 2007",
|
| 338 |
+
"conf": 100.0,
|
| 339 |
+
"iou": 0.946
|
| 340 |
+
}
|
| 341 |
+
]
|
| 342 |
+
},
|
| 343 |
+
"browser": {
|
| 344 |
+
"top1": 94.09,
|
| 345 |
+
"top5": 99.07,
|
| 346 |
+
"parity": 98.0
|
| 347 |
+
}
|
| 348 |
+
}
|
index.html
CHANGED
|
@@ -1,19 +1,58 @@
|
|
| 1 |
<!doctype html>
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
| 6 |
+
<title>Visionary</title>
|
| 7 |
+
<meta name="description" content="Fine-grained vehicle recognition (make, model, year; 196 classes) running entirely in your browser.">
|
| 8 |
+
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><circle cx='16' cy='16' r='14' fill='%23c96442'/><circle cx='16' cy='16' r='6' fill='white'/></svg>">
|
| 9 |
+
<!-- Adds COOP/COEP headers via a service worker so WebAssembly can use threads
|
| 10 |
+
on static hosting (one-time reload on first visit). MIT, coi-serviceworker. -->
|
| 11 |
+
<script src="coi-serviceworker.js"></script>
|
| 12 |
+
<link rel="stylesheet" href="styles.css">
|
| 13 |
+
<script src="vendor/ort.wasm.min.js"></script>
|
| 14 |
+
</head>
|
| 15 |
+
<body>
|
| 16 |
+
<header>
|
| 17 |
+
<div class="brand"><div class="dot"></div><span>Visionary</span></div>
|
| 18 |
+
<div class="spacer"></div>
|
| 19 |
+
<button class="iconbtn" id="benchBtn" title="Model comparison">📊 <span class="label">Benchmarks</span></button>
|
| 20 |
+
<div class="picker">
|
| 21 |
+
<button id="pickerBtn"><span id="modelName">Loading…</span> ▾</button>
|
| 22 |
+
<div class="menu" id="menu"></div>
|
| 23 |
+
</div>
|
| 24 |
+
</header>
|
| 25 |
+
|
| 26 |
+
<main id="chat">
|
| 27 |
+
<section class="hero" id="hero">
|
| 28 |
+
<h1>What car is this?</h1>
|
| 29 |
+
<p>Upload a photo. Visionary finds the vehicle, then identifies its make, model and year across 196 classes.</p>
|
| 30 |
+
<div class="samples">
|
| 31 |
+
<button class="sample" data-pick><b>📷 Upload a photo</b><span>JPG, PNG or WEBP · up to 15 MB</span></button>
|
| 32 |
+
<button class="sample" data-pick><b>🌙 Try a night shot</b><span>Low light is auto-corrected with CLAHE</span></button>
|
| 33 |
+
<button class="sample" id="benchSample"><b>📊 See benchmarks</b><span>Classical vs deep vs hybrid</span></button>
|
| 34 |
+
</div>
|
| 35 |
+
<div class="loader" id="loader">
|
| 36 |
+
<div id="loaderText">Preparing models…</div>
|
| 37 |
+
<div class="bar"><i id="loaderBar"></i></div>
|
| 38 |
+
</div>
|
| 39 |
+
<div class="privacy">🔒 Runs entirely on your device. Photos are never uploaded.</div>
|
| 40 |
+
</section>
|
| 41 |
+
</main>
|
| 42 |
+
|
| 43 |
+
<div class="composer">
|
| 44 |
+
<div class="box" id="drop">
|
| 45 |
+
<div class="hint" data-pick><b>Attach</b>, drop or paste a car photo…</div>
|
| 46 |
+
<input type="file" id="file" accept="image/*" hidden>
|
| 47 |
+
<button class="send" id="sendBtn" data-pick aria-label="Upload image">
|
| 48 |
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>
|
| 49 |
+
</button>
|
| 50 |
+
</div>
|
| 51 |
+
<div class="foot">Trained on Stanford Cars (mostly US models up to 2012). Predictions can be wrong; check the alternatives.</div>
|
| 52 |
+
</div>
|
| 53 |
+
|
| 54 |
+
<div class="overlay" id="overlay"><div class="sheet" id="sheet"></div></div>
|
| 55 |
+
|
| 56 |
+
<script type="module" src="app.js"></script>
|
| 57 |
+
</body>
|
| 58 |
</html>
|
models/convnext_small_320_int8.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ad236e1ba41af28dbc3b43c049ab72bef1c1742e976b857ef3f096b5a179d9d2
|
| 3 |
+
size 56977585
|
models/convnext_tiny_224_int8.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:817cfd7e6ab3d84d786174b3141edf8126be3f776a5e1c0c51cff25d06a38ea0
|
| 3 |
+
size 33972056
|
models/models.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"default": "convnext_tiny_224",
|
| 3 |
+
"models": {
|
| 4 |
+
"convnext_tiny_224": {
|
| 5 |
+
"name": "Visionary Lite",
|
| 6 |
+
"desc": "ConvNeXt-Tiny @224 \u00b7 INT8 \u00b7 fastest",
|
| 7 |
+
"file": "models/convnext_tiny_224_int8.onnx",
|
| 8 |
+
"size": 33972056,
|
| 9 |
+
"imgSize": 224,
|
| 10 |
+
"temperature": 0.55,
|
| 11 |
+
"top1": 94.09
|
| 12 |
+
},
|
| 13 |
+
"convnext_small_320": {
|
| 14 |
+
"name": "Visionary Pro",
|
| 15 |
+
"desc": "ConvNeXt-Small @320 \u00b7 INT8 \u00b7 most accurate",
|
| 16 |
+
"file": "models/convnext_small_320_int8.onnx",
|
| 17 |
+
"size": 56977585,
|
| 18 |
+
"imgSize": 320,
|
| 19 |
+
"temperature": 0.6,
|
| 20 |
+
"top1": null
|
| 21 |
+
}
|
| 22 |
+
},
|
| 23 |
+
"assets": {
|
| 24 |
+
"opencv": 10378215,
|
| 25 |
+
"wasm": 11210254,
|
| 26 |
+
"yolo": 12824165
|
| 27 |
+
}
|
| 28 |
+
}
|
models/yolov8n.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5222d8c7e857d3dfdc95756f8dfea0cf4f6b15bf6f84a0cee57eba0f6dede793
|
| 3 |
+
size 12824165
|
pipeline.js
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Visionary — in-browser hybrid inference pipeline.
|
| 3 |
+
*
|
| 4 |
+
* A faithful port of src/hybrid/engine.py that runs entirely client-side:
|
| 5 |
+
* 1. YOLOv8n (ONNX) vehicle detection — Ultralytics letterbox + class-aware NMS
|
| 6 |
+
* 2. ROI crop with 5 % padding — same integer maths as src/detection/cropper.py
|
| 7 |
+
* 3. Adaptive illumination gate — LAB lightness mean/std, CLAHE (clip 2.5, 8x8) if dark/flat
|
| 8 |
+
* 4. ConvNeXt classifier (INT8 ONNX) — bicubic 224 resize, ImageNet norm, ROI + flipped ROI
|
| 9 |
+
* 5. Temperature-calibrated softmax, averaged over views; confidence handling
|
| 10 |
+
* plus the classical-CV visualisation stages (CLAHE, bilateral, Canny, contours).
|
| 11 |
+
*
|
| 12 |
+
* Environment-agnostic: works in the browser and in Node (used by web/test/parity.mjs).
|
| 13 |
+
* Inputs are ImageData-like objects {data: RGBA Uint8ClampedArray, width, height}.
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
const MEAN = [0.485, 0.456, 0.406];
|
| 17 |
+
const STD = [0.229, 0.224, 0.225];
|
| 18 |
+
const VEHICLE = { 2: "car", 5: "bus", 7: "truck" };
|
| 19 |
+
const YOLO_SIZE = 640;
|
| 20 |
+
const MAX_SIDE = 1600;
|
| 21 |
+
|
| 22 |
+
export class Pipeline {
|
| 23 |
+
/**
|
| 24 |
+
* @param {object} ort onnxruntime-web namespace
|
| 25 |
+
* @param {object} cv initialised OpenCV.js namespace
|
| 26 |
+
* @param {object} cfg { classes, temperature, imgSize, lowConf, detConf, dark, flat }
|
| 27 |
+
*/
|
| 28 |
+
constructor(ort, cv, cfg) {
|
| 29 |
+
this.ort = ort;
|
| 30 |
+
this.cv = cv;
|
| 31 |
+
this.cfg = Object.assign(
|
| 32 |
+
{ temperature: 1, imgSize: 224, lowConf: 0.5, detConf: 0.25, nmsIou: 0.7, dark: 70, flat: 35,
|
| 33 |
+
clahe: 2.5, flipTTA: true, clahegate: true },
|
| 34 |
+
cfg
|
| 35 |
+
);
|
| 36 |
+
this.detector = null;
|
| 37 |
+
this.classifier = null;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
async load(yoloBytes, clsBytes, opts = {}) {
|
| 41 |
+
const so = { executionProviders: ["wasm"], graphOptimizationLevel: "all", ...opts };
|
| 42 |
+
this.detector = await this.ort.InferenceSession.create(yoloBytes, so);
|
| 43 |
+
await this.setClassifier(clsBytes, opts);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
async setClassifier(clsBytes, opts = {}, cfgPatch = {}) {
|
| 47 |
+
const so = { executionProviders: ["wasm"], graphOptimizationLevel: "all", ...opts };
|
| 48 |
+
if (this.classifier && this.classifier.release) await this.classifier.release();
|
| 49 |
+
this.classifier = await this.ort.InferenceSession.create(clsBytes, so);
|
| 50 |
+
Object.assign(this.cfg, cfgPatch);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/* ------------------------------------------------------------------ helpers */
|
| 54 |
+
_rgbMat(img) {
|
| 55 |
+
const cv = this.cv;
|
| 56 |
+
const rgba = cv.matFromImageData(img);
|
| 57 |
+
const rgb = new cv.Mat();
|
| 58 |
+
cv.cvtColor(rgba, rgb, cv.COLOR_RGBA2RGB);
|
| 59 |
+
rgba.delete();
|
| 60 |
+
return rgb;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
static toImageData(cv, rgbOrGray) {
|
| 64 |
+
const out = new cv.Mat();
|
| 65 |
+
if (rgbOrGray.channels() === 1) cv.cvtColor(rgbOrGray, out, cv.COLOR_GRAY2RGBA);
|
| 66 |
+
else cv.cvtColor(rgbOrGray, out, cv.COLOR_RGB2RGBA);
|
| 67 |
+
const res = { data: new Uint8ClampedArray(out.data), width: out.cols, height: out.rows };
|
| 68 |
+
out.delete();
|
| 69 |
+
return res;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
_capSize(rgb) {
|
| 73 |
+
const cv = this.cv;
|
| 74 |
+
const m = Math.max(rgb.rows, rgb.cols);
|
| 75 |
+
if (m <= MAX_SIDE) return rgb;
|
| 76 |
+
const s = MAX_SIDE / m;
|
| 77 |
+
const out = new cv.Mat();
|
| 78 |
+
cv.resize(rgb, out, new cv.Size(Math.round(rgb.cols * s), Math.round(rgb.rows * s)), 0, 0, cv.INTER_AREA);
|
| 79 |
+
rgb.delete();
|
| 80 |
+
return out;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/* ---------------------------------------------------------------- detection */
|
| 84 |
+
async detect(rgb) {
|
| 85 |
+
const cv = this.cv;
|
| 86 |
+
const t0 = now();
|
| 87 |
+
const h = rgb.rows, w = rgb.cols;
|
| 88 |
+
const r = Math.min(YOLO_SIZE / h, YOLO_SIZE / w);
|
| 89 |
+
const nw = Math.round(w * r), nh = Math.round(h * r);
|
| 90 |
+
const dw = (YOLO_SIZE - nw) / 2, dh = (YOLO_SIZE - nh) / 2;
|
| 91 |
+
const top = Math.round(dh - 0.1), left = Math.round(dw - 0.1);
|
| 92 |
+
const bottom = Math.round(dh + 0.1), right = Math.round(dw + 0.1);
|
| 93 |
+
const resized = new cv.Mat();
|
| 94 |
+
if (nw !== w || nh !== h) cv.resize(rgb, resized, new cv.Size(nw, nh), 0, 0, cv.INTER_LINEAR);
|
| 95 |
+
else rgb.copyTo(resized);
|
| 96 |
+
const padded = new cv.Mat();
|
| 97 |
+
cv.copyMakeBorder(resized, padded, top, bottom, left, right, cv.BORDER_CONSTANT, new cv.Scalar(114, 114, 114, 255));
|
| 98 |
+
resized.delete();
|
| 99 |
+
|
| 100 |
+
const N = YOLO_SIZE * YOLO_SIZE;
|
| 101 |
+
const input = new Float32Array(3 * N);
|
| 102 |
+
const d = padded.data;
|
| 103 |
+
for (let i = 0; i < N; i++) {
|
| 104 |
+
input[i] = d[i * 3] / 255;
|
| 105 |
+
input[N + i] = d[i * 3 + 1] / 255;
|
| 106 |
+
input[2 * N + i] = d[i * 3 + 2] / 255;
|
| 107 |
+
}
|
| 108 |
+
padded.delete();
|
| 109 |
+
const feeds = { [this.detector.inputNames[0]]: new this.ort.Tensor("float32", input, [1, 3, YOLO_SIZE, YOLO_SIZE]) };
|
| 110 |
+
const out = (await this.detector.run(feeds))[this.detector.outputNames[0]].data; // [1,84,8400]
|
| 111 |
+
const A = 8400;
|
| 112 |
+
const cands = [];
|
| 113 |
+
for (let a = 0; a < A; a++) {
|
| 114 |
+
let best = -1, bc = -1;
|
| 115 |
+
for (let c = 0; c < 80; c++) {
|
| 116 |
+
const s = out[(4 + c) * A + a];
|
| 117 |
+
if (s > best) { best = s; bc = c; }
|
| 118 |
+
}
|
| 119 |
+
if (best < this.cfg.detConf || !(bc in VEHICLE)) continue;
|
| 120 |
+
const cx = out[a], cy = out[A + a], bw = out[2 * A + a], bh = out[3 * A + a];
|
| 121 |
+
cands.push({ x1: cx - bw / 2, y1: cy - bh / 2, x2: cx + bw / 2, y2: cy + bh / 2, conf: best, cls: bc });
|
| 122 |
+
}
|
| 123 |
+
// Ultralytics: best class per anchor (multi_label=False), class-aware NMS.
|
| 124 |
+
cands.sort((p, q) => q.conf - p.conf);
|
| 125 |
+
const keep = [];
|
| 126 |
+
for (const b of cands) {
|
| 127 |
+
if (keep.some(k => k.cls === b.cls && iou(k, b) > this.cfg.nmsIou)) continue;
|
| 128 |
+
keep.push(b);
|
| 129 |
+
if (keep.length >= 300) break;
|
| 130 |
+
}
|
| 131 |
+
const boxes = keep.map(b => {
|
| 132 |
+
const x1 = clamp((b.x1 - left) / r, 0, w), y1 = clamp((b.y1 - top) / r, 0, h);
|
| 133 |
+
const x2 = clamp((b.x2 - left) / r, 0, w), y2 = clamp((b.y2 - top) / r, 0, h);
|
| 134 |
+
return { box: [x1, y1, x2, y2], conf: b.conf, label: VEHICLE[b.cls] };
|
| 135 |
+
});
|
| 136 |
+
let primary = null;
|
| 137 |
+
for (const b of boxes) {
|
| 138 |
+
const s = (b.box[2] - b.box[0]) * (b.box[3] - b.box[1]) * b.conf;
|
| 139 |
+
if (!primary || s > primary._s) primary = Object.assign({ _s: s }, b);
|
| 140 |
+
}
|
| 141 |
+
return { boxes, primary, ms: now() - t0 };
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/* --------------------------------------------------------------- classical */
|
| 145 |
+
crop(rgb, box, pad = 0.05) {
|
| 146 |
+
if (!box) return rgb.clone();
|
| 147 |
+
const [x1, y1, x2, y2] = box;
|
| 148 |
+
const bw = x2 - x1, bh = y2 - y1;
|
| 149 |
+
const px = pyRound(bw * pad), py = pyRound(bh * pad);
|
| 150 |
+
const cx1 = Math.max(0, Math.trunc(x1) - px), cy1 = Math.max(0, Math.trunc(y1) - py);
|
| 151 |
+
const cx2 = Math.min(rgb.cols, Math.trunc(x2) + px), cy2 = Math.min(rgb.rows, Math.trunc(y2) + py);
|
| 152 |
+
if (cx2 <= cx1 || cy2 <= cy1) return rgb.clone();
|
| 153 |
+
return rgb.roi(new this.cv.Rect(cx1, cy1, cx2 - cx1, cy2 - cy1)).clone();
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
illumination(rgb) {
|
| 157 |
+
const cv = this.cv;
|
| 158 |
+
const lab = new cv.Mat();
|
| 159 |
+
cv.cvtColor(rgb, lab, cv.COLOR_RGB2Lab);
|
| 160 |
+
const d = lab.data;
|
| 161 |
+
let s = 0, s2 = 0;
|
| 162 |
+
const n = d.length / 3;
|
| 163 |
+
for (let i = 0; i < d.length; i += 3) { s += d[i]; s2 += d[i] * d[i]; }
|
| 164 |
+
lab.delete();
|
| 165 |
+
const mean = s / n;
|
| 166 |
+
return { mean_luma: mean, contrast: Math.sqrt(Math.max(0, s2 / n - mean * mean)) };
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
clahe(rgb, clip = this.cfg.clahe) {
|
| 170 |
+
const cv = this.cv;
|
| 171 |
+
const lab = new cv.Mat();
|
| 172 |
+
cv.cvtColor(rgb, lab, cv.COLOR_RGB2Lab);
|
| 173 |
+
const ch = new cv.MatVector();
|
| 174 |
+
cv.split(lab, ch);
|
| 175 |
+
const L = ch.get(0), Leq = new cv.Mat();
|
| 176 |
+
const cl = new cv.CLAHE(clip, new cv.Size(8, 8));
|
| 177 |
+
cl.apply(L, Leq);
|
| 178 |
+
ch.set(0, Leq);
|
| 179 |
+
cv.merge(ch, lab);
|
| 180 |
+
const out = new cv.Mat();
|
| 181 |
+
cv.cvtColor(lab, out, cv.COLOR_Lab2RGB);
|
| 182 |
+
[lab, L, Leq].forEach(m => m.delete());
|
| 183 |
+
ch.delete(); cl.delete();
|
| 184 |
+
return out;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/** CLAHE -> bilateral -> auto-Canny -> contours, as RGBA images for the UI. */
|
| 188 |
+
stages(roi) {
|
| 189 |
+
const cv = this.cv;
|
| 190 |
+
const clahe = this.clahe(roi);
|
| 191 |
+
const den = new cv.Mat();
|
| 192 |
+
cv.bilateralFilter(clahe, den, 9, 75, 75, cv.BORDER_DEFAULT);
|
| 193 |
+
const gray = new cv.Mat(), blur = new cv.Mat(), edges = new cv.Mat();
|
| 194 |
+
cv.cvtColor(den, gray, cv.COLOR_RGB2GRAY);
|
| 195 |
+
cv.GaussianBlur(gray, blur, new cv.Size(3, 3), 0, 0, cv.BORDER_DEFAULT);
|
| 196 |
+
const med = median(blur.data);
|
| 197 |
+
let lo = Math.trunc(Math.max(0, 0.67 * med)), hi = Math.trunc(Math.min(255, 1.33 * med));
|
| 198 |
+
if (lo === hi) { lo = Math.max(0, lo - 30); hi = Math.min(255, hi + 30); }
|
| 199 |
+
cv.Canny(blur, edges, lo, hi);
|
| 200 |
+
const closed = new cv.Mat(), kernel = cv.getStructuringElement(cv.MORPH_RECT, new cv.Size(3, 3));
|
| 201 |
+
cv.morphologyEx(edges, closed, cv.MORPH_CLOSE, kernel);
|
| 202 |
+
const contours = new cv.MatVector(), hier = new cv.Mat();
|
| 203 |
+
cv.findContours(closed, contours, hier, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE);
|
| 204 |
+
const vis = cv.Mat.zeros(edges.rows, edges.cols, cv.CV_8UC3);
|
| 205 |
+
let bestI = -1, bestA = -1;
|
| 206 |
+
const keep = new cv.MatVector();
|
| 207 |
+
for (let i = 0; i < contours.size(); i++) {
|
| 208 |
+
const c = contours.get(i), a = cv.contourArea(c);
|
| 209 |
+
if (a >= 50) {
|
| 210 |
+
keep.push_back(c);
|
| 211 |
+
if (a > bestA) { bestA = a; bestI = keep.size() - 1; }
|
| 212 |
+
}
|
| 213 |
+
c.delete();
|
| 214 |
+
}
|
| 215 |
+
if (keep.size() > 0) {
|
| 216 |
+
cv.drawContours(vis, keep, -1, new cv.Scalar(0, 255, 255), 1);
|
| 217 |
+
cv.drawContours(vis, keep, bestI, new cv.Scalar(0, 255, 0), 2);
|
| 218 |
+
}
|
| 219 |
+
const T = m => Pipeline.toImageData(cv, m);
|
| 220 |
+
const res = [
|
| 221 |
+
{ name: "Vehicle ROI", desc: "YOLOv8 crop of the primary vehicle", img: T(roi) },
|
| 222 |
+
{ name: "CLAHE", desc: "Contrast-limited equalisation on LAB lightness", img: T(clahe) },
|
| 223 |
+
{ name: "Bilateral denoise", desc: "Edge-preserving smoothing", img: T(den) },
|
| 224 |
+
{ name: "Canny edges", desc: `Auto thresholds ${lo}–${hi} (median ± 33%)`, img: T(edges) },
|
| 225 |
+
{ name: "Contours", desc: `${keep.size()} structural contours`, img: T(vis) },
|
| 226 |
+
];
|
| 227 |
+
[clahe, den, gray, blur, edges, closed, kernel, hier, vis].forEach(m => m.delete());
|
| 228 |
+
contours.delete(); keep.delete();
|
| 229 |
+
return res;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
/* ---------------------------------------------------------- classification */
|
| 233 |
+
_prep(rgb, flip, out, offset) {
|
| 234 |
+
const cv = this.cv, S = this.cfg.imgSize;
|
| 235 |
+
let src = rgb, tmp = null;
|
| 236 |
+
if (flip) { tmp = new cv.Mat(); cv.flip(rgb, tmp, 1); src = tmp; }
|
| 237 |
+
const r = new cv.Mat();
|
| 238 |
+
cv.resize(src, r, new cv.Size(S, S), 0, 0, cv.INTER_CUBIC);
|
| 239 |
+
const d = r.data, N = S * S;
|
| 240 |
+
for (let i = 0; i < N; i++) {
|
| 241 |
+
out[offset + i] = (d[i * 3] / 255 - MEAN[0]) / STD[0];
|
| 242 |
+
out[offset + N + i] = (d[i * 3 + 1] / 255 - MEAN[1]) / STD[1];
|
| 243 |
+
out[offset + 2 * N + i] = (d[i * 3 + 2] / 255 - MEAN[2]) / STD[2];
|
| 244 |
+
}
|
| 245 |
+
r.delete();
|
| 246 |
+
if (tmp) tmp.delete();
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
async classify(roi) {
|
| 250 |
+
const S = this.cfg.imgSize, V = this.cfg.flipTTA ? 2 : 1, per = 3 * S * S;
|
| 251 |
+
const buf = new Float32Array(V * per);
|
| 252 |
+
this._prep(roi, false, buf, 0);
|
| 253 |
+
if (V === 2) this._prep(roi, true, buf, per);
|
| 254 |
+
const feeds = { [this.classifier.inputNames[0]]: new this.ort.Tensor("float32", buf, [V, 3, S, S]) };
|
| 255 |
+
const logits = (await this.classifier.run(feeds))[this.classifier.outputNames[0]].data;
|
| 256 |
+
const K = logits.length / V, p = new Float64Array(K);
|
| 257 |
+
for (let v = 0; v < V; v++) {
|
| 258 |
+
const row = softmax(logits.subarray(v * K, (v + 1) * K), this.cfg.temperature);
|
| 259 |
+
for (let k = 0; k < K; k++) p[k] += row[k] / V;
|
| 260 |
+
}
|
| 261 |
+
return p;
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
/* ------------------------------------------------------------ end to end */
|
| 265 |
+
async analyze(img, { withStages = true } = {}) {
|
| 266 |
+
const cv = this.cv;
|
| 267 |
+
const t0 = now();
|
| 268 |
+
const rgb = this._capSize(this._rgbMat(img));
|
| 269 |
+
const det = await this.detect(rgb);
|
| 270 |
+
const box = det.primary ? det.primary.box : null;
|
| 271 |
+
|
| 272 |
+
let t = now();
|
| 273 |
+
const roi = this.crop(rgb, box);
|
| 274 |
+
const illum = this.illumination(roi);
|
| 275 |
+
const gate = this.cfg.clahegate && (illum.mean_luma < this.cfg.dark || illum.contrast < this.cfg.flat);
|
| 276 |
+
const roiIn = gate ? this.clahe(roi) : roi;
|
| 277 |
+
const classicalMs = now() - t;
|
| 278 |
+
|
| 279 |
+
t = now();
|
| 280 |
+
const p = await this.classify(roiIn);
|
| 281 |
+
const classifierMs = now() - t;
|
| 282 |
+
|
| 283 |
+
const order = Array.from(p.keys()).sort((a, b) => p[b] - p[a]).slice(0, 5);
|
| 284 |
+
const conf = p[order[0]], margin = p[order[0]] - p[order[1]];
|
| 285 |
+
let status, message;
|
| 286 |
+
if (!box && conf < this.cfg.lowConf) {
|
| 287 |
+
status = "no_vehicle";
|
| 288 |
+
message = "No vehicle detected in this image. Try a clearer photo of a car.";
|
| 289 |
+
} else if (conf < this.cfg.lowConf) {
|
| 290 |
+
status = "low_confidence";
|
| 291 |
+
message = `Low confidence (${Math.round(conf * 100)}%). The car may be a model outside the 196 Stanford Cars classes, heavily occluded, or shot from an unusual angle — see the top-5 alternatives.`;
|
| 292 |
+
} else {
|
| 293 |
+
status = "ok";
|
| 294 |
+
message = box ? "Vehicle identified." : "Detector found no vehicle box; classified the full frame.";
|
| 295 |
+
}
|
| 296 |
+
t = now();
|
| 297 |
+
const stages = withStages && status !== "no_vehicle" ? this.stages(roi) : [];
|
| 298 |
+
const stagesMs = now() - t;
|
| 299 |
+
const image = Pipeline.toImageData(cv, rgb);
|
| 300 |
+
const result = {
|
| 301 |
+
status, message,
|
| 302 |
+
top5: order.map(i => ({ class_id: i, ...this.cfg.classes[i], confidence: +(p[i] * 100).toFixed(2) })),
|
| 303 |
+
confidence: +(conf * 100).toFixed(2), margin: +(margin * 100).toFixed(2),
|
| 304 |
+
probs: p,
|
| 305 |
+
detection: { box, conf: det.primary ? det.primary.conf : 0, label: det.primary ? det.primary.label : "",
|
| 306 |
+
all: det.boxes, image_size: [rgb.cols, rgb.rows] },
|
| 307 |
+
illumination: { mean_luma: +illum.mean_luma.toFixed(1), contrast: +illum.contrast.toFixed(1), clahe_applied: gate },
|
| 308 |
+
timings: { detection_ms: det.ms, classical_ms: classicalMs, classifier_ms: classifierMs,
|
| 309 |
+
stages_ms: stagesMs, total_ms: now() - t0 },
|
| 310 |
+
stages, image,
|
| 311 |
+
};
|
| 312 |
+
result.prediction = result.top5[0];
|
| 313 |
+
if (roiIn !== roi) roiIn.delete();
|
| 314 |
+
roi.delete(); rgb.delete();
|
| 315 |
+
return result;
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/* ------------------------------------------------------------------ utilities */
|
| 320 |
+
function now() { return (typeof performance !== "undefined" ? performance : Date).now(); }
|
| 321 |
+
function clamp(v, lo, hi) { return Math.min(hi, Math.max(lo, v)); }
|
| 322 |
+
function iou(a, b) {
|
| 323 |
+
const iw = Math.max(0, Math.min(a.x2, b.x2) - Math.max(a.x1, b.x1));
|
| 324 |
+
const ih = Math.max(0, Math.min(a.y2, b.y2) - Math.max(a.y1, b.y1));
|
| 325 |
+
const inter = iw * ih;
|
| 326 |
+
const u = (a.x2 - a.x1) * (a.y2 - a.y1) + (b.x2 - b.x1) * (b.y2 - b.y1) - inter;
|
| 327 |
+
return u > 0 ? inter / u : 0;
|
| 328 |
+
}
|
| 329 |
+
/** Python's round(): half to even. */
|
| 330 |
+
function pyRound(x) {
|
| 331 |
+
const f = Math.floor(x), d = x - f;
|
| 332 |
+
if (d > 0.5) return f + 1;
|
| 333 |
+
if (d < 0.5) return f;
|
| 334 |
+
return f % 2 === 0 ? f : f + 1;
|
| 335 |
+
}
|
| 336 |
+
function softmax(z, T) {
|
| 337 |
+
let m = -Infinity;
|
| 338 |
+
for (const v of z) m = Math.max(m, v / T);
|
| 339 |
+
const e = new Float64Array(z.length);
|
| 340 |
+
let s = 0;
|
| 341 |
+
for (let i = 0; i < z.length; i++) { e[i] = Math.exp(z[i] / T - m); s += e[i]; }
|
| 342 |
+
for (let i = 0; i < z.length; i++) e[i] /= s;
|
| 343 |
+
return e;
|
| 344 |
+
}
|
| 345 |
+
/** numpy.median over uint8 data via histogram. */
|
| 346 |
+
function median(data) {
|
| 347 |
+
const h = new Uint32Array(256);
|
| 348 |
+
for (const v of data) h[v]++;
|
| 349 |
+
const n = data.length;
|
| 350 |
+
const kth = k => { let c = 0; for (let i = 0; i < 256; i++) { c += h[i]; if (c > k) return i; } return 255; };
|
| 351 |
+
return n % 2 ? kth((n - 1) / 2) : (kth(n / 2 - 1) + kth(n / 2)) / 2;
|
| 352 |
+
}
|
styles.css
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root{
|
| 2 |
+
--bg:#faf9f7; --panel:#ffffff; --soft:#f2f0ec; --line:#e6e2dc; --text:#1f1e1c; --muted:#6f6b64;
|
| 3 |
+
--accent:#c96442; --accent-soft:#f6e6df; --ok:#2f7d4f; --warn:#a86a12; --bad:#b3372f;
|
| 4 |
+
--bar:#c96442; --shadow:0 1px 2px rgba(0,0,0,.04),0 4px 16px rgba(0,0,0,.04);
|
| 5 |
+
--r:16px; font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
|
| 6 |
+
}
|
| 7 |
+
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
|
| 8 |
+
--bg:#1c1b19; --panel:#262522; --soft:#2e2d29; --line:#3a3833; --text:#ecebe7; --muted:#a19d94;
|
| 9 |
+
--accent:#e07a55; --accent-soft:#3a2a23; --bar:#e07a55; --shadow:none;}}
|
| 10 |
+
:root[data-theme="dark"]{--bg:#1c1b19; --panel:#262522; --soft:#2e2d29; --line:#3a3833; --text:#ecebe7; --muted:#a19d94;
|
| 11 |
+
--accent:#e07a55; --accent-soft:#3a2a23; --bar:#e07a55; --shadow:none;}
|
| 12 |
+
*{box-sizing:border-box} html,body{height:100%}
|
| 13 |
+
body{margin:0;background:var(--bg);color:var(--text);font-size:15px;line-height:1.5;display:flex;flex-direction:column}
|
| 14 |
+
button{font:inherit;color:inherit;cursor:pointer}
|
| 15 |
+
header{position:sticky;top:0;z-index:5;display:flex;align-items:center;gap:10px;padding:10px 16px;
|
| 16 |
+
background:color-mix(in srgb,var(--bg) 88%,transparent);backdrop-filter:blur(8px);border-bottom:1px solid transparent}
|
| 17 |
+
.brand{display:flex;align-items:center;gap:8px;font-weight:600}
|
| 18 |
+
.dot{width:22px;height:22px;border-radius:50%;background:var(--accent);display:grid;place-items:center}
|
| 19 |
+
.dot::after{content:"";width:8px;height:8px;border-radius:50%;background:#fff}
|
| 20 |
+
.spacer{flex:1}
|
| 21 |
+
.picker{position:relative}
|
| 22 |
+
.picker>button{display:flex;align-items:center;gap:6px;border:1px solid var(--line);background:var(--panel);
|
| 23 |
+
padding:6px 12px;border-radius:999px;font-size:14px}
|
| 24 |
+
.menu{position:absolute;right:0;top:calc(100% + 6px);width:min(320px,calc(100vw - 32px));background:var(--panel);
|
| 25 |
+
border:1px solid var(--line);border-radius:14px;box-shadow:0 8px 30px rgba(0,0,0,.12);padding:6px;display:none}
|
| 26 |
+
.menu.open{display:block}
|
| 27 |
+
.menu button{display:block;width:100%;text-align:left;border:0;background:none;padding:9px 10px;border-radius:10px}
|
| 28 |
+
.menu button:hover,.menu button.sel{background:var(--soft)}
|
| 29 |
+
.menu small{display:block;color:var(--muted);font-size:12.5px}
|
| 30 |
+
.iconbtn{border:1px solid var(--line);background:var(--panel);border-radius:999px;padding:6px 12px;font-size:14px}
|
| 31 |
+
main{flex:1;width:100%;max-width:780px;margin:0 auto;padding:8px 16px 160px}
|
| 32 |
+
.hero{text-align:center;margin:12vh auto 0;max-width:560px}
|
| 33 |
+
.hero h1{font-family:ui-serif,Georgia,serif;font-weight:500;font-size:clamp(26px,5vw,36px);margin:0 0 6px}
|
| 34 |
+
.hero p{color:var(--muted);margin:0 0 22px}
|
| 35 |
+
.samples{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px}
|
| 36 |
+
.sample{border:1px solid var(--line);background:var(--panel);border-radius:14px;padding:12px;text-align:left;font-size:14px}
|
| 37 |
+
.sample:hover{border-color:var(--accent)}
|
| 38 |
+
.sample b{display:block;font-weight:600}
|
| 39 |
+
.sample span{color:var(--muted);font-size:13px}
|
| 40 |
+
.msg{margin:22px 0;animation:in .25s ease}
|
| 41 |
+
@keyframes in{from{opacity:0;transform:translateY(4px)}}
|
| 42 |
+
.user{display:flex;justify-content:flex-end}
|
| 43 |
+
.user img{max-width:min(260px,70%);border-radius:14px;border:1px solid var(--line)}
|
| 44 |
+
.bot{display:flex;gap:12px}
|
| 45 |
+
.bot .dot{flex:0 0 22px;margin-top:2px}
|
| 46 |
+
.body{flex:1;min-width:0}
|
| 47 |
+
.title{font-family:ui-serif,Georgia,serif;font-size:22px;line-height:1.25;margin:0 0 4px}
|
| 48 |
+
.sub{color:var(--muted);font-size:14px;margin-bottom:12px}
|
| 49 |
+
.canvaswrap{position:relative;border-radius:14px;overflow:hidden;border:1px solid var(--line);background:var(--soft)}
|
| 50 |
+
.canvaswrap canvas{display:block;width:100%;height:auto}
|
| 51 |
+
.badge{display:inline-flex;align-items:center;gap:6px;font-size:12.5px;padding:3px 9px;border-radius:999px;background:var(--soft);color:var(--muted);margin:0 6px 6px 0}
|
| 52 |
+
.badge.ok{color:var(--ok)} .badge.warn{color:var(--warn);background:color-mix(in srgb,var(--warn) 12%,transparent)}
|
| 53 |
+
.badge.bad{color:var(--bad);background:color-mix(in srgb,var(--bad) 10%,transparent)}
|
| 54 |
+
.card{background:var(--panel);border:1px solid var(--line);border-radius:var(--r);padding:14px 16px;margin-top:12px;box-shadow:var(--shadow)}
|
| 55 |
+
.card h3{margin:0 0 10px;font-size:13px;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:.04em}
|
| 56 |
+
.row{display:grid;grid-template-columns:minmax(0,1fr) 56px;gap:4px 10px;align-items:center;margin:8px 0}
|
| 57 |
+
.row .n{font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
| 58 |
+
.row .v{font-variant-numeric:tabular-nums;text-align:right;font-size:13.5px;color:var(--muted)}
|
| 59 |
+
.track{grid-column:1/-1;height:6px;border-radius:99px;background:var(--soft);overflow:hidden}
|
| 60 |
+
.fill{height:100%;background:var(--bar);border-radius:99px;width:0;transition:width .6s ease}
|
| 61 |
+
.row.alt .fill{background:color-mix(in srgb,var(--bar) 45%,var(--soft))}
|
| 62 |
+
.kv{display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:10px}
|
| 63 |
+
.kv div{background:var(--soft);border-radius:12px;padding:8px 10px}
|
| 64 |
+
.kv small{display:block;color:var(--muted);font-size:12px}
|
| 65 |
+
.kv b{font-variant-numeric:tabular-nums;font-weight:600}
|
| 66 |
+
details{margin-top:12px} summary{cursor:pointer;color:var(--muted);font-size:14px;list-style:none}
|
| 67 |
+
summary::before{content:"▸ ";} details[open] summary::before{content:"▾ ";}
|
| 68 |
+
.stages{display:flex;gap:10px;overflow-x:auto;padding:10px 0 4px;scroll-snap-type:x mandatory}
|
| 69 |
+
.stage{flex:0 0 170px;scroll-snap-align:start}
|
| 70 |
+
.stage img{width:170px;height:120px;object-fit:cover;border-radius:10px;border:1px solid var(--line);background:var(--soft)}
|
| 71 |
+
.stage b{display:block;font-size:13px;margin-top:4px} .stage span{font-size:12px;color:var(--muted)}
|
| 72 |
+
.notice{border-radius:12px;padding:10px 12px;font-size:14px;margin-bottom:12px}
|
| 73 |
+
.notice.warn{background:color-mix(in srgb,var(--warn) 12%,transparent);color:var(--warn)}
|
| 74 |
+
.notice.bad{background:color-mix(in srgb,var(--bad) 10%,transparent);color:var(--bad)}
|
| 75 |
+
.typing{display:flex;align-items:center;gap:10px;color:var(--muted);font-size:14px}
|
| 76 |
+
.typing i{width:7px;height:7px;border-radius:50%;background:var(--muted);display:inline-block;animation:b 1s infinite}
|
| 77 |
+
.typing i:nth-child(2){animation-delay:.15s}.typing i:nth-child(3){animation-delay:.3s}
|
| 78 |
+
@keyframes b{0%,80%,100%{opacity:.25}40%{opacity:1}}
|
| 79 |
+
.composer{position:fixed;left:0;right:0;bottom:0;padding:12px 16px calc(14px + env(safe-area-inset-bottom));
|
| 80 |
+
background:linear-gradient(to top,var(--bg) 70%,transparent)}
|
| 81 |
+
.box{max-width:780px;margin:0 auto;background:var(--panel);border:1px solid var(--line);border-radius:22px;
|
| 82 |
+
box-shadow:0 4px 24px rgba(0,0,0,.06);padding:10px 10px 10px 16px;display:flex;align-items:center;gap:10px}
|
| 83 |
+
.box.drag{border-color:var(--accent);background:var(--accent-soft)}
|
| 84 |
+
.box .hint{flex:1;color:var(--muted);font-size:15px;cursor:pointer;min-width:0}
|
| 85 |
+
.box .hint b{color:var(--text);font-weight:500}
|
| 86 |
+
.send{width:38px;height:38px;border-radius:50%;border:0;background:var(--accent);color:#fff;display:grid;place-items:center;flex:0 0 38px}
|
| 87 |
+
.send:disabled{opacity:.4;cursor:default}
|
| 88 |
+
.foot{max-width:780px;margin:6px auto 0;text-align:center;color:var(--muted);font-size:12px}
|
| 89 |
+
table{width:100%;border-collapse:collapse;font-size:13.5px}
|
| 90 |
+
th,td{padding:7px 8px;border-bottom:1px solid var(--line);text-align:left;font-variant-numeric:tabular-nums}
|
| 91 |
+
th{color:var(--muted);font-weight:600;font-size:12.5px}
|
| 92 |
+
.tablewrap{overflow-x:auto}
|
| 93 |
+
.overlay{position:fixed;inset:0;background:rgba(0,0,0,.35);display:none;z-index:20;align-items:flex-end;justify-content:center}
|
| 94 |
+
.overlay.open{display:flex}
|
| 95 |
+
.sheet{background:var(--panel);width:100%;max-width:820px;max-height:86vh;overflow:auto;border-radius:20px 20px 0 0;padding:18px 18px 28px}
|
| 96 |
+
@media(min-width:700px){.overlay{align-items:center}.sheet{border-radius:20px}}
|
| 97 |
+
.sheet h2{font-family:ui-serif,Georgia,serif;font-weight:500;margin:0 0 4px}
|
| 98 |
+
.close{float:right;border:0;background:var(--soft);border-radius:999px;padding:4px 12px}
|
| 99 |
+
@media(max-width:520px){header .label{display:none} .title{font-size:19px}}
|
| 100 |
+
/* ---- in-browser loader ---- */
|
| 101 |
+
.loader{max-width:420px;margin:22px auto 0;text-align:left;background:var(--panel);border:1px solid var(--line);border-radius:14px;padding:12px 14px;font-size:13.5px;color:var(--muted)}
|
| 102 |
+
.loader .bar{height:6px;border-radius:99px;background:var(--soft);overflow:hidden;margin-top:8px}
|
| 103 |
+
.loader .bar i{display:block;height:100%;width:0;background:var(--accent);transition:width .2s}
|
| 104 |
+
.loader.done{display:none}
|
| 105 |
+
.privacy{color:var(--muted);font-size:12.5px;margin-top:14px}
|
vendor/opencv.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
vendor/ort-wasm-simd-threaded.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var ortWasmThreaded = (() => {
|
| 2 |
+
var _scriptName = import.meta.url;
|
| 3 |
+
|
| 4 |
+
return (
|
| 5 |
+
async function(moduleArg = {}) {
|
| 6 |
+
var moduleRtn;
|
| 7 |
+
|
| 8 |
+
var f=moduleArg,aa,ba,ca=new Promise((a,b)=>{aa=a;ba=b}),da="object"==typeof window,k="undefined"!=typeof WorkerGlobalScope,l="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node&&"renderer"!=process.type,m=k&&self.name?.startsWith("em-pthread");if(l){const {createRequire:a}=await import("module");var require=a(import.meta.url),n=require("worker_threads");global.Worker=n.Worker;m=(k=!n.jb)&&"em-pthread"==n.workerData}
|
| 9 |
+
f.mountExternalData=(a,b)=>{a.startsWith("./")&&(a=a.substring(2));(f.Sa||(f.Sa=new Map)).set(a,b)};f.unmountExternalData=()=>{delete f.Sa};var SharedArrayBuffer=globalThis.SharedArrayBuffer??(new WebAssembly.Memory({initial:0,maximum:0,lb:!0})).buffer.constructor,ea=Object.assign({},f),fa="./this.program",q=(a,b)=>{throw b;},r="",ha,t;
|
| 10 |
+
if(l){var fs=require("fs"),ia=require("path");import.meta.url.startsWith("data:")||(r=ia.dirname(require("url").fileURLToPath(import.meta.url))+"/");t=a=>{a=u(a)?new URL(a):a;return fs.readFileSync(a)};ha=async a=>{a=u(a)?new URL(a):a;return fs.readFileSync(a,void 0)};!f.thisProgram&&1<process.argv.length&&(fa=process.argv[1].replace(/\\/g,"/"));process.argv.slice(2);q=(a,b)=>{process.exitCode=a;throw b;}}else if(da||k)k?r=self.location.href:"undefined"!=typeof document&&document.currentScript&&
|
| 11 |
+
(r=document.currentScript.src),_scriptName&&(r=_scriptName),r.startsWith("blob:")?r="":r=r.slice(0,r.replace(/[?#].*/,"").lastIndexOf("/")+1),l||(k&&(t=a=>{var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)}),ha=async a=>{if(u(a))return new Promise((c,d)=>{var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";e.onload=()=>{200==e.status||0==e.status&&e.response?c(e.response):d(e.status)};e.onerror=d;e.send(null)});
|
| 12 |
+
var b=await fetch(a,{credentials:"same-origin"});if(b.ok)return b.arrayBuffer();throw Error(b.status+" : "+b.url);});var ja=console.log.bind(console),ka=console.error.bind(console);l&&(ja=(...a)=>fs.writeSync(1,a.join(" ")+"\n"),ka=(...a)=>fs.writeSync(2,a.join(" ")+"\n"));var la=ja,w=ka;Object.assign(f,ea);ea=null;var x=f.wasmBinary,y,ma,z=!1,A,B,na,oa,pa,qa,ra,C,sa,u=a=>a.startsWith("file://");function D(){y.buffer!=B.buffer&&E();return B}function F(){y.buffer!=B.buffer&&E();return na}
|
| 13 |
+
function ta(){y.buffer!=B.buffer&&E();return oa}function G(){y.buffer!=B.buffer&&E();return pa}function H(){y.buffer!=B.buffer&&E();return qa}function va(){y.buffer!=B.buffer&&E();return ra}function I(){y.buffer!=B.buffer&&E();return sa}
|
| 14 |
+
if(m){var wa;if(l){var xa=n.parentPort;xa.on("message",b=>onmessage({data:b}));Object.assign(globalThis,{self:global,postMessage:b=>xa.postMessage(b)})}var ya=!1;w=function(...b){b=b.join(" ");l?fs.writeSync(2,b+"\n"):console.error(b)};self.alert=function(...b){postMessage({Ra:"alert",text:b.join(" "),eb:J()})};self.onunhandledrejection=b=>{throw b.reason||b;};function a(b){try{var c=b.data,d=c.Ra;if("load"===d){let e=[];self.onmessage=g=>e.push(g);self.startWorker=()=>{postMessage({Ra:"loaded"});
|
| 15 |
+
for(let g of e)a(g);self.onmessage=a};for(const g of c.Za)if(!f[g]||f[g].proxy)f[g]=(...h)=>{postMessage({Ra:"callHandler",Ya:g,args:h})},"print"==g&&(la=f[g]),"printErr"==g&&(w=f[g]);y=c.gb;E();wa(c.hb)}else if("run"===d){za(c.Qa);Aa(c.Qa,0,0,1,0,0);Ba();Ca(c.Qa);ya||=!0;try{Da(c.bb,c.Va)}catch(e){if("unwind"!=e)throw e;}}else"setimmediate"!==c.target&&("checkMailbox"===d?ya&&K():d&&(w(`worker: received unknown command ${d}`),w(c)))}catch(e){throw Ea(),e;}}self.onmessage=a}
|
| 16 |
+
function E(){var a=y.buffer;f.HEAP8=B=new Int8Array(a);f.HEAP16=oa=new Int16Array(a);f.HEAPU8=na=new Uint8Array(a);f.HEAPU16=new Uint16Array(a);f.HEAP32=pa=new Int32Array(a);f.HEAPU32=qa=new Uint32Array(a);f.HEAPF32=ra=new Float32Array(a);f.HEAPF64=sa=new Float64Array(a);f.HEAP64=C=new BigInt64Array(a);f.HEAPU64=new BigUint64Array(a)}m||(y=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),E());function Fa(){m?startWorker(f):L.$()}var M=0,N=null;
|
| 17 |
+
function Ga(){M--;if(0==M&&N){var a=N;N=null;a()}}function O(a){a="Aborted("+a+")";w(a);z=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");ba(a);throw a;}var Ha;async function Ia(a){if(!x)try{var b=await ha(a);return new Uint8Array(b)}catch{}if(a==Ha&&x)a=new Uint8Array(x);else if(t)a=t(a);else throw"both async and sync fetching of the wasm failed";return a}
|
| 18 |
+
async function Ja(a,b){try{var c=await Ia(a);return await WebAssembly.instantiate(c,b)}catch(d){w(`failed to asynchronously prepare wasm: ${d}`),O(d)}}async function Ka(a){var b=Ha;if(!x&&"function"==typeof WebAssembly.instantiateStreaming&&!u(b)&&!l)try{var c=fetch(b,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(c,a)}catch(d){w(`wasm streaming compile failed: ${d}`),w("falling back to ArrayBuffer instantiation")}return Ja(b,a)}
|
| 19 |
+
function La(){Ma={j:Na,b:Oa,E:Pa,f:Qa,U:Ra,A:Sa,C:Ta,V:Ua,S:Va,L:Wa,R:Xa,n:Ya,B:Za,y:$a,T:ab,z:bb,_:cb,O:db,w:eb,F:fb,t:gb,i:hb,N:Ca,X:ib,I:jb,J:kb,K:lb,G:mb,H:nb,u:ob,q:pb,Z:qb,o:rb,k:sb,Y:tb,d:ub,W:vb,x:wb,c:xb,e:yb,h:zb,v:Ab,s:Bb,r:Cb,P:Db,Q:Eb,D:Fb,g:Gb,m:Hb,M:Ib,l:Jb,a:y,p:Kb};return{a:Ma}}
|
| 20 |
+
var Mb={802156:(a,b,c,d,e)=>{if("undefined"==typeof f||!f.Sa)return 1;a=Lb(Number(a>>>0));a.startsWith("./")&&(a=a.substring(2));a=f.Sa.get(a);if(!a)return 2;b=Number(b>>>0);c=Number(c>>>0);d=Number(d>>>0);if(b+c>a.byteLength)return 3;try{const g=a.subarray(b,b+c);switch(e){case 0:F().set(g,d>>>0);break;case 1:f.ib?f.ib(d,g):f.kb(d,g);break;default:return 4}return 0}catch{return 4}},802980:()=>"undefined"!==typeof wasmOffsetConverter};function Na(){return"undefined"!==typeof wasmOffsetConverter}
|
| 21 |
+
class Nb{name="ExitStatus";constructor(a){this.message=`Program terminated with exit(${a})`;this.status=a}}
|
| 22 |
+
var Ob=a=>{a.terminate();a.onmessage=()=>{}},Pb=[],Sb=a=>{0==Q.length&&(Qb(),Rb(Q[0]));var b=Q.pop();if(!b)return 6;R.push(b);S[a.Qa]=b;b.Qa=a.Qa;var c={Ra:"run",bb:a.ab,Va:a.Va,Qa:a.Qa};l&&b.unref();b.postMessage(c,a.Xa);return 0},T=0,V=(a,b,...c)=>{for(var d=2*c.length,e=Tb(),g=Ub(8*d),h=g>>>3,p=0;p<c.length;p++){var v=c[p];"bigint"==typeof v?(C[h+2*p]=1n,C[h+2*p+1]=v):(C[h+2*p]=0n,I()[h+2*p+1>>>0]=v)}a=Vb(a,0,d,g,b);U(e);return a};
|
| 23 |
+
function Kb(a){if(m)return V(0,1,a);A=a;if(!(0<T)){for(var b of R)Ob(b);for(b of Q)Ob(b);Q=[];R=[];S={};z=!0}q(a,new Nb(a))}function Wb(a){if(m)return V(1,0,a);Fb(a)}var Fb=a=>{A=a;if(m)throw Wb(a),"unwind";Kb(a)},Q=[],R=[],Xb=[],S={};function Yb(){for(var a=f.numThreads-1;a--;)Qb();Pb.unshift(()=>{M++;Zb(()=>Ga())})}var ac=a=>{var b=a.Qa;delete S[b];Q.push(a);R.splice(R.indexOf(a),1);a.Qa=0;$b(b)};function Ba(){Xb.forEach(a=>a())}
|
| 24 |
+
var Rb=a=>new Promise(b=>{a.onmessage=g=>{g=g.data;var h=g.Ra;if(g.Ta&&g.Ta!=J()){var p=S[g.Ta];p?p.postMessage(g,g.Xa):w(`Internal error! Worker sent a message "${h}" to target pthread ${g.Ta}, but that thread no longer exists!`)}else if("checkMailbox"===h)K();else if("spawnThread"===h)Sb(g);else if("cleanupThread"===h)ac(S[g.cb]);else if("loaded"===h)a.loaded=!0,l&&!a.Qa&&a.unref(),b(a);else if("alert"===h)alert(`Thread ${g.eb}: ${g.text}`);else if("setimmediate"===g.target)a.postMessage(g);else if("callHandler"===
|
| 25 |
+
h)f[g.Ya](...g.args);else h&&w(`worker sent an unknown command ${h}`)};a.onerror=g=>{w(`${"worker sent an error!"} ${g.filename}:${g.lineno}: ${g.message}`);throw g;};l&&(a.on("message",g=>a.onmessage({data:g})),a.on("error",g=>a.onerror(g)));var c=[],d=[],e;for(e of d)f.propertyIsEnumerable(e)&&c.push(e);a.postMessage({Ra:"load",Za:c,gb:y,hb:ma})});function Zb(a){m?a():Promise.all(Q.map(Rb)).then(a)}
|
| 26 |
+
function Qb(){var a=new Worker(new URL(import.meta.url),{type:"module",workerData:"em-pthread",name:"em-pthread"});Q.push(a)}var za=a=>{E();var b=H()[a+52>>>2>>>0];a=H()[a+56>>>2>>>0];bc(b,b-a);U(b)},W=[],cc,Da=(a,b)=>{T=0;var c=W[a];c||(a>=W.length&&(W.length=a+1),W[a]=c=cc.get(a));a=c(b);0<T?A=a:dc(a)};class ec{constructor(a){this.Ua=a-24}}var fc=0,gc=0;
|
| 27 |
+
function Oa(a,b,c){a>>>=0;var d=new ec(a);b>>>=0;c>>>=0;H()[d.Ua+16>>>2>>>0]=0;H()[d.Ua+4>>>2>>>0]=b;H()[d.Ua+8>>>2>>>0]=c;fc=a;gc++;throw fc;}function hc(a,b,c,d){return m?V(2,1,a,b,c,d):Pa(a,b,c,d)}function Pa(a,b,c,d){a>>>=0;b>>>=0;c>>>=0;d>>>=0;if("undefined"==typeof SharedArrayBuffer)return 6;var e=[];if(m&&0===e.length)return hc(a,b,c,d);a={ab:c,Qa:a,Va:d,Xa:e};return m?(a.Ra="spawnThread",postMessage(a,e),0):Sb(a)}
|
| 28 |
+
var ic="undefined"!=typeof TextDecoder?new TextDecoder:void 0,jc=(a,b=0,c=NaN)=>{b>>>=0;var d=b+c;for(c=b;a[c]&&!(c>=d);)++c;if(16<c-b&&a.buffer&&ic)return ic.decode(a.buffer instanceof ArrayBuffer?a.subarray(b,c):a.slice(b,c));for(d="";b<c;){var e=a[b++];if(e&128){var g=a[b++]&63;if(192==(e&224))d+=String.fromCharCode((e&31)<<6|g);else{var h=a[b++]&63;e=224==(e&240)?(e&15)<<12|g<<6|h:(e&7)<<18|g<<12|h<<6|a[b++]&63;65536>e?d+=String.fromCharCode(e):(e-=65536,d+=String.fromCharCode(55296|e>>10,56320|
|
| 29 |
+
e&1023))}}else d+=String.fromCharCode(e)}return d},Lb=(a,b)=>(a>>>=0)?jc(F(),a,b):"";function Qa(a,b,c){return m?V(3,1,a,b,c):0}function Ra(a,b){if(m)return V(4,1,a,b)}
|
| 30 |
+
var X=(a,b,c)=>{var d=F();b>>>=0;if(0<c){var e=b;c=b+c-1;for(var g=0;g<a.length;++g){var h=a.charCodeAt(g);if(55296<=h&&57343>=h){var p=a.charCodeAt(++g);h=65536+((h&1023)<<10)|p&1023}if(127>=h){if(b>=c)break;d[b++>>>0]=h}else{if(2047>=h){if(b+1>=c)break;d[b++>>>0]=192|h>>6}else{if(65535>=h){if(b+2>=c)break;d[b++>>>0]=224|h>>12}else{if(b+3>=c)break;d[b++>>>0]=240|h>>18;d[b++>>>0]=128|h>>12&63}d[b++>>>0]=128|h>>6&63}d[b++>>>0]=128|h&63}}d[b>>>0]=0;a=b-e}else a=0;return a};
|
| 31 |
+
function Sa(a,b){if(m)return V(5,1,a,b)}function Ta(a,b,c){if(m)return V(6,1,a,b,c)}function Ua(a,b,c){return m?V(7,1,a,b,c):0}function Va(a,b){if(m)return V(8,1,a,b)}function Wa(a,b,c){if(m)return V(9,1,a,b,c)}function Xa(a,b,c,d){if(m)return V(10,1,a,b,c,d)}function Ya(a,b,c,d){if(m)return V(11,1,a,b,c,d)}function Za(a,b,c,d){if(m)return V(12,1,a,b,c,d)}function $a(a){if(m)return V(13,1,a)}function ab(a,b){if(m)return V(14,1,a,b)}function bb(a,b,c){if(m)return V(15,1,a,b,c)}var cb=()=>O("");
|
| 32 |
+
function db(a){Aa(a>>>0,!k,1,!da,131072,!1);Ba()}var kc=a=>{if(!z)try{if(a(),!(0<T))try{m?dc(A):Fb(A)}catch(b){b instanceof Nb||"unwind"==b||q(1,b)}}catch(b){b instanceof Nb||"unwind"==b||q(1,b)}};function Ca(a){a>>>=0;"function"===typeof Atomics.fb&&(Atomics.fb(G(),a>>>2,a).value.then(K),a+=128,Atomics.store(G(),a>>>2,1))}var K=()=>{var a=J();a&&(Ca(a),kc(lc))};function eb(a,b){a>>>=0;a==b>>>0?setTimeout(K):m?postMessage({Ta:a,Ra:"checkMailbox"}):(a=S[a])&&a.postMessage({Ra:"checkMailbox"})}
|
| 33 |
+
var mc=[];function fb(a,b,c,d,e){b>>>=0;d/=2;mc.length=d;c=e>>>0>>>3;for(e=0;e<d;e++)mc[e]=C[c+2*e]?C[c+2*e+1]:I()[c+2*e+1>>>0];return(b?Mb[b]:nc[a])(...mc)}var gb=()=>{T=0};function hb(a){a>>>=0;m?postMessage({Ra:"cleanupThread",cb:a}):ac(S[a])}function ib(a){l&&S[a>>>0].ref()}
|
| 34 |
+
function jb(a,b){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);b>>>=0;a=new Date(1E3*a);G()[b>>>2>>>0]=a.getUTCSeconds();G()[b+4>>>2>>>0]=a.getUTCMinutes();G()[b+8>>>2>>>0]=a.getUTCHours();G()[b+12>>>2>>>0]=a.getUTCDate();G()[b+16>>>2>>>0]=a.getUTCMonth();G()[b+20>>>2>>>0]=a.getUTCFullYear()-1900;G()[b+24>>>2>>>0]=a.getUTCDay();a=(a.getTime()-Date.UTC(a.getUTCFullYear(),0,1,0,0,0,0))/864E5|0;G()[b+28>>>2>>>0]=a}
|
| 35 |
+
var oc=a=>0===a%4&&(0!==a%100||0===a%400),pc=[0,31,60,91,121,152,182,213,244,274,305,335],qc=[0,31,59,90,120,151,181,212,243,273,304,334];
|
| 36 |
+
function kb(a,b){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);b>>>=0;a=new Date(1E3*a);G()[b>>>2>>>0]=a.getSeconds();G()[b+4>>>2>>>0]=a.getMinutes();G()[b+8>>>2>>>0]=a.getHours();G()[b+12>>>2>>>0]=a.getDate();G()[b+16>>>2>>>0]=a.getMonth();G()[b+20>>>2>>>0]=a.getFullYear()-1900;G()[b+24>>>2>>>0]=a.getDay();var c=(oc(a.getFullYear())?pc:qc)[a.getMonth()]+a.getDate()-1|0;G()[b+28>>>2>>>0]=c;G()[b+36>>>2>>>0]=-(60*a.getTimezoneOffset());c=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();
|
| 37 |
+
var d=(new Date(a.getFullYear(),0,1)).getTimezoneOffset();a=(c!=d&&a.getTimezoneOffset()==Math.min(d,c))|0;G()[b+32>>>2>>>0]=a}
|
| 38 |
+
function lb(a){a>>>=0;var b=new Date(G()[a+20>>>2>>>0]+1900,G()[a+16>>>2>>>0],G()[a+12>>>2>>>0],G()[a+8>>>2>>>0],G()[a+4>>>2>>>0],G()[a>>>2>>>0],0),c=G()[a+32>>>2>>>0],d=b.getTimezoneOffset(),e=(new Date(b.getFullYear(),6,1)).getTimezoneOffset(),g=(new Date(b.getFullYear(),0,1)).getTimezoneOffset(),h=Math.min(g,e);0>c?G()[a+32>>>2>>>0]=Number(e!=g&&h==d):0<c!=(h==d)&&(e=Math.max(g,e),b.setTime(b.getTime()+6E4*((0<c?h:e)-d)));G()[a+24>>>2>>>0]=b.getDay();c=(oc(b.getFullYear())?pc:qc)[b.getMonth()]+
|
| 39 |
+
b.getDate()-1|0;G()[a+28>>>2>>>0]=c;G()[a>>>2>>>0]=b.getSeconds();G()[a+4>>>2>>>0]=b.getMinutes();G()[a+8>>>2>>>0]=b.getHours();G()[a+12>>>2>>>0]=b.getDate();G()[a+16>>>2>>>0]=b.getMonth();G()[a+20>>>2>>>0]=b.getYear();a=b.getTime();return BigInt(isNaN(a)?-1:a/1E3)}function mb(a,b,c,d,e,g,h){return m?V(16,1,a,b,c,d,e,g,h):-52}function nb(a,b,c,d,e,g){if(m)return V(17,1,a,b,c,d,e,g)}var Y={},xb=()=>performance.timeOrigin+performance.now();
|
| 40 |
+
function ob(a,b){if(m)return V(18,1,a,b);Y[a]&&(clearTimeout(Y[a].id),delete Y[a]);if(!b)return 0;var c=setTimeout(()=>{delete Y[a];kc(()=>rc(a,performance.timeOrigin+performance.now()))},b);Y[a]={id:c,mb:b};return 0}
|
| 41 |
+
function pb(a,b,c,d){a>>>=0;b>>>=0;c>>>=0;d>>>=0;var e=(new Date).getFullYear(),g=(new Date(e,0,1)).getTimezoneOffset();e=(new Date(e,6,1)).getTimezoneOffset();var h=Math.max(g,e);H()[a>>>2>>>0]=60*h;G()[b>>>2>>>0]=Number(g!=e);b=p=>{var v=Math.abs(p);return`UTC${0<=p?"-":"+"}${String(Math.floor(v/60)).padStart(2,"0")}${String(v%60).padStart(2,"0")}`};a=b(g);b=b(e);e<g?(X(a,c,17),X(b,d,17)):(X(a,d,17),X(b,c,17))}var tb=()=>Date.now(),sc=1;
|
| 42 |
+
function qb(a,b,c){if(!(0<=a&&3>=a))return 28;if(0===a)a=Date.now();else if(sc)a=performance.timeOrigin+performance.now();else return 52;C[c>>>0>>>3]=BigInt(Math.round(1E6*a));return 0}var tc=[];function rb(a,b,c){a>>>=0;b>>>=0;c>>>=0;tc.length=0;for(var d;d=F()[b++>>>0];){var e=105!=d;e&=112!=d;c+=e&&c%8?4:0;tc.push(112==d?H()[c>>>2>>>0]:106==d?C[c>>>3]:105==d?G()[c>>>2>>>0]:I()[c>>>3>>>0]);c+=e?8:4}return Mb[a](...tc)}var sb=()=>{};function ub(a,b){return w(Lb(a>>>0,b>>>0))}
|
| 43 |
+
var vb=()=>{T+=1;throw"unwind";};function wb(){return 4294901760}var yb=()=>l?require("os").cpus().length:navigator.hardwareConcurrency;function zb(){O("Cannot use emscripten_pc_get_function without -sUSE_OFFSET_CONVERTER");return 0}
|
| 44 |
+
function Ab(a){a>>>=0;var b=F().length;if(a<=b||4294901760<a)return!1;for(var c=1;4>=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);a:{d=(Math.min(4294901760,65536*Math.ceil(Math.max(a,d)/65536))-y.buffer.byteLength+65535)/65536|0;try{y.grow(d);E();var e=1;break a}catch(g){}e=void 0}if(e)return!0}return!1}var uc=()=>{O("Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER");return 0},Z={},vc=a=>{a.forEach(b=>{var c=uc();c&&(Z[c]=b)})};
|
| 45 |
+
function Bb(){var a=Error().stack.toString().split("\n");"Error"==a[0]&&a.shift();vc(a);Z.Wa=uc();Z.$a=a;return Z.Wa}function Cb(a,b,c){a>>>=0;b>>>=0;if(Z.Wa==a)var d=Z.$a;else d=Error().stack.toString().split("\n"),"Error"==d[0]&&d.shift(),vc(d);for(var e=3;d[e]&&uc()!=a;)++e;for(a=0;a<c&&d[a+e];++a)G()[b+4*a>>>2>>>0]=uc();return a}
|
| 46 |
+
var wc={},yc=()=>{if(!xc){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:fa||"./this.program"},b;for(b in wc)void 0===wc[b]?delete a[b]:a[b]=wc[b];var c=[];for(b in a)c.push(`${b}=${a[b]}`);xc=c}return xc},xc;
|
| 47 |
+
function Db(a,b){if(m)return V(19,1,a,b);a>>>=0;b>>>=0;var c=0;yc().forEach((d,e)=>{var g=b+c;e=H()[a+4*e>>>2>>>0]=g;for(g=0;g<d.length;++g)D()[e++>>>0]=d.charCodeAt(g);D()[e>>>0]=0;c+=d.length+1});return 0}function Eb(a,b){if(m)return V(20,1,a,b);a>>>=0;b>>>=0;var c=yc();H()[a>>>2>>>0]=c.length;var d=0;c.forEach(e=>d+=e.length+1);H()[b>>>2>>>0]=d;return 0}function Gb(a){return m?V(21,1,a):52}function Hb(a,b,c,d){return m?V(22,1,a,b,c,d):52}function Ib(a,b,c,d){return m?V(23,1,a,b,c,d):70}
|
| 48 |
+
var zc=[null,[],[]];function Jb(a,b,c,d){if(m)return V(24,1,a,b,c,d);b>>>=0;c>>>=0;d>>>=0;for(var e=0,g=0;g<c;g++){var h=H()[b>>>2>>>0],p=H()[b+4>>>2>>>0];b+=8;for(var v=0;v<p;v++){var P=F()[h+v>>>0],ua=zc[a];0===P||10===P?((1===a?la:w)(jc(ua)),ua.length=0):ua.push(P)}e+=p}H()[d>>>2>>>0]=e;return 0}m||Yb();var nc=[Kb,Wb,hc,Qa,Ra,Sa,Ta,Ua,Va,Wa,Xa,Ya,Za,$a,ab,bb,mb,nb,ob,Db,Eb,Gb,Hb,Ib,Jb],Ma,L;
|
| 49 |
+
(async function(){function a(d,e){L=d.exports;L=Ac();Xb.push(L.Da);cc=L.Ea;ma=e;Ga();return L}M++;var b=La();if(f.instantiateWasm)return new Promise(d=>{f.instantiateWasm(b,(e,g)=>{a(e,g);d(e.exports)})});if(m)return new Promise(d=>{wa=e=>{var g=new WebAssembly.Instance(e,La());d(a(g,e))}});Ha??=f.locateFile?f.locateFile?f.locateFile("ort-wasm-simd-threaded.wasm",r):r+"ort-wasm-simd-threaded.wasm":(new URL("ort-wasm-simd-threaded.wasm",import.meta.url)).href;try{var c=await Ka(b);return a(c.instance,
|
| 50 |
+
c.module)}catch(d){return ba(d),Promise.reject(d)}})();f._OrtInit=(a,b)=>(f._OrtInit=L.aa)(a,b);f._OrtGetLastError=(a,b)=>(f._OrtGetLastError=L.ba)(a,b);f._OrtCreateSessionOptions=(a,b,c,d,e,g,h,p,v,P)=>(f._OrtCreateSessionOptions=L.ca)(a,b,c,d,e,g,h,p,v,P);f._OrtAppendExecutionProvider=(a,b,c,d,e)=>(f._OrtAppendExecutionProvider=L.da)(a,b,c,d,e);f._OrtAddFreeDimensionOverride=(a,b,c)=>(f._OrtAddFreeDimensionOverride=L.ea)(a,b,c);
|
| 51 |
+
f._OrtAddSessionConfigEntry=(a,b,c)=>(f._OrtAddSessionConfigEntry=L.fa)(a,b,c);f._OrtReleaseSessionOptions=a=>(f._OrtReleaseSessionOptions=L.ga)(a);f._OrtCreateSession=(a,b,c)=>(f._OrtCreateSession=L.ha)(a,b,c);f._OrtReleaseSession=a=>(f._OrtReleaseSession=L.ia)(a);f._OrtGetInputOutputCount=(a,b,c)=>(f._OrtGetInputOutputCount=L.ja)(a,b,c);f._OrtGetInputOutputMetadata=(a,b,c,d)=>(f._OrtGetInputOutputMetadata=L.ka)(a,b,c,d);f._OrtFree=a=>(f._OrtFree=L.la)(a);
|
| 52 |
+
f._OrtCreateTensor=(a,b,c,d,e,g)=>(f._OrtCreateTensor=L.ma)(a,b,c,d,e,g);f._OrtGetTensorData=(a,b,c,d,e)=>(f._OrtGetTensorData=L.na)(a,b,c,d,e);f._OrtReleaseTensor=a=>(f._OrtReleaseTensor=L.oa)(a);f._OrtCreateRunOptions=(a,b,c,d)=>(f._OrtCreateRunOptions=L.pa)(a,b,c,d);f._OrtAddRunConfigEntry=(a,b,c)=>(f._OrtAddRunConfigEntry=L.qa)(a,b,c);f._OrtReleaseRunOptions=a=>(f._OrtReleaseRunOptions=L.ra)(a);f._OrtCreateBinding=a=>(f._OrtCreateBinding=L.sa)(a);
|
| 53 |
+
f._OrtBindInput=(a,b,c)=>(f._OrtBindInput=L.ta)(a,b,c);f._OrtBindOutput=(a,b,c,d)=>(f._OrtBindOutput=L.ua)(a,b,c,d);f._OrtClearBoundOutputs=a=>(f._OrtClearBoundOutputs=L.va)(a);f._OrtReleaseBinding=a=>(f._OrtReleaseBinding=L.wa)(a);f._OrtRunWithBinding=(a,b,c,d,e)=>(f._OrtRunWithBinding=L.xa)(a,b,c,d,e);f._OrtRun=(a,b,c,d,e,g,h,p)=>(f._OrtRun=L.ya)(a,b,c,d,e,g,h,p);f._OrtEndProfiling=a=>(f._OrtEndProfiling=L.za)(a);var J=()=>(J=L.Aa)();f._free=a=>(f._free=L.Ba)(a);f._malloc=a=>(f._malloc=L.Ca)(a);
|
| 54 |
+
var Aa=(a,b,c,d,e,g)=>(Aa=L.Fa)(a,b,c,d,e,g),Ea=()=>(Ea=L.Ga)(),Vb=(a,b,c,d,e)=>(Vb=L.Ha)(a,b,c,d,e),$b=a=>($b=L.Ia)(a),dc=a=>(dc=L.Ja)(a),rc=(a,b)=>(rc=L.Ka)(a,b),lc=()=>(lc=L.La)(),bc=(a,b)=>(bc=L.Ma)(a,b),U=a=>(U=L.Na)(a),Ub=a=>(Ub=L.Oa)(a),Tb=()=>(Tb=L.Pa)();function Ac(){var a=L;a=Object.assign({},a);var b=d=>()=>d()>>>0,c=d=>e=>d(e)>>>0;a.Aa=b(a.Aa);a.Ca=c(a.Ca);a.Oa=c(a.Oa);a.Pa=b(a.Pa);a.__cxa_get_exception_ptr=c(a.__cxa_get_exception_ptr);return a}f.stackSave=()=>Tb();f.stackRestore=a=>U(a);
|
| 55 |
+
f.stackAlloc=a=>Ub(a);f.setValue=function(a,b,c="i8"){c.endsWith("*")&&(c="*");switch(c){case "i1":D()[a>>>0]=b;break;case "i8":D()[a>>>0]=b;break;case "i16":ta()[a>>>1>>>0]=b;break;case "i32":G()[a>>>2>>>0]=b;break;case "i64":C[a>>>3]=BigInt(b);break;case "float":va()[a>>>2>>>0]=b;break;case "double":I()[a>>>3>>>0]=b;break;case "*":H()[a>>>2>>>0]=b;break;default:O(`invalid type for setValue: ${c}`)}};
|
| 56 |
+
f.getValue=function(a,b="i8"){b.endsWith("*")&&(b="*");switch(b){case "i1":return D()[a>>>0];case "i8":return D()[a>>>0];case "i16":return ta()[a>>>1>>>0];case "i32":return G()[a>>>2>>>0];case "i64":return C[a>>>3];case "float":return va()[a>>>2>>>0];case "double":return I()[a>>>3>>>0];case "*":return H()[a>>>2>>>0];default:O(`invalid type for getValue: ${b}`)}};f.UTF8ToString=Lb;f.stringToUTF8=X;
|
| 57 |
+
f.lengthBytesUTF8=a=>{for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);127>=d?b++:2047>=d?b+=2:55296<=d&&57343>=d?(b+=4,++c):b+=3}return b};function Bc(){if(0<M)N=Bc;else if(m)aa(f),Fa();else{for(;0<Pb.length;)Pb.shift()(f);0<M?N=Bc:(f.calledRun=!0,z||(Fa(),aa(f)))}}Bc();f.PTR_SIZE=4;moduleRtn=ca;
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
return moduleRtn;
|
| 61 |
+
}
|
| 62 |
+
);
|
| 63 |
+
})();
|
| 64 |
+
export default ortWasmThreaded;
|
| 65 |
+
var isPthread = globalThis.self?.name?.startsWith('em-pthread');
|
| 66 |
+
var isNode = typeof globalThis.process?.versions?.node == 'string';
|
| 67 |
+
if (isNode) isPthread = (await import('worker_threads')).workerData === 'em-pthread';
|
| 68 |
+
|
| 69 |
+
// When running as a pthread, construct a new instance on startup
|
| 70 |
+
isPthread && ortWasmThreaded();
|
vendor/ort-wasm-simd-threaded.wasm
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:71aef04959c5c1b6de461b6538e2058e306610034a85aad2742d0c7fd4533fe4
|
| 3 |
+
size 11210254
|
vendor/ort.wasm.min.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* ONNX Runtime Web v1.22.0
|
| 3 |
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
| 4 |
+
* Licensed under the MIT License.
|
| 5 |
+
*/
|
| 6 |
+
"use strict";var ort=(()=>{var je=Object.defineProperty;var An=Object.getOwnPropertyDescriptor;var On=Object.getOwnPropertyNames;var In=Object.prototype.hasOwnProperty;var Ve=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var E=(e,t)=>()=>(e&&(t=e(e=0)),t);var be=(e,t)=>{for(var n in t)je(e,n,{get:t[n],enumerable:!0})},Pn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of On(t))!In.call(e,r)&&r!==n&&je(e,r,{get:()=>t[r],enumerable:!(o=An(t,r))||o.enumerable});return e};var Ye=e=>Pn(je({},"__esModule",{value:!0}),e);var ge,J,re,Ln,mt,qe=E(()=>{"use strict";ge=new Map,J=[],re=(e,t,n)=>{if(t&&typeof t.init=="function"&&typeof t.createInferenceSessionHandler=="function"){let o=ge.get(e);if(o===void 0)ge.set(e,{backend:t,priority:n});else{if(o.priority>n)return;if(o.priority===n&&o.backend!==t)throw new Error(`cannot register backend "${e}" using priority ${n}`)}if(n>=0){let r=J.indexOf(e);r!==-1&&J.splice(r,1);for(let i=0;i<J.length;i++)if(ge.get(J[i]).priority<=n){J.splice(i,0,e);return}J.push(e)}return}throw new TypeError("not a valid backend")},Ln=async e=>{let t=ge.get(e);if(!t)return"backend not found.";if(t.initialized)return t.backend;if(t.aborted)return t.error;{let n=!!t.initPromise;try{return n||(t.initPromise=t.backend.init(e)),await t.initPromise,t.initialized=!0,t.backend}catch(o){return n||(t.error=`${o}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},mt=async e=>{let t=e.executionProviders||[],n=t.map(u=>typeof u=="string"?u:u.name),o=n.length===0?J:n,r,i=[],a=new Set;for(let u of o){let f=await Ln(u);typeof f=="string"?i.push({name:u,err:f}):(r||(r=f),r===f&&a.add(u))}if(!r)throw new Error(`no available backend found. ERR: ${i.map(u=>`[${u.name}] ${u.err}`).join(", ")}`);for(let{name:u,err:f}of i)n.includes(u)&&console.warn(`removing requested execution provider "${u}" from session options because it is not available: ${f}`);let s=t.filter(u=>a.has(typeof u=="string"?u:u.name));return[r,new Proxy(e,{get:(u,f)=>f==="executionProviders"?s:Reflect.get(u,f)})]}});var wt=E(()=>{"use strict";qe()});var ht,yt=E(()=>{"use strict";ht="1.22.0"});var bt,C,Je=E(()=>{"use strict";yt();bt="warning",C={wasm:{},webgl:{},webgpu:{},versions:{common:ht},set logLevel(e){if(e!==void 0){if(typeof e!="string"||["verbose","info","warning","error","fatal"].indexOf(e)===-1)throw new Error(`Unsupported logging level: ${e}`);bt=e}},get logLevel(){return bt}};Object.defineProperty(C,"logLevel",{enumerable:!0})});var O,gt=E(()=>{"use strict";Je();O=C});var Et,Tt,St=E(()=>{"use strict";Et=(e,t)=>{let n=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);n.width=e.dims[3],n.height=e.dims[2];let o=n.getContext("2d");if(o!=null){let r,i;t?.tensorLayout!==void 0&&t.tensorLayout==="NHWC"?(r=e.dims[2],i=e.dims[3]):(r=e.dims[3],i=e.dims[2]);let a=t?.format!==void 0?t.format:"RGB",s=t?.norm,u,f;s===void 0||s.mean===void 0?u=[255,255,255,255]:typeof s.mean=="number"?u=[s.mean,s.mean,s.mean,s.mean]:(u=[s.mean[0],s.mean[1],s.mean[2],0],s.mean[3]!==void 0&&(u[3]=s.mean[3])),s===void 0||s.bias===void 0?f=[0,0,0,0]:typeof s.bias=="number"?f=[s.bias,s.bias,s.bias,s.bias]:(f=[s.bias[0],s.bias[1],s.bias[2],0],s.bias[3]!==void 0&&(f[3]=s.bias[3]));let c=i*r,l=0,d=c,p=c*2,w=-1;a==="RGBA"?(l=0,d=c,p=c*2,w=c*3):a==="RGB"?(l=0,d=c,p=c*2):a==="RBG"&&(l=0,p=c,d=c*2);for(let b=0;b<i;b++)for(let I=0;I<r;I++){let m=(e.data[l++]-f[0])*u[0],h=(e.data[d++]-f[1])*u[1],P=(e.data[p++]-f[2])*u[2],g=w===-1?255:(e.data[w++]-f[3])*u[3];o.fillStyle="rgba("+m+","+h+","+P+","+g+")",o.fillRect(I,b,1,1)}if("toDataURL"in n)return n.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},Tt=(e,t)=>{let n=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),o;if(n!=null){let r,i,a;t?.tensorLayout!==void 0&&t.tensorLayout==="NHWC"?(r=e.dims[2],i=e.dims[1],a=e.dims[3]):(r=e.dims[3],i=e.dims[2],a=e.dims[1]);let s=t!==void 0&&t.format!==void 0?t.format:"RGB",u=t?.norm,f,c;u===void 0||u.mean===void 0?f=[255,255,255,255]:typeof u.mean=="number"?f=[u.mean,u.mean,u.mean,u.mean]:(f=[u.mean[0],u.mean[1],u.mean[2],255],u.mean[3]!==void 0&&(f[3]=u.mean[3])),u===void 0||u.bias===void 0?c=[0,0,0,0]:typeof u.bias=="number"?c=[u.bias,u.bias,u.bias,u.bias]:(c=[u.bias[0],u.bias[1],u.bias[2],0],u.bias[3]!==void 0&&(c[3]=u.bias[3]));let l=i*r;if(t!==void 0&&(t.format!==void 0&&a===4&&t.format!=="RGBA"||a===3&&t.format!=="RGB"&&t.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let d=4,p=0,w=1,b=2,I=3,m=0,h=l,P=l*2,g=-1;s==="RGBA"?(m=0,h=l,P=l*2,g=l*3):s==="RGB"?(m=0,h=l,P=l*2):s==="RBG"&&(m=0,P=l,h=l*2),o=n.createImageData(r,i);for(let S=0;S<i*r;p+=d,w+=d,b+=d,I+=d,S++)o.data[p]=(e.data[m++]-c[0])*f[0],o.data[w]=(e.data[h++]-c[1])*f[1],o.data[b]=(e.data[P++]-c[2])*f[2],o.data[I]=g===-1?255:(e.data[g++]-c[3])*f[3]}else throw new Error("Can not access image data");return o}});var Ze,At,Ot,It,Pt,Lt,xt=E(()=>{"use strict";Ee();Ze=(e,t)=>{if(e===void 0)throw new Error("Image buffer must be defined");if(t.height===void 0||t.width===void 0)throw new Error("Image height and width must be defined");if(t.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:n,width:o}=t,r=t.norm??{mean:255,bias:0},i,a;typeof r.mean=="number"?i=[r.mean,r.mean,r.mean,r.mean]:i=[r.mean[0],r.mean[1],r.mean[2],r.mean[3]??255],typeof r.bias=="number"?a=[r.bias,r.bias,r.bias,r.bias]:a=[r.bias[0],r.bias[1],r.bias[2],r.bias[3]??0];let s=t.format!==void 0?t.format:"RGBA",u=t.tensorFormat!==void 0&&t.tensorFormat!==void 0?t.tensorFormat:"RGB",f=n*o,c=u==="RGBA"?new Float32Array(f*4):new Float32Array(f*3),l=4,d=0,p=1,w=2,b=3,I=0,m=f,h=f*2,P=-1;s==="RGB"&&(l=3,d=0,p=1,w=2,b=-1),u==="RGBA"?P=f*3:u==="RBG"?(I=0,h=f,m=f*2):u==="BGR"&&(h=0,m=f,I=f*2);for(let S=0;S<f;S++,d+=l,w+=l,p+=l,b+=l)c[I++]=(e[d]+a[0])/i[0],c[m++]=(e[p]+a[1])/i[1],c[h++]=(e[w]+a[2])/i[2],P!==-1&&b!==-1&&(c[P++]=(e[b]+a[3])/i[3]);return u==="RGBA"?new U("float32",c,[1,4,n,o]):new U("float32",c,[1,3,n,o])},At=async(e,t)=>{let n=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,o=typeof ImageData<"u"&&e instanceof ImageData,r=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,i=typeof e=="string",a,s=t??{},u=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},f=c=>typeof HTMLCanvasElement<"u"&&c instanceof HTMLCanvasElement||c instanceof OffscreenCanvas?c.getContext("2d"):null;if(n){let c=u();c.width=e.width,c.height=e.height;let l=f(c);if(l!=null){let d=e.height,p=e.width;if(t!==void 0&&t.resizedHeight!==void 0&&t.resizedWidth!==void 0&&(d=t.resizedHeight,p=t.resizedWidth),t!==void 0){if(s=t,t.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");s.tensorFormat="RGBA",s.height=d,s.width=p}else s.tensorFormat="RGBA",s.height=d,s.width=p;l.drawImage(e,0,0),a=l.getImageData(0,0,p,d).data}else throw new Error("Can not access image data")}else if(o){let c,l;if(t!==void 0&&t.resizedWidth!==void 0&&t.resizedHeight!==void 0?(c=t.resizedHeight,l=t.resizedWidth):(c=e.height,l=e.width),t!==void 0&&(s=t),s.format="RGBA",s.height=c,s.width=l,t!==void 0){let d=u();d.width=l,d.height=c;let p=f(d);if(p!=null)p.putImageData(e,0,0),a=p.getImageData(0,0,l,c).data;else throw new Error("Can not access image data")}else a=e.data}else if(r){if(t===void 0)throw new Error("Please provide image config with format for Imagebitmap");let c=u();c.width=e.width,c.height=e.height;let l=f(c);if(l!=null){let d=e.height,p=e.width;return l.drawImage(e,0,0,p,d),a=l.getImageData(0,0,p,d).data,s.height=d,s.width=p,Ze(a,s)}else throw new Error("Can not access image data")}else{if(i)return new Promise((c,l)=>{let d=u(),p=f(d);if(!e||!p)return l();let w=new Image;w.crossOrigin="Anonymous",w.src=e,w.onload=()=>{d.width=w.width,d.height=w.height,p.drawImage(w,0,0,d.width,d.height);let b=p.getImageData(0,0,d.width,d.height);s.height=d.height,s.width=d.width,c(Ze(b.data,s))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(a!==void 0)return Ze(a,s);throw new Error("Input data provided is not supported - aborted tensor creation")},Ot=(e,t)=>{let{width:n,height:o,download:r,dispose:i}=t,a=[1,o,n,4];return new U({location:"texture",type:"float32",texture:e,dims:a,download:r,dispose:i})},It=(e,t)=>{let{dataType:n,dims:o,download:r,dispose:i}=t;return new U({location:"gpu-buffer",type:n??"float32",gpuBuffer:e,dims:o,download:r,dispose:i})},Pt=(e,t)=>{let{dataType:n,dims:o,download:r,dispose:i}=t;return new U({location:"ml-tensor",type:n??"float32",mlTensor:e,dims:o,download:r,dispose:i})},Lt=(e,t,n)=>new U({location:"cpu-pinned",type:e,data:t,dims:n??[t.length]})});var Z,de,vt,Bt,Ut=E(()=>{"use strict";Z=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),de=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),vt=!1,Bt=()=>{if(!vt){vt=!0;let e=typeof BigInt64Array<"u"&&BigInt64Array.from,t=typeof BigUint64Array<"u"&&BigUint64Array.from,n=globalThis.Float16Array,o=typeof n<"u"&&n.from;e&&(Z.set("int64",BigInt64Array),de.set(BigInt64Array,"int64")),t&&(Z.set("uint64",BigUint64Array),de.set(BigUint64Array,"uint64")),o?(Z.set("float16",n),de.set(n,"float16")):Z.set("float16",Uint16Array)}}});var _t,Mt,Dt=E(()=>{"use strict";Ee();_t=e=>{let t=1;for(let n=0;n<e.length;n++){let o=e[n];if(typeof o!="number"||!Number.isSafeInteger(o))throw new TypeError(`dims[${n}] must be an integer, got: ${o}`);if(o<0)throw new RangeError(`dims[${n}] must be a non-negative integer, got: ${o}`);t*=o}return t},Mt=(e,t)=>{switch(e.location){case"cpu":return new U(e.type,e.data,t);case"cpu-pinned":return new U({location:"cpu-pinned",data:e.data,type:e.type,dims:t});case"texture":return new U({location:"texture",texture:e.texture,type:e.type,dims:t});case"gpu-buffer":return new U({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:t});case"ml-tensor":return new U({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:t});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}}});var U,Ee=E(()=>{"use strict";St();xt();Ut();Dt();U=class{constructor(t,n,o){Bt();let r,i;if(typeof t=="object"&&"location"in t)switch(this.dataLocation=t.location,r=t.type,i=t.dims,t.location){case"cpu-pinned":{let s=Z.get(r);if(!s)throw new TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(t.data instanceof s))throw new TypeError(`buffer should be of type ${s.name}`);this.cpuData=t.data;break}case"texture":{if(r!=="float32")throw new TypeError(`unsupported type "${r}" to create tensor from texture`);this.gpuTextureData=t.texture,this.downloader=t.download,this.disposer=t.dispose;break}case"gpu-buffer":{if(r!=="float32"&&r!=="float16"&&r!=="int32"&&r!=="int64"&&r!=="uint32"&&r!=="uint8"&&r!=="bool"&&r!=="uint4"&&r!=="int4")throw new TypeError(`unsupported type "${r}" to create tensor from gpu buffer`);this.gpuBufferData=t.gpuBuffer,this.downloader=t.download,this.disposer=t.dispose;break}case"ml-tensor":{if(r!=="float32"&&r!=="float16"&&r!=="int32"&&r!=="int64"&&r!=="uint32"&&r!=="uint64"&&r!=="int8"&&r!=="uint8"&&r!=="bool"&&r!=="uint4"&&r!=="int4")throw new TypeError(`unsupported type "${r}" to create tensor from MLTensor`);this.mlTensorData=t.mlTensor,this.downloader=t.download,this.disposer=t.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let s,u;if(typeof t=="string")if(r=t,u=o,t==="string"){if(!Array.isArray(n))throw new TypeError("A string tensor's data must be a string array.");s=n}else{let f=Z.get(t);if(f===void 0)throw new TypeError(`Unsupported tensor type: ${t}.`);if(Array.isArray(n)){if(t==="float16"&&f===Uint16Array||t==="uint4"||t==="int4")throw new TypeError(`Creating a ${t} tensor from number array is not supported. Please use ${f.name} as data.`);t==="uint64"||t==="int64"?s=f.from(n,BigInt):s=f.from(n)}else if(n instanceof f)s=n;else if(n instanceof Uint8ClampedArray)if(t==="uint8")s=Uint8Array.from(n);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(t==="float16"&&n instanceof Uint16Array&&f!==Uint16Array)s=new globalThis.Float16Array(n.buffer,n.byteOffset,n.length);else throw new TypeError(`A ${r} tensor's data must be type of ${f}`)}else if(u=n,Array.isArray(t)){if(t.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let f=typeof t[0];if(f==="string")r="string",s=t;else if(f==="boolean")r="bool",s=Uint8Array.from(t);else throw new TypeError(`Invalid element type of data array: ${f}.`)}else if(t instanceof Uint8ClampedArray)r="uint8",s=Uint8Array.from(t);else{let f=de.get(t.constructor);if(f===void 0)throw new TypeError(`Unsupported type for tensor data: ${t.constructor}.`);r=f,s=t}if(u===void 0)u=[s.length];else if(!Array.isArray(u))throw new TypeError("A tensor's dims must be a number array");i=u,this.cpuData=s,this.dataLocation="cpu"}let a=_t(i);if(this.cpuData&&a!==this.cpuData.length&&!((r==="uint4"||r==="int4")&&Math.ceil(a/2)===this.cpuData.length))throw new Error(`Tensor's size(${a}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=i,this.size=a}static async fromImage(t,n){return At(t,n)}static fromTexture(t,n){return Ot(t,n)}static fromGpuBuffer(t,n){return It(t,n)}static fromMLTensor(t,n){return Pt(t,n)}static fromPinnedBuffer(t,n,o){return Lt(t,n,o)}toDataURL(t){return Et(this,t)}toImageData(t){return Tt(this,t)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(t){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let n=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=n,t&&this.disposer&&(this.disposer(),this.disposer=void 0),n}finally{this.isDownloading=!1}}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(t){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return Mt(this,t)}}});var N,Xe=E(()=>{"use strict";Ee();N=U});var Ke,Ct,Y,q,Qe=E(()=>{"use strict";Je();Ke=(e,t)=>{(typeof C.trace>"u"?!C.wasm.trace:!C.trace)||console.timeStamp(`${e}::ORT::${t}`)},Ct=(e,t)=>{let n=new Error().stack?.split(/\r\n|\r|\n/g)||[],o=!1;for(let r=0;r<n.length;r++){if(o&&!n[r].includes("TRACE_FUNC")){let i=`FUNC_${e}::${n[r].trim().split(" ")[1]}`;t&&(i+=`::${t}`),Ke("CPU",i);return}n[r].includes("TRACE_FUNC")&&(o=!0)}},Y=e=>{(typeof C.trace>"u"?!C.wasm.trace:!C.trace)||Ct("BEGIN",e)},q=e=>{(typeof C.trace>"u"?!C.wasm.trace:!C.trace)||Ct("END",e)}});var Te,Rt=E(()=>{"use strict";qe();Xe();Qe();Te=class e{constructor(t){this.handler=t}async run(t,n,o){Y();let r={},i={};if(typeof t!="object"||t===null||t instanceof N||Array.isArray(t))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let a=!0;if(typeof n=="object"){if(n===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(n instanceof N)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(n)){if(n.length===0)throw new TypeError("'fetches' cannot be an empty array.");a=!1;for(let f of n){if(typeof f!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(f)===-1)throw new RangeError(`'fetches' contains invalid output name: ${f}.`);r[f]=null}if(typeof o=="object"&&o!==null)i=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else{let f=!1,c=Object.getOwnPropertyNames(n);for(let l of this.outputNames)if(c.indexOf(l)!==-1){let d=n[l];(d===null||d instanceof N)&&(f=!0,a=!1,r[l]=d)}if(f){if(typeof o=="object"&&o!==null)i=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else i=n}}else if(typeof n<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let f of this.inputNames)if(typeof t[f]>"u")throw new Error(`input '${f}' is missing in 'feeds'.`);if(a)for(let f of this.outputNames)r[f]=null;let s=await this.handler.run(t,r,i),u={};for(let f in s)if(Object.hasOwnProperty.call(s,f)){let c=s[f];c instanceof N?u[f]=c:u[f]=new N(c.type,c.data,c.dims)}return q(),u}async release(){return this.handler.dispose()}static async create(t,n,o,r){Y();let i,a={};if(typeof t=="string"){if(i=t,typeof n=="object"&&n!==null)a=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof Uint8Array){if(i=t,typeof n=="object"&&n!==null)a=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer){let c=t,l=0,d=t.byteLength;if(typeof n=="object"&&n!==null)a=n;else if(typeof n=="number"){if(l=n,!Number.isSafeInteger(l))throw new RangeError("'byteOffset' must be an integer.");if(l<0||l>=c.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${c.byteLength}).`);if(d=t.byteLength-l,typeof o=="number"){if(d=o,!Number.isSafeInteger(d))throw new RangeError("'byteLength' must be an integer.");if(d<=0||l+d>c.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${c.byteLength-l}].`);if(typeof r=="object"&&r!==null)a=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(typeof o<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof n<"u")throw new TypeError("'options' must be an object.");i=new Uint8Array(c,l,d)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[s,u]=await mt(a),f=await s.createInferenceSessionHandler(i,u);return q(),new e(f)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}get inputMetadata(){return this.handler.inputMetadata}get outputMetadata(){return this.handler.outputMetadata}}});var Ft,kt=E(()=>{"use strict";Rt();Ft=Te});var Nt=E(()=>{"use strict"});var Wt=E(()=>{"use strict"});var Gt=E(()=>{"use strict"});var $t=E(()=>{"use strict"});var et={};be(et,{InferenceSession:()=>Ft,TRACE:()=>Ke,TRACE_FUNC_BEGIN:()=>Y,TRACE_FUNC_END:()=>q,Tensor:()=>N,env:()=>O,registerBackend:()=>re});var X=E(()=>{"use strict";wt();gt();kt();Xe();Nt();Wt();Qe();Gt();$t()});var Se=E(()=>{"use strict"});var Vt={};be(Vt,{default:()=>xn});var Ht,jt,xn,Yt=E(()=>{"use strict";tt();K();Ae();Ht="ort-wasm-proxy-worker",jt=globalThis.self?.name===Ht;jt&&(self.onmessage=e=>{let{type:t,in:n}=e.data;try{switch(t){case"init-wasm":Oe(n.wasm).then(()=>{Ie(n).then(()=>{postMessage({type:t})},o=>{postMessage({type:t,err:o})})},o=>{postMessage({type:t,err:o})});break;case"init-ep":{let{epName:o,env:r}=n;Pe(r,o).then(()=>{postMessage({type:t})},i=>{postMessage({type:t,err:i})});break}case"copy-from":{let{buffer:o}=n,r=le(o);postMessage({type:t,out:r});break}case"create":{let{model:o,options:r}=n;Le(o,r).then(i=>{postMessage({type:t,out:i})},i=>{postMessage({type:t,err:i})});break}case"release":xe(n),postMessage({type:t});break;case"run":{let{sessionId:o,inputIndices:r,inputs:i,outputIndices:a,options:s}=n;ve(o,r,i,a,new Array(a.length).fill(null),s).then(u=>{u.some(f=>f[3]!=="cpu")?postMessage({type:t,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:t,out:u},Ue([...i,...u]))},u=>{postMessage({type:t,err:u})});break}case"end-profiling":Be(n),postMessage({type:t});break;default:}}catch(o){postMessage({type:t,err:o})}});xn=jt?null:e=>new Worker(e??R,{type:"classic",name:Ht})});var vn,Bn,R,_e,nt,Un,_n,Zt,Mn,qt,Xt,Jt,Kt,Ae=E(()=>{"use strict";Se();vn=typeof location>"u"?void 0:location.origin,Bn=()=>{if(!!1)return typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0},R=Bn(),_e=()=>{if(R&&!R.startsWith("blob:"))return R.substring(0,R.lastIndexOf("/")+1)},nt=(e,t)=>{try{let n=t??R;return(n?new URL(e,n):new URL(e)).origin===vn}catch{return!1}},Un=(e,t)=>{let n=t??R;try{return(n?new URL(e,n):new URL(e)).href}catch{return}},_n=(e,t)=>`${t??"./"}${e}`,Zt=async e=>{let n=await(await fetch(e,{credentials:"same-origin"})).blob();return URL.createObjectURL(n)},Mn=async e=>(await import(/*webpackIgnore:true*/e)).default,qt=(Yt(),Ye(Vt)).default,Xt=async()=>{if(!R)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(nt(R))return[void 0,qt()];let e=await Zt(R);return[e,qt(e)]},Jt=void 0,Kt=async(e,t,n)=>{if(!e&&!t&&Jt&&R&&nt(R))return[void 0,Jt];{let o="ort-wasm-simd-threaded.mjs",r=e??Un(o,t),i=!!1&&n&&r&&!nt(r,t),a=i?await Zt(r):r??_n(o,t);return[i?a:void 0,await Mn(a)]}}});var rt,ot,Me,Qt,Dn,Cn,Rn,Oe,A,K=E(()=>{"use strict";Ae();ot=!1,Me=!1,Qt=!1,Dn=()=>{if(typeof SharedArrayBuffer>"u")return!1;try{return typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch{return!1}},Cn=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch{return!1}},Rn=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,19,1,17,0,65,1,253,15,65,2,253,15,65,3,253,15,253,147,2,11]))}catch{return!1}},Oe=async e=>{if(ot)return Promise.resolve();if(Me)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(Qt)throw new Error("previous call to 'initializeWebAssembly()' failed.");Me=!0;let t=e.initTimeout,n=e.numThreads;if(e.simd!==!1){if(e.simd==="relaxed"){if(!Rn())throw new Error("Relaxed WebAssembly SIMD is not supported in the current environment.")}else if(!Cn())throw new Error("WebAssembly SIMD is not supported in the current environment.")}let o=Dn();n>1&&!o&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+n+", but this will not work unless you enable crossOriginIsolated mode. See https://web.dev/cross-origin-isolation-guide/ for more info."),console.warn("WebAssembly multi-threading is not supported in the current environment. Falling back to single-threading."),e.numThreads=n=1);let r=e.wasmPaths,i=typeof r=="string"?r:void 0,a=r?.mjs,s=a?.href??a,u=r?.wasm,f=u?.href??u,c=e.wasmBinary,[l,d]=await Kt(s,i,n>1),p=!1,w=[];if(t>0&&w.push(new Promise(b=>{setTimeout(()=>{p=!0,b()},t)})),w.push(new Promise((b,I)=>{let m={numThreads:n};if(c)m.wasmBinary=c;else if(f||i)m.locateFile=h=>f??i+h;else if(s&&s.indexOf("blob:")!==0)m.locateFile=h=>new URL(h,s).href;else if(l){let h=_e();h&&(m.locateFile=P=>h+P)}d(m).then(h=>{Me=!1,ot=!0,rt=h,b(),l&&URL.revokeObjectURL(l)},h=>{Me=!1,Qt=!0,I(h)})})),await Promise.race(w),p)throw new Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`)},A=()=>{if(ot&&rt)return rt;throw new Error("WebAssembly is not initialized yet.")}});var F,pe,T,De=E(()=>{"use strict";K();F=(e,t)=>{let n=A(),o=n.lengthBytesUTF8(e)+1,r=n._malloc(o);return n.stringToUTF8(e,r,o),t.push(r),r},pe=(e,t,n,o)=>{if(typeof e=="object"&&e!==null){if(n.has(e))throw new Error("Circular reference in options");n.add(e)}Object.entries(e).forEach(([r,i])=>{let a=t?t+r:r;if(typeof i=="object")pe(i,a+".",n,o);else if(typeof i=="string"||typeof i=="number")o(a,i.toString());else if(typeof i=="boolean")o(a,i?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof i}`)})},T=e=>{let t=A(),n=t.stackSave();try{let o=t.PTR_SIZE,r=t.stackAlloc(2*o);t._OrtGetLastError(r,r+o);let i=Number(t.getValue(r,o===4?"i32":"i64")),a=t.getValue(r+o,"*"),s=a?t.UTF8ToString(a):"";throw new Error(`${e} ERROR_CODE: ${i}, ERROR_MESSAGE: ${s}`)}finally{t.stackRestore(n)}}});var en,tn=E(()=>{"use strict";K();De();en=e=>{let t=A(),n=0,o=[],r=e||{};try{if(e?.logSeverityLevel===void 0)r.logSeverityLevel=2;else if(typeof e.logSeverityLevel!="number"||!Number.isInteger(e.logSeverityLevel)||e.logSeverityLevel<0||e.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${e.logSeverityLevel}`);if(e?.logVerbosityLevel===void 0)r.logVerbosityLevel=0;else if(typeof e.logVerbosityLevel!="number"||!Number.isInteger(e.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${e.logVerbosityLevel}`);e?.terminate===void 0&&(r.terminate=!1);let i=0;return e?.tag!==void 0&&(i=F(e.tag,o)),n=t._OrtCreateRunOptions(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,i),n===0&&T("Can't create run options."),e?.extra!==void 0&&pe(e.extra,"",new WeakSet,(a,s)=>{let u=F(a,o),f=F(s,o);t._OrtAddRunConfigEntry(n,u,f)!==0&&T(`Can't set a run config entry: ${a} - ${s}.`)}),[n,o]}catch(i){throw n!==0&&t._OrtReleaseRunOptions(n),o.forEach(a=>t._free(a)),i}}});var Fn,kn,Nn,Ce,Wn,nn,rn=E(()=>{"use strict";K();De();Fn=e=>{switch(e){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${e}`)}},kn=e=>{switch(e){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${e}`)}},Nn=e=>{e.extra||(e.extra={}),e.extra.session||(e.extra.session={});let t=e.extra.session;t.use_ort_model_bytes_directly||(t.use_ort_model_bytes_directly="1"),e.executionProviders&&e.executionProviders.some(n=>(typeof n=="string"?n:n.name)==="webgpu")&&(e.enableMemPattern=!1)},Ce=(e,t,n,o)=>{let r=F(t,o),i=F(n,o);A()._OrtAddSessionConfigEntry(e,r,i)!==0&&T(`Can't set a session config entry: ${t} - ${n}.`)},Wn=async(e,t,n)=>{for(let o of t){let r=typeof o=="string"?o:o.name,i=[];switch(r){case"webnn":if(r="WEBNN",typeof o!="string"){let l=o?.deviceType;l&&Ce(e,"deviceType",l,n)}break;case"webgpu":if(r="JS",typeof o!="string"){let c=o;if(c?.preferredLayout){if(c.preferredLayout!=="NCHW"&&c.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${c.preferredLayout}`);Ce(e,"preferredLayout",c.preferredLayout,n)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${r}`)}let a=F(r,n),s=i.length,u=0,f=0;if(s>0){u=A()._malloc(s*A().PTR_SIZE),n.push(u),f=A()._malloc(s*A().PTR_SIZE),n.push(f);for(let c=0;c<s;c++)A().setValue(u+c*A().PTR_SIZE,i[c][0],"*"),A().setValue(f+c*A().PTR_SIZE,i[c][1],"*")}await A()._OrtAppendExecutionProvider(e,a,u,f,s)!==0&&T(`Can't append execution provider: ${r}.`)}},nn=async e=>{let t=A(),n=0,o=[],r=e||{};Nn(r);try{let i=Fn(r.graphOptimizationLevel??"all"),a=kn(r.executionMode??"sequential"),s=typeof r.logId=="string"?F(r.logId,o):0,u=r.logSeverityLevel??2;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log serverity level is not valid: ${u}`);let f=r.logVerbosityLevel??0;if(!Number.isInteger(f)||f<0||f>4)throw new Error(`log verbosity level is not valid: ${f}`);let c=typeof r.optimizedModelFilePath=="string"?F(r.optimizedModelFilePath,o):0;if(n=t._OrtCreateSessionOptions(i,!!r.enableCpuMemArena,!!r.enableMemPattern,a,!!r.enableProfiling,0,s,u,f,c),n===0&&T("Can't create session options."),r.executionProviders&&await Wn(n,r.executionProviders,o),r.enableGraphCapture!==void 0){if(typeof r.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);Ce(n,"enableGraphCapture",r.enableGraphCapture.toString(),o)}if(r.freeDimensionOverrides)for(let[l,d]of Object.entries(r.freeDimensionOverrides)){if(typeof l!="string")throw new Error(`free dimension override name must be a string: ${l}`);if(typeof d!="number"||!Number.isInteger(d)||d<0)throw new Error(`free dimension override value must be a non-negative integer: ${d}`);let p=F(l,o);t._OrtAddFreeDimensionOverride(n,p,d)!==0&&T(`Can't set a free dimension override: ${l} - ${d}.`)}return r.extra!==void 0&&pe(r.extra,"",new WeakSet,(l,d)=>{Ce(n,l,d,o)}),[n,o]}catch(i){throw n!==0&&t._OrtReleaseSessionOptions(n)!==0&&T("Can't release session options."),o.forEach(a=>t._free(a)),i}}});var oe,Re,se,on,sn,Fe,ke,an,st=E(()=>{"use strict";oe=e=>{switch(e){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float16":return 10;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;case"int4":return 22;case"uint4":return 21;default:throw new Error(`unsupported data type: ${e}`)}},Re=e=>{switch(e){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 10:return"float16";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";case 22:return"int4";case 21:return"uint4";default:throw new Error(`unsupported data type: ${e}`)}},se=(e,t)=>{let n=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][e],o=typeof t=="number"?t:t.reduce((r,i)=>r*i,1);return n>0?Math.ceil(o*n):void 0},on=e=>{switch(e){case"float16":return typeof Float16Array<"u"&&Float16Array.from?Float16Array:Uint16Array;case"float32":return Float32Array;case"uint8":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"bool":return Uint8Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${e}`)}},sn=e=>{switch(e){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${e}`)}},Fe=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint8"||e==="bool"||e==="uint4"||e==="int4",ke=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint64"||e==="int8"||e==="uint8"||e==="bool"||e==="uint4"||e==="int4",an=e=>{switch(e){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;case"ml-tensor":return 5;default:throw new Error(`unsupported data location: ${e}`)}}});var me,at=E(()=>{"use strict";Se();me=async e=>{if(typeof e=="string")if(!1)try{let{readFile:t}=Ve("node:fs/promises");return new Uint8Array(await t(e))}catch(t){if(t.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:n}=Ve("node:fs"),o=n(e),r=[];for await(let i of o)r.push(i);return new Uint8Array(Buffer.concat(r))}throw t}else{let t=await fetch(e);if(!t.ok)throw new Error(`failed to load external data file: ${e}`);let n=t.headers.get("Content-Length"),o=n?parseInt(n,10):0;if(o<1073741824)return new Uint8Array(await t.arrayBuffer());{if(!t.body)throw new Error(`failed to load external data file: ${e}, no response body.`);let r=t.body.getReader(),i;try{i=new ArrayBuffer(o)}catch(s){if(s instanceof RangeError){let u=Math.ceil(o/65536);i=new WebAssembly.Memory({initial:u,maximum:u}).buffer}else throw s}let a=0;for(;;){let{done:s,value:u}=await r.read();if(s)break;let f=u.byteLength;new Uint8Array(i,a,f).set(u),a+=f}return new Uint8Array(i,0,o)}}else return e instanceof Blob?new Uint8Array(await e.arrayBuffer()):e instanceof Uint8Array?e:new Uint8Array(e)}});var Gn,Ie,Pe,ae,$n,un,le,Le,xe,fn,ve,Be,Ue,tt=E(()=>{"use strict";tn();rn();st();K();De();at();Gn=(e,t)=>{A()._OrtInit(e,t)!==0&&T("Can't initialize onnxruntime.")},Ie=async e=>{Gn(e.wasm.numThreads,sn(e.logLevel))},Pe=async(e,t)=>{A().asyncInit?.()},ae=new Map,$n=e=>{let t=A(),n=t.stackSave();try{let o=t.PTR_SIZE,r=t.stackAlloc(2*o);t._OrtGetInputOutputCount(e,r,r+o)!==0&&T("Can't get session input/output count.");let a=o===4?"i32":"i64";return[Number(t.getValue(r,a)),Number(t.getValue(r+o,a))]}finally{t.stackRestore(n)}},un=(e,t)=>{let n=A(),o=n.stackSave(),r=0;try{let i=n.PTR_SIZE,a=n.stackAlloc(2*i);n._OrtGetInputOutputMetadata(e,t,a,a+i)!==0&&T("Can't get session input/output metadata.");let u=Number(n.getValue(a,"*"));r=Number(n.getValue(a+i,"*"));let f=n.HEAP32[r/4];if(f===0)return[u,0];let c=n.HEAPU32[r/4+1],l=[];for(let d=0;d<c;d++){let p=Number(n.getValue(r+8+d*i,"*"));l.push(p!==0?n.UTF8ToString(p):Number(n.getValue(r+8+(d+c)*i,"*")))}return[u,f,l]}finally{n.stackRestore(o),r!==0&&n._OrtFree(r)}},le=e=>{let t=A(),n=t._malloc(e.byteLength);if(n===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);return t.HEAPU8.set(e,n),[n,e.byteLength]},Le=async(e,t)=>{let n,o,r=A();Array.isArray(e)?[n,o]=e:e.buffer===r.HEAPU8.buffer?[n,o]=[e.byteOffset,e.byteLength]:[n,o]=le(e);let i=0,a=0,s=0,u=[],f=[],c=[];try{if([a,u]=await nn(t),t?.externalData&&r.mountExternalData){let g=[];for(let S of t.externalData){let B=typeof S=="string"?S:S.path;g.push(me(typeof S=="string"?S:S.data).then(D=>{r.mountExternalData(B,D)}))}await Promise.all(g)}for(let g of t?.executionProviders??[])if((typeof g=="string"?g:g.name)==="webnn"){if(r.shouldTransferToMLTensor=!1,typeof g!="string"){let B=g,D=B?.context,_=B?.gpuDevice,te=B?.deviceType,fe=B?.powerPreference;D?r.currentContext=D:_?r.currentContext=await r.webnnCreateMLContext(_):r.currentContext=await r.webnnCreateMLContext({deviceType:te,powerPreference:fe})}else r.currentContext=await r.webnnCreateMLContext();break}i=await r._OrtCreateSession(n,o,a),r.webgpuOnCreateSession?.(i),i===0&&T("Can't create a session."),r.jsepOnCreateSession?.(),r.currentContext&&(r.webnnRegisterMLContext(i,r.currentContext),r.currentContext=void 0,r.shouldTransferToMLTensor=!0);let[l,d]=$n(i),p=!!t?.enableGraphCapture,w=[],b=[],I=[],m=[],h=[];for(let g=0;g<l;g++){let[S,B,D]=un(i,g);S===0&&T("Can't get an input name."),f.push(S);let _=r.UTF8ToString(S);w.push(_),I.push(B===0?{name:_,isTensor:!1}:{name:_,isTensor:!0,type:Re(B),shape:D})}for(let g=0;g<d;g++){let[S,B,D]=un(i,g+l);S===0&&T("Can't get an output name."),c.push(S);let _=r.UTF8ToString(S);b.push(_),m.push(B===0?{name:_,isTensor:!1}:{name:_,isTensor:!0,type:Re(B),shape:D})}return ae.set(i,[i,f,c,null,p,!1]),[i,w,b,I,m]}catch(l){throw f.forEach(d=>r._OrtFree(d)),c.forEach(d=>r._OrtFree(d)),s!==0&&r._OrtReleaseBinding(s)!==0&&T("Can't release IO binding."),i!==0&&r._OrtReleaseSession(i)!==0&&T("Can't release session."),l}finally{r._free(n),a!==0&&r._OrtReleaseSessionOptions(a)!==0&&T("Can't release session options."),u.forEach(l=>r._free(l)),r.unmountExternalData?.()}},xe=e=>{let t=A(),n=ae.get(e);if(!n)throw new Error(`cannot release session. invalid session id: ${e}`);let[o,r,i,a,s]=n;a&&(s&&t._OrtClearBoundOutputs(a.handle)!==0&&T("Can't clear bound outputs."),t._OrtReleaseBinding(a.handle)!==0&&T("Can't release IO binding.")),t.jsepOnReleaseSession?.(e),t.webnnOnReleaseSession?.(e),t.webgpuOnReleaseSession?.(e),r.forEach(u=>t._OrtFree(u)),i.forEach(u=>t._OrtFree(u)),t._OrtReleaseSession(o)!==0&&T("Can't release session."),ae.delete(e)},fn=async(e,t,n,o,r,i,a=!1)=>{if(!e){t.push(0);return}let s=A(),u=s.PTR_SIZE,f=e[0],c=e[1],l=e[3],d=l,p,w;if(f==="string"&&(l==="gpu-buffer"||l==="ml-tensor"))throw new Error("String tensor is not supported on GPU.");if(a&&l!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${i} when enableGraphCapture is true.`);if(l==="gpu-buffer"){let m=e[2].gpuBuffer;w=se(oe(f),c);{let h=s.jsepRegisterBuffer;if(!h)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');p=h(o,i,m,w)}}else if(l==="ml-tensor"){let m=e[2].mlTensor;w=se(oe(f),c);let h=s.webnnRegisterMLTensor;if(!h)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');p=h(o,m,oe(f),c)}else{let m=e[2];if(Array.isArray(m)){w=u*m.length,p=s._malloc(w),n.push(p);for(let h=0;h<m.length;h++){if(typeof m[h]!="string")throw new TypeError(`tensor data at index ${h} is not a string`);s.setValue(p+h*u,F(m[h],n),"*")}}else{let h=s.webnnIsGraphInput,P=s.webnnIsGraphOutput;if(f!=="string"&&h&&P){let g=s.UTF8ToString(r);if(h(o,g)||P(o,g)){let S=oe(f);w=se(S,c),d="ml-tensor";let B=s.webnnCreateTemporaryTensor,D=s.webnnUploadTensor;if(!B||!D)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');let _=await B(o,S,c);D(_,new Uint8Array(m.buffer,m.byteOffset,m.byteLength)),p=_}else w=m.byteLength,p=s._malloc(w),n.push(p),s.HEAPU8.set(new Uint8Array(m.buffer,m.byteOffset,w),p)}else w=m.byteLength,p=s._malloc(w),n.push(p),s.HEAPU8.set(new Uint8Array(m.buffer,m.byteOffset,w),p)}}let b=s.stackSave(),I=s.stackAlloc(4*c.length);try{c.forEach((h,P)=>s.setValue(I+P*u,h,u===4?"i32":"i64"));let m=s._OrtCreateTensor(oe(f),p,w,I,c.length,an(d));m===0&&T(`Can't create tensor for input/output. session=${o}, index=${i}.`),t.push(m)}finally{s.stackRestore(b)}},ve=async(e,t,n,o,r,i)=>{let a=A(),s=a.PTR_SIZE,u=ae.get(e);if(!u)throw new Error(`cannot run inference. invalid session id: ${e}`);let f=u[0],c=u[1],l=u[2],d=u[3],p=u[4],w=u[5],b=t.length,I=o.length,m=0,h=[],P=[],g=[],S=[],B=a.stackSave(),D=a.stackAlloc(b*s),_=a.stackAlloc(b*s),te=a.stackAlloc(I*s),fe=a.stackAlloc(I*s);try{[m,h]=en(i);for(let y=0;y<b;y++)await fn(n[y],P,S,e,c[t[y]],t[y],p);for(let y=0;y<I;y++)await fn(r[y],g,S,e,l[o[y]],b+o[y],p);for(let y=0;y<b;y++)a.setValue(D+y*s,P[y],"*"),a.setValue(_+y*s,c[t[y]],"*");for(let y=0;y<I;y++)a.setValue(te+y*s,g[y],"*"),a.setValue(fe+y*s,l[o[y]],"*");a.jsepOnRunStart?.(f),a.webnnOnRunStart?.(f);let k;k=await a._OrtRun(f,_,D,b,fe,I,te,m),k!==0&&T("failed to call OrtRun().");let $=[],ct=[];for(let y=0;y<I;y++){let z=Number(a.getValue(te+y*s,"*"));if(z===g[y]){$.push(r[y]);continue}let dt=a.stackSave(),G=a.stackAlloc(4*s),ne=!1,x,M=0;try{a._OrtGetTensorData(z,G,G+s,G+2*s,G+3*s)!==0&&T(`Can't access output tensor data on index ${y}.`);let He=s===4?"i32":"i64",he=Number(a.getValue(G,He));M=a.getValue(G+s,"*");let lt=a.getValue(G+s*2,"*"),Sn=Number(a.getValue(G+s*3,He)),H=[];for(let v=0;v<Sn;v++)H.push(Number(a.getValue(lt+v*s,He)));a._OrtFree(lt)!==0&&T("Can't free memory for tensor dims.");let j=H.reduce((v,L)=>v*L,1);x=Re(he);let ce=d?.outputPreferredLocations[o[y]];if(x==="string"){if(ce==="gpu-buffer"||ce==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let v=[];for(let L=0;L<j;L++){let V=a.getValue(M+L*s,"*"),ye=a.getValue(M+(L+1)*s,"*"),pt=L===j-1?void 0:ye-V;v.push(a.UTF8ToString(V,pt))}$.push([x,H,v,"cpu"])}else if(ce==="gpu-buffer"&&j>0){let v=a.jsepGetBuffer;if(!v)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let L=v(M),V=se(he,j);if(V===void 0||!Fe(x))throw new Error(`Unsupported data type: ${x}`);ne=!0,$.push([x,H,{gpuBuffer:L,download:a.jsepCreateDownloader(L,V,x),dispose:()=>{a._OrtReleaseTensor(z)!==0&&T("Can't release tensor.")}},"gpu-buffer"])}else if(ce==="ml-tensor"&&j>0){let v=a.webnnEnsureTensor,L=a.webnnIsGraphInputOutputTypeSupported;if(!v||!L)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(se(he,j)===void 0||!ke(x))throw new Error(`Unsupported data type: ${x}`);if(!L(e,x,!1))throw new Error(`preferredLocation "ml-tensor" for ${x} output is not supported by current WebNN Context.`);let ye=await v(e,M,he,H,!1);ne=!0,$.push([x,H,{mlTensor:ye,download:a.webnnCreateMLTensorDownloader(M,x),dispose:()=>{a.webnnReleaseTensorId(M),a._OrtReleaseTensor(z)}},"ml-tensor"])}else if(ce==="ml-tensor-cpu-output"&&j>0){let v=a.webnnCreateMLTensorDownloader(M,x)(),L=$.length;ne=!0,ct.push((async()=>{let V=[L,await v];return a.webnnReleaseTensorId(M),a._OrtReleaseTensor(z),V})()),$.push([x,H,[],"cpu"])}else{let v=on(x),L=new v(j);new Uint8Array(L.buffer,L.byteOffset,L.byteLength).set(a.HEAPU8.subarray(M,M+L.byteLength)),$.push([x,H,L,"cpu"])}}finally{a.stackRestore(dt),x==="string"&&M&&a._free(M),ne||a._OrtReleaseTensor(z)}}d&&!p&&(a._OrtClearBoundOutputs(d.handle)!==0&&T("Can't clear bound outputs."),ae.set(e,[f,c,l,d,p,!1]));for(let[y,z]of await Promise.all(ct))$[y][2]=z;return $}finally{a.webnnOnRunEnd?.(f),a.stackRestore(B),P.forEach(k=>a._OrtReleaseTensor(k)),g.forEach(k=>a._OrtReleaseTensor(k)),S.forEach(k=>a._free(k)),m!==0&&a._OrtReleaseRunOptions(m),h.forEach(k=>a._free(k))}},Be=e=>{let t=A(),n=ae.get(e);if(!n)throw new Error("invalid session id");let o=n[0],r=t._OrtEndProfiling(o);r===0&&T("Can't get an profile file name."),t._OrtFree(r)},Ue=e=>{let t=[];for(let n of e){let o=n[2];!Array.isArray(o)&&"buffer"in o&&t.push(o.buffer)}return t}});var ee,W,we,We,Ge,Ne,it,ut,ie,ue,Hn,cn,dn,ln,pn,mn,wn,hn,ft=E(()=>{"use strict";X();tt();K();Ae();ee=()=>!!O.wasm.proxy&&typeof document<"u",we=!1,We=!1,Ge=!1,ut=new Map,ie=(e,t)=>{let n=ut.get(e);n?n.push(t):ut.set(e,[t])},ue=()=>{if(we||!We||Ge||!W)throw new Error("worker not ready")},Hn=e=>{switch(e.data.type){case"init-wasm":we=!1,e.data.err?(Ge=!0,it[1](e.data.err)):(We=!0,it[0]()),Ne&&(URL.revokeObjectURL(Ne),Ne=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let t=ut.get(e.data.type);e.data.err?t.shift()[1](e.data.err):t.shift()[0](e.data.out);break}default:}},cn=async()=>{if(!We){if(we)throw new Error("multiple calls to 'initWasm()' detected.");if(Ge)throw new Error("previous call to 'initWasm()' failed.");if(we=!0,ee())return new Promise((e,t)=>{W?.terminate(),Xt().then(([n,o])=>{try{W=o,W.onerror=i=>t(i),W.onmessage=Hn,it=[e,t];let r={type:"init-wasm",in:O};if(!r.in.wasm.wasmPaths&&n){let i=_e();i&&(r.in.wasm.wasmPaths=i)}W.postMessage(r),Ne=n}catch(r){t(r)}},t)});try{await Oe(O.wasm),await Ie(O),We=!0}catch(e){throw Ge=!0,e}finally{we=!1}}},dn=async e=>{if(ee())return ue(),new Promise((t,n)=>{ie("init-ep",[t,n]);let o={type:"init-ep",in:{epName:e,env:O}};W.postMessage(o)});await Pe(O,e)},ln=async e=>ee()?(ue(),new Promise((t,n)=>{ie("copy-from",[t,n]);let o={type:"copy-from",in:{buffer:e}};W.postMessage(o,[e.buffer])})):le(e),pn=async(e,t)=>{if(ee()){if(t?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return ue(),new Promise((n,o)=>{ie("create",[n,o]);let r={type:"create",in:{model:e,options:{...t}}},i=[];e instanceof Uint8Array&&i.push(e.buffer),W.postMessage(r,i)})}else return Le(e,t)},mn=async e=>{if(ee())return ue(),new Promise((t,n)=>{ie("release",[t,n]);let o={type:"release",in:e};W.postMessage(o)});xe(e)},wn=async(e,t,n,o,r,i)=>{if(ee()){if(n.some(a=>a[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(r.some(a=>a))throw new Error("pre-allocated output tensor is not supported for proxy.");return ue(),new Promise((a,s)=>{ie("run",[a,s]);let u=n,f={type:"run",in:{sessionId:e,inputIndices:t,inputs:u,outputIndices:o,options:i}};W.postMessage(f,Ue(u))})}else return ve(e,t,n,o,r,i)},hn=async e=>{if(ee())return ue(),new Promise((t,n)=>{ie("end-profiling",[t,n]);let o={type:"end-profiling",in:e};W.postMessage(o)});Be(e)}});var yn,jn,$e,bn=E(()=>{"use strict";X();ft();st();Se();at();yn=(e,t)=>{switch(e.location){case"cpu":return[e.type,e.dims,e.data,"cpu"];case"gpu-buffer":return[e.type,e.dims,{gpuBuffer:e.gpuBuffer},"gpu-buffer"];case"ml-tensor":return[e.type,e.dims,{mlTensor:e.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${e.location} for ${t()}`)}},jn=e=>{switch(e[3]){case"cpu":return new N(e[0],e[2],e[1]);case"gpu-buffer":{let t=e[0];if(!Fe(t))throw new Error(`not supported data type: ${t} for deserializing GPU tensor`);let{gpuBuffer:n,download:o,dispose:r}=e[2];return N.fromGpuBuffer(n,{dataType:t,dims:e[1],download:o,dispose:r})}case"ml-tensor":{let t=e[0];if(!ke(t))throw new Error(`not supported data type: ${t} for deserializing MLTensor tensor`);let{mlTensor:n,download:o,dispose:r}=e[2];return N.fromMLTensor(n,{dataType:t,dims:e[1],download:o,dispose:r})}default:throw new Error(`invalid data location: ${e[3]}`)}},$e=class{async fetchModelAndCopyToWasmMemory(t){return ln(await me(t))}async loadModel(t,n){Y();let o;typeof t=="string"?o=await this.fetchModelAndCopyToWasmMemory(t):o=t,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await pn(o,n),q()}async dispose(){return mn(this.sessionId)}async run(t,n,o){Y();let r=[],i=[];Object.entries(t).forEach(d=>{let p=d[0],w=d[1],b=this.inputNames.indexOf(p);if(b===-1)throw new Error(`invalid input '${p}'`);r.push(w),i.push(b)});let a=[],s=[];Object.entries(n).forEach(d=>{let p=d[0],w=d[1],b=this.outputNames.indexOf(p);if(b===-1)throw new Error(`invalid output '${p}'`);a.push(w),s.push(b)});let u=r.map((d,p)=>yn(d,()=>`input "${this.inputNames[i[p]]}"`)),f=a.map((d,p)=>d?yn(d,()=>`output "${this.outputNames[s[p]]}"`):null),c=await wn(this.sessionId,i,u,s,f,o),l={};for(let d=0;d<c.length;d++)l[this.outputNames[s[d]]]=a[d]??jn(c[d]);return q(),l}startProfiling(){}endProfiling(){hn(this.sessionId)}}});var En={};be(En,{OnnxruntimeWebAssemblyBackend:()=>ze,initializeFlags:()=>gn,wasmBackend:()=>Vn});var gn,ze,Vn,Tn=E(()=>{"use strict";X();ft();bn();gn=()=>{(typeof O.wasm.initTimeout!="number"||O.wasm.initTimeout<0)&&(O.wasm.initTimeout=0);let e=O.wasm.simd;if(typeof e!="boolean"&&e!==void 0&&e!=="fixed"&&e!=="relaxed"&&(console.warn(`Property "env.wasm.simd" is set to unknown value "${e}". Reset it to \`false\` and ignore SIMD feature checking.`),O.wasm.simd=!1),typeof O.wasm.proxy!="boolean"&&(O.wasm.proxy=!1),typeof O.wasm.trace!="boolean"&&(O.wasm.trace=!1),typeof O.wasm.numThreads!="number"||!Number.isInteger(O.wasm.numThreads)||O.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)O.wasm.numThreads=1;else{let t=typeof navigator>"u"?Ve("node:os").cpus().length:navigator.hardwareConcurrency;O.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}},ze=class{async init(t){gn(),await cn(),await dn(t)}async createInferenceSessionHandler(t,n){let o=new $e;return await o.loadModel(t,n),o}},Vn=new ze});var qn={};be(qn,{InferenceSession:()=>Ft,TRACE:()=>Ke,TRACE_FUNC_BEGIN:()=>Y,TRACE_FUNC_END:()=>q,Tensor:()=>N,default:()=>Yn,env:()=>O,registerBackend:()=>re});X();X();X();var zt="1.22.0";var Yn=et;{let e=(Tn(),Ye(En)).wasmBackend;re("cpu",e,10),re("wasm",e,10)}Object.defineProperty(O.versions,"web",{value:zt,enumerable:!0});return Ye(qn);})();
|
| 7 |
+
typeof exports=="object"&&typeof module=="object"&&(module.exports=ort);
|
| 8 |
+
//# sourceMappingURL=ort.wasm.min.js.map
|