token-goat 2.9.29 → 2.9.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -40
- package/SECURITY.md +28 -10
- package/THIRD_PARTY_NOTICES.md +40 -3
- package/dist/native/linux-arm64/tg-hook +0 -0
- package/dist/native/linux-x64/tg-hook +0 -0
- package/dist/ort-wasm-simd-threaded.mjs +59 -0
- package/dist/token-goat-chunk-3CHUNJ2O.mjs +53 -0
- package/dist/token-goat-chunk-3Z5S4KGM.mjs +918 -0
- package/dist/token-goat-chunk-4FVIAHSI.mjs +211 -0
- package/dist/{token-goat-chunk-PGTH2U4C.mjs → token-goat-chunk-4JJS54TR.mjs} +4 -3
- package/dist/token-goat-chunk-4LCCNRTG.mjs +313 -0
- package/dist/{token-goat-chunk-L7H3U27L.mjs → token-goat-chunk-54K3EUV3.mjs} +1 -1
- package/dist/token-goat-chunk-56EIMS3E.mjs +159 -0
- package/dist/token-goat-chunk-5BCIJXMO.mjs +609 -0
- package/dist/token-goat-chunk-5KDMCMF2.mjs +362 -0
- package/dist/token-goat-chunk-5RG5SBL6.mjs +221 -0
- package/dist/{token-goat-chunk-RRNZMM3A.mjs → token-goat-chunk-5Y6ZYL6U.mjs} +21 -2
- package/dist/{token-goat-chunk-GLXRTTLE.mjs → token-goat-chunk-64FBPDTK.mjs} +12 -8
- package/dist/{token-goat-chunk-G23DWHV4.mjs → token-goat-chunk-664RTTUV.mjs} +28 -15
- package/dist/token-goat-chunk-67TQJ76B.mjs +57 -0
- package/dist/token-goat-chunk-6QMAS7AB.mjs +42 -0
- package/dist/token-goat-chunk-7BXSNBY5.mjs +253 -0
- package/dist/{token-goat-chunk-IVWI2OCK.mjs → token-goat-chunk-7F2UBPD3.mjs} +40 -11
- package/dist/{token-goat-chunk-TGOXNAHW.mjs → token-goat-chunk-7IN2MKDS.mjs} +682 -501
- package/dist/token-goat-chunk-7NADEDKJ.mjs +124 -0
- package/dist/{token-goat-chunk-KOPIR3KZ.mjs → token-goat-chunk-A3CK6N5Z.mjs} +618 -72
- package/dist/{token-goat-chunk-O6I2XU4P.mjs → token-goat-chunk-AFLYLHDH.mjs} +44 -31
- package/dist/{token-goat-chunk-TCQANXYC.mjs → token-goat-chunk-AM5V6GSX.mjs} +18 -2
- package/dist/{token-goat-chunk-E4ZOJIZK.mjs → token-goat-chunk-APGZXSPS.mjs} +39 -146
- package/dist/{token-goat-chunk-D4ETHJD6.mjs → token-goat-chunk-ARDNEC2U.mjs} +9 -7
- package/dist/token-goat-chunk-ATCPY7EQ.mjs +134 -0
- package/dist/token-goat-chunk-B2RZZCSS.mjs +354 -0
- package/dist/{token-goat-chunk-BGYOZ6DO.mjs → token-goat-chunk-B45VMIIH.mjs} +6 -7
- package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
- package/dist/{token-goat-chunk-TDUT2CL6.mjs → token-goat-chunk-C63JQV5K.mjs} +45 -6
- package/dist/{token-goat-chunk-ZER6EAXZ.mjs → token-goat-chunk-COBQGL5S.mjs} +2661 -2440
- package/dist/token-goat-chunk-COTXZHTS.mjs +39 -0
- package/dist/{token-goat-chunk-RQGGMPCR.mjs → token-goat-chunk-CYCEYAEO.mjs} +76 -16
- package/dist/token-goat-chunk-CZ3LUXYZ.mjs +4115 -0
- package/dist/{token-goat-chunk-ASLWOQ3I.mjs → token-goat-chunk-DZX2YDPT.mjs} +2 -1
- package/dist/token-goat-chunk-E3OQX2XT.mjs +824 -0
- package/dist/token-goat-chunk-EFHMMIGP.mjs +68 -0
- package/dist/token-goat-chunk-ETBHVDB6.mjs +328 -0
- package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
- package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
- package/dist/{token-goat-chunk-RTMVLHWX.mjs → token-goat-chunk-FBNQNSJK.mjs} +2555 -5127
- package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
- package/dist/{token-goat-chunk-RLP6J7WR.mjs → token-goat-chunk-FZ3NEW5O.mjs} +33 -19
- package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
- package/dist/{token-goat-chunk-DNRPXHYH.mjs → token-goat-chunk-GFBSN7BD.mjs} +29 -401
- package/dist/{token-goat-chunk-XYWPOSCN.mjs → token-goat-chunk-GOLEOXZP.mjs} +763 -211
- package/dist/token-goat-chunk-H2K3QP6H.mjs +24 -0
- package/dist/token-goat-chunk-H2PHHGM5.mjs +188 -0
- package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
- package/dist/token-goat-chunk-HG45AF2B.mjs +2228 -0
- package/dist/{token-goat-chunk-HUYUHODZ.mjs → token-goat-chunk-HOJLCGDP.mjs} +12965 -11748
- package/dist/{token-goat-chunk-435UQTKD.mjs → token-goat-chunk-HYBFA5X3.mjs} +118 -19
- package/dist/token-goat-chunk-IVALLT3S.mjs +48 -0
- package/dist/{token-goat-chunk-UXSXQQIY.mjs → token-goat-chunk-IVKIZWAB.mjs} +3 -3
- package/dist/{token-goat-chunk-52NSDWYY.mjs → token-goat-chunk-JB6QN6VF.mjs} +6 -4
- package/dist/{token-goat-chunk-HNFZZHFW.mjs → token-goat-chunk-JDHE26RP.mjs} +10 -3
- package/dist/{token-goat-chunk-FTP4U4QA.mjs → token-goat-chunk-JDU3EXSU.mjs} +12 -11
- package/dist/token-goat-chunk-JDWCRD6M.mjs +253 -0
- package/dist/{token-goat-chunk-6AK46ZT7.mjs → token-goat-chunk-JN4XMLSD.mjs} +5 -1
- package/dist/token-goat-chunk-JTQQGXZH.mjs +733 -0
- package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
- package/dist/token-goat-chunk-KQNZDCBD.mjs +47 -0
- package/dist/{token-goat-chunk-2WOUYWLM.mjs → token-goat-chunk-KWPNJBDH.mjs} +27 -3
- package/dist/{token-goat-chunk-DPNLUJWB.mjs → token-goat-chunk-LOBGHXPB.mjs} +30 -8
- package/dist/token-goat-chunk-MKPF4CL5.mjs +37 -0
- package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
- package/dist/{token-goat-chunk-DNSPXQXQ.mjs → token-goat-chunk-N2NMER56.mjs} +25 -15
- package/dist/token-goat-chunk-NYKZLXMK.mjs +218 -0
- package/dist/token-goat-chunk-OJBNYTJP.mjs +3087 -0
- package/dist/token-goat-chunk-P4QMM4WK.mjs +295 -0
- package/dist/token-goat-chunk-PD5VKH46.mjs +184 -0
- package/dist/token-goat-chunk-PEPTHRFF.mjs +129 -0
- package/dist/{token-goat-chunk-NMBWLRHW.mjs → token-goat-chunk-PU7V3FD6.mjs} +8721 -11104
- package/dist/token-goat-chunk-PY533T7F.mjs +46 -0
- package/dist/token-goat-chunk-Q5VTGRH7.mjs +761 -0
- package/dist/{token-goat-chunk-67BNIKKO.mjs → token-goat-chunk-QCLDAQTS.mjs} +31 -20
- package/dist/{token-goat-chunk-SE6E4BKJ.mjs → token-goat-chunk-QSBRTGM2.mjs} +9 -2
- package/dist/{token-goat-chunk-VZQEWRVH.mjs → token-goat-chunk-RC35RBUL.mjs} +4 -4
- package/dist/{token-goat-chunk-VMFWNHGR.mjs → token-goat-chunk-RHXKCZX3.mjs} +873 -504
- package/dist/{token-goat-chunk-PYSUADX4.mjs → token-goat-chunk-RZRTDST7.mjs} +17 -7
- package/dist/{token-goat-chunk-ONXH6NZ5.mjs → token-goat-chunk-SJHWVNDQ.mjs} +15 -21
- package/dist/token-goat-chunk-SMVRN2HU.mjs +188 -0
- package/dist/{token-goat-chunk-QO3LXVVR.mjs → token-goat-chunk-SQSSNQPE.mjs} +2295 -1718
- package/dist/{token-goat-chunk-2AWQ2R5X.mjs → token-goat-chunk-T4FK7VOV.mjs} +2 -2
- package/dist/token-goat-chunk-U4N3BN2W.mjs +92 -0
- package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
- package/dist/{token-goat-chunk-UA5BKWWQ.mjs → token-goat-chunk-UQ5UK2T7.mjs} +15 -4
- package/dist/token-goat-chunk-USILZ3T3.mjs +53 -0
- package/dist/{token-goat-chunk-MELOKFDJ.mjs → token-goat-chunk-VES7EL7O.mjs} +7 -1
- package/dist/{token-goat-chunk-7CPMDFGB.mjs → token-goat-chunk-VL3YIFHZ.mjs} +389 -14
- package/dist/{token-goat-chunk-E5TK5DNO.mjs → token-goat-chunk-VPBBTSJR.mjs} +356 -129
- package/dist/{token-goat-chunk-YOOVFPTP.mjs → token-goat-chunk-W3QCJS6G.mjs} +10 -2
- package/dist/{token-goat-chunk-LZNBQTDK.mjs → token-goat-chunk-WY3L4DVT.mjs} +11 -7
- package/dist/token-goat-chunk-XKI4SEMX.mjs +66 -0
- package/dist/token-goat-chunk-XU4P6Z24.mjs +133 -0
- package/dist/{token-goat-chunk-H5J3C56Q.mjs → token-goat-chunk-Y776AENC.mjs} +112 -26
- package/dist/token-goat-chunk-YARZFCZS.mjs +359 -0
- package/dist/{token-goat-chunk-S4VSXURL.mjs → token-goat-chunk-Z44YO3QZ.mjs} +4 -0
- package/dist/token-goat-chunk-Z57YODA2.mjs +35 -0
- package/dist/{token-goat-chunk-PQ53BSCF.mjs → token-goat-chunk-ZCDTCVIS.mjs} +48 -29
- package/dist/token-goat-chunk-ZEJVMUQH.mjs +48 -0
- package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
- package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
- package/dist/{token-goat-chunk-PKRWMHVP.mjs → token-goat-chunk-ZQSJMO2R.mjs} +338 -170
- package/dist/token-goat-hook-client.cjs +87 -23
- package/dist/token-goat-hook-client.mjs +3 -3
- package/dist/token-goat-hook.mjs +46 -30
- package/dist/token-goat.core.mjs +6 -6
- package/docs/C4_RUNTIME_ARCHITECTURE.md +1 -1
- package/docs/cli.md +80 -46
- package/docs/install.md +47 -14
- package/docs/security.md +7 -7
- package/package.json +17 -7
- package/scripts/verify-native-dist.mjs +386 -0
- package/dist/token-goat-chunk-2NNUA2LR.mjs +0 -143
- package/dist/token-goat-chunk-44BM7DDQ.mjs +0 -294
- package/dist/token-goat-chunk-C5YPNZKQ.mjs +0 -318
- package/dist/token-goat-chunk-CIQ2FTY3.mjs +0 -1990
- package/dist/token-goat-chunk-EUSDXRXU.mjs +0 -1429
- package/dist/token-goat-chunk-G7IWXCFF.mjs +0 -456
- package/dist/token-goat-chunk-JTKCQMQA.mjs +0 -418
- package/dist/token-goat-chunk-ORNFMIER.mjs +0 -295
- package/dist/token-goat-chunk-VQ6F6T7X.mjs +0 -36
- package/dist/token-goat-chunk-YAGLESS3.mjs +0 -23
- package/dist/token-goat-chunk-YKSRAWUU.mjs +0 -33
- package/dist/token-goat-chunk-Z6KBMOBI.mjs +0 -53
|
@@ -0,0 +1,2096 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
__export,
|
|
5
|
+
init_define_import_meta_env
|
|
6
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
7
|
+
|
|
8
|
+
// node_modules/onnxruntime-web/dist/ort.node.min.mjs
|
|
9
|
+
init_define_import_meta_env();
|
|
10
|
+
import { createRequire } from "module";
|
|
11
|
+
|
|
12
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/index.js
|
|
13
|
+
var esm_exports = {};
|
|
14
|
+
__export(esm_exports, {
|
|
15
|
+
InferenceSession: () => InferenceSession2,
|
|
16
|
+
TRACE: () => TRACE,
|
|
17
|
+
TRACE_EVENT_BEGIN: () => TRACE_EVENT_BEGIN,
|
|
18
|
+
TRACE_EVENT_END: () => TRACE_EVENT_END,
|
|
19
|
+
TRACE_FUNC_BEGIN: () => TRACE_FUNC_BEGIN,
|
|
20
|
+
TRACE_FUNC_END: () => TRACE_FUNC_END,
|
|
21
|
+
Tensor: () => Tensor2,
|
|
22
|
+
env: () => env2,
|
|
23
|
+
registerBackend: () => registerBackend
|
|
24
|
+
});
|
|
25
|
+
init_define_import_meta_env();
|
|
26
|
+
|
|
27
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/backend.js
|
|
28
|
+
init_define_import_meta_env();
|
|
29
|
+
|
|
30
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/backend-impl.js
|
|
31
|
+
init_define_import_meta_env();
|
|
32
|
+
var backends = /* @__PURE__ */ new Map();
|
|
33
|
+
var backendsSortedByPriority = [];
|
|
34
|
+
var registerBackend = (name, backend, priority) => {
|
|
35
|
+
if (backend && typeof backend.init === "function" && typeof backend.createInferenceSessionHandler === "function") {
|
|
36
|
+
const currentBackend = backends.get(name);
|
|
37
|
+
if (currentBackend === void 0) {
|
|
38
|
+
backends.set(name, { backend, priority });
|
|
39
|
+
} else if (currentBackend.priority > priority) {
|
|
40
|
+
return;
|
|
41
|
+
} else if (currentBackend.priority === priority) {
|
|
42
|
+
if (currentBackend.backend !== backend) {
|
|
43
|
+
throw new Error(`cannot register backend "${name}" using priority ${priority}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (priority >= 0) {
|
|
47
|
+
const i = backendsSortedByPriority.indexOf(name);
|
|
48
|
+
if (i !== -1) {
|
|
49
|
+
backendsSortedByPriority.splice(i, 1);
|
|
50
|
+
}
|
|
51
|
+
for (let i2 = 0; i2 < backendsSortedByPriority.length; i2++) {
|
|
52
|
+
if (backends.get(backendsSortedByPriority[i2]).priority <= priority) {
|
|
53
|
+
backendsSortedByPriority.splice(i2, 0, name);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
backendsSortedByPriority.push(name);
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
throw new TypeError("not a valid backend");
|
|
62
|
+
};
|
|
63
|
+
var tryResolveAndInitializeBackend = async (backendName) => {
|
|
64
|
+
const backendInfo = backends.get(backendName);
|
|
65
|
+
if (!backendInfo) {
|
|
66
|
+
return "backend not found.";
|
|
67
|
+
}
|
|
68
|
+
if (backendInfo.initialized) {
|
|
69
|
+
return backendInfo.backend;
|
|
70
|
+
} else if (backendInfo.aborted) {
|
|
71
|
+
return backendInfo.error;
|
|
72
|
+
} else {
|
|
73
|
+
const isInitializing = !!backendInfo.initPromise;
|
|
74
|
+
try {
|
|
75
|
+
if (!isInitializing) {
|
|
76
|
+
backendInfo.initPromise = backendInfo.backend.init(backendName);
|
|
77
|
+
}
|
|
78
|
+
await backendInfo.initPromise;
|
|
79
|
+
backendInfo.initialized = true;
|
|
80
|
+
return backendInfo.backend;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (!isInitializing) {
|
|
83
|
+
backendInfo.error = `${e}`;
|
|
84
|
+
backendInfo.aborted = true;
|
|
85
|
+
}
|
|
86
|
+
return backendInfo.error;
|
|
87
|
+
} finally {
|
|
88
|
+
delete backendInfo.initPromise;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var resolveBackendAndExecutionProviders = async (options) => {
|
|
93
|
+
const eps = options.executionProviders || [];
|
|
94
|
+
const backendHints = eps.map((i) => typeof i === "string" ? i : i.name);
|
|
95
|
+
const backendNames = backendHints.length === 0 ? backendsSortedByPriority : backendHints;
|
|
96
|
+
let backend;
|
|
97
|
+
const errors = [];
|
|
98
|
+
const availableBackendNames = /* @__PURE__ */ new Set();
|
|
99
|
+
for (const backendName of backendNames) {
|
|
100
|
+
const resolveResult = await tryResolveAndInitializeBackend(backendName);
|
|
101
|
+
if (typeof resolveResult === "string") {
|
|
102
|
+
errors.push({ name: backendName, err: resolveResult });
|
|
103
|
+
} else {
|
|
104
|
+
if (!backend) {
|
|
105
|
+
backend = resolveResult;
|
|
106
|
+
}
|
|
107
|
+
if (backend === resolveResult) {
|
|
108
|
+
availableBackendNames.add(backendName);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!backend) {
|
|
113
|
+
throw new Error(`no available backend found. ERR: ${errors.map((e) => `[${e.name}] ${e.err}`).join(", ")}`);
|
|
114
|
+
}
|
|
115
|
+
for (const { name, err } of errors) {
|
|
116
|
+
if (backendHints.includes(name)) {
|
|
117
|
+
console.warn(`removing requested execution provider "${name}" from session options because it is not available: ${err}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const filteredEps = eps.filter((i) => availableBackendNames.has(typeof i === "string" ? i : i.name));
|
|
121
|
+
return [
|
|
122
|
+
backend,
|
|
123
|
+
new Proxy(options, {
|
|
124
|
+
get: (target, prop) => {
|
|
125
|
+
if (prop === "executionProviders") {
|
|
126
|
+
return filteredEps;
|
|
127
|
+
}
|
|
128
|
+
return Reflect.get(target, prop);
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
];
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/env.js
|
|
135
|
+
init_define_import_meta_env();
|
|
136
|
+
|
|
137
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/env-impl.js
|
|
138
|
+
init_define_import_meta_env();
|
|
139
|
+
|
|
140
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/version.js
|
|
141
|
+
init_define_import_meta_env();
|
|
142
|
+
var version = "1.30.0";
|
|
143
|
+
|
|
144
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/env-impl.js
|
|
145
|
+
var logLevelValue = "warning";
|
|
146
|
+
var env = {
|
|
147
|
+
wasm: {},
|
|
148
|
+
webgl: {},
|
|
149
|
+
webgpu: {},
|
|
150
|
+
versions: { common: version },
|
|
151
|
+
set logLevel(value) {
|
|
152
|
+
if (value === void 0) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (typeof value !== "string" || ["verbose", "info", "warning", "error", "fatal"].indexOf(value) === -1) {
|
|
156
|
+
throw new Error(`Unsupported logging level: ${value}`);
|
|
157
|
+
}
|
|
158
|
+
logLevelValue = value;
|
|
159
|
+
},
|
|
160
|
+
get logLevel() {
|
|
161
|
+
return logLevelValue;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
Object.defineProperty(env, "logLevel", { enumerable: true });
|
|
165
|
+
|
|
166
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/env.js
|
|
167
|
+
var env2 = env;
|
|
168
|
+
|
|
169
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/inference-session.js
|
|
170
|
+
init_define_import_meta_env();
|
|
171
|
+
|
|
172
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/inference-session-impl.js
|
|
173
|
+
init_define_import_meta_env();
|
|
174
|
+
|
|
175
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/tensor.js
|
|
176
|
+
init_define_import_meta_env();
|
|
177
|
+
|
|
178
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/tensor-impl.js
|
|
179
|
+
init_define_import_meta_env();
|
|
180
|
+
|
|
181
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/tensor-conversion-impl.js
|
|
182
|
+
init_define_import_meta_env();
|
|
183
|
+
var tensorToDataURL = (tensor, options) => {
|
|
184
|
+
const canvas = typeof document !== "undefined" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
|
|
185
|
+
canvas.width = tensor.dims[3];
|
|
186
|
+
canvas.height = tensor.dims[2];
|
|
187
|
+
const pixels2DContext = canvas.getContext("2d");
|
|
188
|
+
if (pixels2DContext != null) {
|
|
189
|
+
let width;
|
|
190
|
+
let height;
|
|
191
|
+
if (options?.tensorLayout !== void 0 && options.tensorLayout === "NHWC") {
|
|
192
|
+
width = tensor.dims[2];
|
|
193
|
+
height = tensor.dims[3];
|
|
194
|
+
} else {
|
|
195
|
+
width = tensor.dims[3];
|
|
196
|
+
height = tensor.dims[2];
|
|
197
|
+
}
|
|
198
|
+
const inputformat = options?.format !== void 0 ? options.format : "RGB";
|
|
199
|
+
const norm = options?.norm;
|
|
200
|
+
let normMean;
|
|
201
|
+
let normBias;
|
|
202
|
+
if (norm === void 0 || norm.mean === void 0) {
|
|
203
|
+
normMean = [255, 255, 255, 255];
|
|
204
|
+
} else {
|
|
205
|
+
if (typeof norm.mean === "number") {
|
|
206
|
+
normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
|
|
207
|
+
} else {
|
|
208
|
+
normMean = [norm.mean[0], norm.mean[1], norm.mean[2], 0];
|
|
209
|
+
if (norm.mean[3] !== void 0) {
|
|
210
|
+
normMean[3] = norm.mean[3];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (norm === void 0 || norm.bias === void 0) {
|
|
215
|
+
normBias = [0, 0, 0, 0];
|
|
216
|
+
} else {
|
|
217
|
+
if (typeof norm.bias === "number") {
|
|
218
|
+
normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
|
|
219
|
+
} else {
|
|
220
|
+
normBias = [norm.bias[0], norm.bias[1], norm.bias[2], 0];
|
|
221
|
+
if (norm.bias[3] !== void 0) {
|
|
222
|
+
normBias[3] = norm.bias[3];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const stride = height * width;
|
|
227
|
+
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
|
228
|
+
if (inputformat === "RGBA") {
|
|
229
|
+
rTensorPointer = 0;
|
|
230
|
+
gTensorPointer = stride;
|
|
231
|
+
bTensorPointer = stride * 2;
|
|
232
|
+
aTensorPointer = stride * 3;
|
|
233
|
+
} else if (inputformat === "RGB") {
|
|
234
|
+
rTensorPointer = 0;
|
|
235
|
+
gTensorPointer = stride;
|
|
236
|
+
bTensorPointer = stride * 2;
|
|
237
|
+
} else if (inputformat === "RBG") {
|
|
238
|
+
rTensorPointer = 0;
|
|
239
|
+
bTensorPointer = stride;
|
|
240
|
+
gTensorPointer = stride * 2;
|
|
241
|
+
}
|
|
242
|
+
for (let i = 0; i < height; i++) {
|
|
243
|
+
for (let j2 = 0; j2 < width; j2++) {
|
|
244
|
+
const R = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0];
|
|
245
|
+
const G = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1];
|
|
246
|
+
const B = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2];
|
|
247
|
+
const A2 = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3];
|
|
248
|
+
pixels2DContext.fillStyle = "rgba(" + R + "," + G + "," + B + "," + A2 + ")";
|
|
249
|
+
pixels2DContext.fillRect(j2, i, 1, 1);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if ("toDataURL" in canvas) {
|
|
253
|
+
return canvas.toDataURL();
|
|
254
|
+
} else {
|
|
255
|
+
throw new Error("toDataURL is not supported");
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
throw new Error("Can not access image data");
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
var tensorToImageData = (tensor, options) => {
|
|
262
|
+
const pixels2DContext = typeof document !== "undefined" ? document.createElement("canvas").getContext("2d") : new OffscreenCanvas(1, 1).getContext("2d");
|
|
263
|
+
let image;
|
|
264
|
+
if (pixels2DContext != null) {
|
|
265
|
+
let width;
|
|
266
|
+
let height;
|
|
267
|
+
let channels;
|
|
268
|
+
if (options?.tensorLayout !== void 0 && options.tensorLayout === "NHWC") {
|
|
269
|
+
width = tensor.dims[2];
|
|
270
|
+
height = tensor.dims[1];
|
|
271
|
+
channels = tensor.dims[3];
|
|
272
|
+
} else {
|
|
273
|
+
width = tensor.dims[3];
|
|
274
|
+
height = tensor.dims[2];
|
|
275
|
+
channels = tensor.dims[1];
|
|
276
|
+
}
|
|
277
|
+
const inputformat = options !== void 0 ? options.format !== void 0 ? options.format : "RGB" : "RGB";
|
|
278
|
+
const norm = options?.norm;
|
|
279
|
+
let normMean;
|
|
280
|
+
let normBias;
|
|
281
|
+
if (norm === void 0 || norm.mean === void 0) {
|
|
282
|
+
normMean = [255, 255, 255, 255];
|
|
283
|
+
} else {
|
|
284
|
+
if (typeof norm.mean === "number") {
|
|
285
|
+
normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
|
|
286
|
+
} else {
|
|
287
|
+
normMean = [norm.mean[0], norm.mean[1], norm.mean[2], 255];
|
|
288
|
+
if (norm.mean[3] !== void 0) {
|
|
289
|
+
normMean[3] = norm.mean[3];
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (norm === void 0 || norm.bias === void 0) {
|
|
294
|
+
normBias = [0, 0, 0, 0];
|
|
295
|
+
} else {
|
|
296
|
+
if (typeof norm.bias === "number") {
|
|
297
|
+
normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
|
|
298
|
+
} else {
|
|
299
|
+
normBias = [norm.bias[0], norm.bias[1], norm.bias[2], 0];
|
|
300
|
+
if (norm.bias[3] !== void 0) {
|
|
301
|
+
normBias[3] = norm.bias[3];
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const stride = height * width;
|
|
306
|
+
if (options !== void 0) {
|
|
307
|
+
if (options.format !== void 0 && channels === 4 && options.format !== "RGBA" || channels === 3 && options.format !== "RGB" && options.format !== "BGR") {
|
|
308
|
+
throw new Error("Tensor format doesn't match input tensor dims");
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const step = 4;
|
|
312
|
+
let rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
|
|
313
|
+
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
|
314
|
+
if (inputformat === "RGBA") {
|
|
315
|
+
rTensorPointer = 0;
|
|
316
|
+
gTensorPointer = stride;
|
|
317
|
+
bTensorPointer = stride * 2;
|
|
318
|
+
aTensorPointer = stride * 3;
|
|
319
|
+
} else if (inputformat === "RGB") {
|
|
320
|
+
rTensorPointer = 0;
|
|
321
|
+
gTensorPointer = stride;
|
|
322
|
+
bTensorPointer = stride * 2;
|
|
323
|
+
} else if (inputformat === "RBG") {
|
|
324
|
+
rTensorPointer = 0;
|
|
325
|
+
bTensorPointer = stride;
|
|
326
|
+
gTensorPointer = stride * 2;
|
|
327
|
+
}
|
|
328
|
+
image = pixels2DContext.createImageData(width, height);
|
|
329
|
+
for (let i = 0; i < height * width; rImagePointer += step, gImagePointer += step, bImagePointer += step, aImagePointer += step, i++) {
|
|
330
|
+
image.data[rImagePointer] = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0];
|
|
331
|
+
image.data[gImagePointer] = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1];
|
|
332
|
+
image.data[bImagePointer] = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2];
|
|
333
|
+
image.data[aImagePointer] = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3];
|
|
334
|
+
}
|
|
335
|
+
} else {
|
|
336
|
+
throw new Error("Can not access image data");
|
|
337
|
+
}
|
|
338
|
+
return image;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/tensor-factory-impl.js
|
|
342
|
+
init_define_import_meta_env();
|
|
343
|
+
var bufferToTensor = (buffer, options) => {
|
|
344
|
+
if (buffer === void 0) {
|
|
345
|
+
throw new Error("Image buffer must be defined");
|
|
346
|
+
}
|
|
347
|
+
if (options.height === void 0 || options.width === void 0) {
|
|
348
|
+
throw new Error("Image height and width must be defined");
|
|
349
|
+
}
|
|
350
|
+
if (options.tensorLayout === "NHWC") {
|
|
351
|
+
throw new Error("NHWC Tensor layout is not supported yet");
|
|
352
|
+
}
|
|
353
|
+
const { height, width } = options;
|
|
354
|
+
const norm = options.norm ?? { mean: 255, bias: 0 };
|
|
355
|
+
let normMean;
|
|
356
|
+
let normBias;
|
|
357
|
+
if (typeof norm.mean === "number") {
|
|
358
|
+
normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
|
|
359
|
+
} else {
|
|
360
|
+
normMean = [norm.mean[0], norm.mean[1], norm.mean[2], norm.mean[3] ?? 255];
|
|
361
|
+
}
|
|
362
|
+
if (typeof norm.bias === "number") {
|
|
363
|
+
normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
|
|
364
|
+
} else {
|
|
365
|
+
normBias = [norm.bias[0], norm.bias[1], norm.bias[2], norm.bias[3] ?? 0];
|
|
366
|
+
}
|
|
367
|
+
const inputformat = options.format !== void 0 ? options.format : "RGBA";
|
|
368
|
+
const outputformat = options.tensorFormat !== void 0 ? options.tensorFormat !== void 0 ? options.tensorFormat : "RGB" : "RGB";
|
|
369
|
+
const stride = height * width;
|
|
370
|
+
const float32Data = outputformat === "RGBA" ? new Float32Array(stride * 4) : new Float32Array(stride * 3);
|
|
371
|
+
let step = 4, rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
|
|
372
|
+
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
|
373
|
+
if (inputformat === "RGB") {
|
|
374
|
+
step = 3;
|
|
375
|
+
rImagePointer = 0;
|
|
376
|
+
gImagePointer = 1;
|
|
377
|
+
bImagePointer = 2;
|
|
378
|
+
aImagePointer = -1;
|
|
379
|
+
}
|
|
380
|
+
if (outputformat === "RGBA") {
|
|
381
|
+
aTensorPointer = stride * 3;
|
|
382
|
+
} else if (outputformat === "RBG") {
|
|
383
|
+
rTensorPointer = 0;
|
|
384
|
+
bTensorPointer = stride;
|
|
385
|
+
gTensorPointer = stride * 2;
|
|
386
|
+
} else if (outputformat === "BGR") {
|
|
387
|
+
bTensorPointer = 0;
|
|
388
|
+
gTensorPointer = stride;
|
|
389
|
+
rTensorPointer = stride * 2;
|
|
390
|
+
}
|
|
391
|
+
for (let i = 0; i < stride; i++, rImagePointer += step, bImagePointer += step, gImagePointer += step, aImagePointer += step) {
|
|
392
|
+
float32Data[rTensorPointer++] = (buffer[rImagePointer] + normBias[0]) / normMean[0];
|
|
393
|
+
float32Data[gTensorPointer++] = (buffer[gImagePointer] + normBias[1]) / normMean[1];
|
|
394
|
+
float32Data[bTensorPointer++] = (buffer[bImagePointer] + normBias[2]) / normMean[2];
|
|
395
|
+
if (aTensorPointer !== -1 && aImagePointer !== -1) {
|
|
396
|
+
float32Data[aTensorPointer++] = (buffer[aImagePointer] + normBias[3]) / normMean[3];
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const outputTensor = outputformat === "RGBA" ? new Tensor("float32", float32Data, [1, 4, height, width]) : new Tensor("float32", float32Data, [1, 3, height, width]);
|
|
400
|
+
return outputTensor;
|
|
401
|
+
};
|
|
402
|
+
var tensorFromImage = async (image, options) => {
|
|
403
|
+
const isHTMLImageEle = typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement;
|
|
404
|
+
const isImageDataEle = typeof ImageData !== "undefined" && image instanceof ImageData;
|
|
405
|
+
const isImageBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
|
|
406
|
+
const isString = typeof image === "string";
|
|
407
|
+
let data;
|
|
408
|
+
let bufferToTensorOptions = options ?? {};
|
|
409
|
+
const createCanvas = () => {
|
|
410
|
+
if (typeof document !== "undefined") {
|
|
411
|
+
return document.createElement("canvas");
|
|
412
|
+
} else if (typeof OffscreenCanvas !== "undefined") {
|
|
413
|
+
return new OffscreenCanvas(1, 1);
|
|
414
|
+
} else {
|
|
415
|
+
throw new Error("Canvas is not supported");
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
const createCanvasContext = (canvas) => {
|
|
419
|
+
if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
|
|
420
|
+
return canvas.getContext("2d");
|
|
421
|
+
} else if (canvas instanceof OffscreenCanvas) {
|
|
422
|
+
return canvas.getContext("2d");
|
|
423
|
+
} else {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
if (isHTMLImageEle) {
|
|
428
|
+
const canvas = createCanvas();
|
|
429
|
+
canvas.width = image.width;
|
|
430
|
+
canvas.height = image.height;
|
|
431
|
+
const pixels2DContext = createCanvasContext(canvas);
|
|
432
|
+
if (pixels2DContext != null) {
|
|
433
|
+
let height = image.height;
|
|
434
|
+
let width = image.width;
|
|
435
|
+
if (options !== void 0 && options.resizedHeight !== void 0 && options.resizedWidth !== void 0) {
|
|
436
|
+
height = options.resizedHeight;
|
|
437
|
+
width = options.resizedWidth;
|
|
438
|
+
}
|
|
439
|
+
if (options !== void 0) {
|
|
440
|
+
bufferToTensorOptions = options;
|
|
441
|
+
if (options.tensorFormat !== void 0) {
|
|
442
|
+
throw new Error("Image input config format must be RGBA for HTMLImageElement");
|
|
443
|
+
} else {
|
|
444
|
+
bufferToTensorOptions.tensorFormat = "RGBA";
|
|
445
|
+
}
|
|
446
|
+
bufferToTensorOptions.height = height;
|
|
447
|
+
bufferToTensorOptions.width = width;
|
|
448
|
+
} else {
|
|
449
|
+
bufferToTensorOptions.tensorFormat = "RGBA";
|
|
450
|
+
bufferToTensorOptions.height = height;
|
|
451
|
+
bufferToTensorOptions.width = width;
|
|
452
|
+
}
|
|
453
|
+
pixels2DContext.drawImage(image, 0, 0);
|
|
454
|
+
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
|
455
|
+
} else {
|
|
456
|
+
throw new Error("Can not access image data");
|
|
457
|
+
}
|
|
458
|
+
} else if (isImageDataEle) {
|
|
459
|
+
let height;
|
|
460
|
+
let width;
|
|
461
|
+
if (options !== void 0 && options.resizedWidth !== void 0 && options.resizedHeight !== void 0) {
|
|
462
|
+
height = options.resizedHeight;
|
|
463
|
+
width = options.resizedWidth;
|
|
464
|
+
} else {
|
|
465
|
+
height = image.height;
|
|
466
|
+
width = image.width;
|
|
467
|
+
}
|
|
468
|
+
if (options !== void 0) {
|
|
469
|
+
bufferToTensorOptions = options;
|
|
470
|
+
}
|
|
471
|
+
bufferToTensorOptions.format = "RGBA";
|
|
472
|
+
bufferToTensorOptions.height = height;
|
|
473
|
+
bufferToTensorOptions.width = width;
|
|
474
|
+
if (options !== void 0) {
|
|
475
|
+
const tempCanvas = createCanvas();
|
|
476
|
+
tempCanvas.width = width;
|
|
477
|
+
tempCanvas.height = height;
|
|
478
|
+
const pixels2DContext = createCanvasContext(tempCanvas);
|
|
479
|
+
if (pixels2DContext != null) {
|
|
480
|
+
pixels2DContext.putImageData(image, 0, 0);
|
|
481
|
+
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
|
482
|
+
} else {
|
|
483
|
+
throw new Error("Can not access image data");
|
|
484
|
+
}
|
|
485
|
+
} else {
|
|
486
|
+
data = image.data;
|
|
487
|
+
}
|
|
488
|
+
} else if (isImageBitmap) {
|
|
489
|
+
if (options === void 0) {
|
|
490
|
+
throw new Error("Please provide image config with format for Imagebitmap");
|
|
491
|
+
}
|
|
492
|
+
const canvas = createCanvas();
|
|
493
|
+
canvas.width = image.width;
|
|
494
|
+
canvas.height = image.height;
|
|
495
|
+
const pixels2DContext = createCanvasContext(canvas);
|
|
496
|
+
if (pixels2DContext != null) {
|
|
497
|
+
const height = image.height;
|
|
498
|
+
const width = image.width;
|
|
499
|
+
pixels2DContext.drawImage(image, 0, 0, width, height);
|
|
500
|
+
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
|
501
|
+
bufferToTensorOptions.height = height;
|
|
502
|
+
bufferToTensorOptions.width = width;
|
|
503
|
+
return bufferToTensor(data, bufferToTensorOptions);
|
|
504
|
+
} else {
|
|
505
|
+
throw new Error("Can not access image data");
|
|
506
|
+
}
|
|
507
|
+
} else if (isString) {
|
|
508
|
+
return new Promise((resolve, reject) => {
|
|
509
|
+
const canvas = createCanvas();
|
|
510
|
+
const context = createCanvasContext(canvas);
|
|
511
|
+
if (!image || !context) {
|
|
512
|
+
return reject();
|
|
513
|
+
}
|
|
514
|
+
const newImage = new Image();
|
|
515
|
+
newImage.crossOrigin = "Anonymous";
|
|
516
|
+
newImage.src = image;
|
|
517
|
+
newImage.onload = () => {
|
|
518
|
+
canvas.width = newImage.width;
|
|
519
|
+
canvas.height = newImage.height;
|
|
520
|
+
context.drawImage(newImage, 0, 0, canvas.width, canvas.height);
|
|
521
|
+
const img = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
522
|
+
bufferToTensorOptions.height = canvas.height;
|
|
523
|
+
bufferToTensorOptions.width = canvas.width;
|
|
524
|
+
resolve(bufferToTensor(img.data, bufferToTensorOptions));
|
|
525
|
+
};
|
|
526
|
+
});
|
|
527
|
+
} else {
|
|
528
|
+
throw new Error("Input data provided is not supported - aborted tensor creation");
|
|
529
|
+
}
|
|
530
|
+
if (data !== void 0) {
|
|
531
|
+
return bufferToTensor(data, bufferToTensorOptions);
|
|
532
|
+
} else {
|
|
533
|
+
throw new Error("Input data provided is not supported - aborted tensor creation");
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
var tensorFromTexture = (texture, options) => {
|
|
537
|
+
const { width, height, download, dispose } = options;
|
|
538
|
+
const dims = [1, height, width, 4];
|
|
539
|
+
return new Tensor({ location: "texture", type: "float32", texture, dims, download, dispose });
|
|
540
|
+
};
|
|
541
|
+
var tensorFromGpuBuffer = (gpuBuffer, options) => {
|
|
542
|
+
const { dataType, dims, download, dispose } = options;
|
|
543
|
+
return new Tensor({ location: "gpu-buffer", type: dataType ?? "float32", gpuBuffer, dims, download, dispose });
|
|
544
|
+
};
|
|
545
|
+
var tensorFromMLTensor = (mlTensor, options) => {
|
|
546
|
+
const { dataType, dims, download, dispose } = options;
|
|
547
|
+
return new Tensor({ location: "ml-tensor", type: dataType ?? "float32", mlTensor, dims, download, dispose });
|
|
548
|
+
};
|
|
549
|
+
var tensorFromPinnedBuffer = (type, buffer, dims) => new Tensor({ location: "cpu-pinned", type, data: buffer, dims: dims ?? [buffer.length] });
|
|
550
|
+
|
|
551
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/tensor-impl-type-mapping.js
|
|
552
|
+
init_define_import_meta_env();
|
|
553
|
+
var NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP = /* @__PURE__ */ new Map([
|
|
554
|
+
["float32", Float32Array],
|
|
555
|
+
["uint8", Uint8Array],
|
|
556
|
+
["int8", Int8Array],
|
|
557
|
+
["uint16", Uint16Array],
|
|
558
|
+
["int16", Int16Array],
|
|
559
|
+
["int32", Int32Array],
|
|
560
|
+
["bool", Uint8Array],
|
|
561
|
+
["float64", Float64Array],
|
|
562
|
+
["uint32", Uint32Array],
|
|
563
|
+
["int4", Uint8Array],
|
|
564
|
+
["uint4", Uint8Array]
|
|
565
|
+
]);
|
|
566
|
+
var NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP = /* @__PURE__ */ new Map([
|
|
567
|
+
[Float32Array, "float32"],
|
|
568
|
+
[Uint8Array, "uint8"],
|
|
569
|
+
[Int8Array, "int8"],
|
|
570
|
+
[Uint16Array, "uint16"],
|
|
571
|
+
[Int16Array, "int16"],
|
|
572
|
+
[Int32Array, "int32"],
|
|
573
|
+
[Float64Array, "float64"],
|
|
574
|
+
[Uint32Array, "uint32"]
|
|
575
|
+
]);
|
|
576
|
+
var isTypedArrayChecked = false;
|
|
577
|
+
var checkTypedArray = () => {
|
|
578
|
+
if (!isTypedArrayChecked) {
|
|
579
|
+
isTypedArrayChecked = true;
|
|
580
|
+
const isBigInt64ArrayAvailable = typeof BigInt64Array !== "undefined" && BigInt64Array.from;
|
|
581
|
+
const isBigUint64ArrayAvailable = typeof BigUint64Array !== "undefined" && BigUint64Array.from;
|
|
582
|
+
const Float16Array2 = globalThis.Float16Array;
|
|
583
|
+
const isFloat16ArrayAvailable = typeof Float16Array2 !== "undefined" && Float16Array2.from;
|
|
584
|
+
if (isBigInt64ArrayAvailable) {
|
|
585
|
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("int64", BigInt64Array);
|
|
586
|
+
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigInt64Array, "int64");
|
|
587
|
+
}
|
|
588
|
+
if (isBigUint64ArrayAvailable) {
|
|
589
|
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("uint64", BigUint64Array);
|
|
590
|
+
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigUint64Array, "uint64");
|
|
591
|
+
}
|
|
592
|
+
if (isFloat16ArrayAvailable) {
|
|
593
|
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Float16Array2);
|
|
594
|
+
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(Float16Array2, "float16");
|
|
595
|
+
} else {
|
|
596
|
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Uint16Array);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/tensor-utils-impl.js
|
|
602
|
+
init_define_import_meta_env();
|
|
603
|
+
var calculateSize = (dims) => {
|
|
604
|
+
let size = 1;
|
|
605
|
+
for (let i = 0; i < dims.length; i++) {
|
|
606
|
+
const dim = dims[i];
|
|
607
|
+
if (typeof dim !== "number" || !Number.isSafeInteger(dim)) {
|
|
608
|
+
throw new TypeError(`dims[${i}] must be an integer, got: ${dim}`);
|
|
609
|
+
}
|
|
610
|
+
if (dim < 0) {
|
|
611
|
+
throw new RangeError(`dims[${i}] must be a non-negative integer, got: ${dim}`);
|
|
612
|
+
}
|
|
613
|
+
size *= dim;
|
|
614
|
+
}
|
|
615
|
+
return size;
|
|
616
|
+
};
|
|
617
|
+
var tensorReshape = (tensor, dims) => {
|
|
618
|
+
switch (tensor.location) {
|
|
619
|
+
case "cpu":
|
|
620
|
+
return new Tensor(tensor.type, tensor.data, dims);
|
|
621
|
+
case "cpu-pinned":
|
|
622
|
+
return new Tensor({
|
|
623
|
+
location: "cpu-pinned",
|
|
624
|
+
data: tensor.data,
|
|
625
|
+
type: tensor.type,
|
|
626
|
+
dims
|
|
627
|
+
});
|
|
628
|
+
case "texture":
|
|
629
|
+
return new Tensor({
|
|
630
|
+
location: "texture",
|
|
631
|
+
texture: tensor.texture,
|
|
632
|
+
type: tensor.type,
|
|
633
|
+
dims
|
|
634
|
+
});
|
|
635
|
+
case "gpu-buffer":
|
|
636
|
+
return new Tensor({
|
|
637
|
+
location: "gpu-buffer",
|
|
638
|
+
gpuBuffer: tensor.gpuBuffer,
|
|
639
|
+
type: tensor.type,
|
|
640
|
+
dims
|
|
641
|
+
});
|
|
642
|
+
case "ml-tensor":
|
|
643
|
+
return new Tensor({
|
|
644
|
+
location: "ml-tensor",
|
|
645
|
+
mlTensor: tensor.mlTensor,
|
|
646
|
+
type: tensor.type,
|
|
647
|
+
dims
|
|
648
|
+
});
|
|
649
|
+
default:
|
|
650
|
+
throw new Error(`tensorReshape: tensor location ${tensor.location} is not supported`);
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/tensor-impl.js
|
|
655
|
+
var Tensor = class {
|
|
656
|
+
/**
|
|
657
|
+
* implementation.
|
|
658
|
+
*/
|
|
659
|
+
constructor(arg0, arg1, arg2) {
|
|
660
|
+
checkTypedArray();
|
|
661
|
+
let type;
|
|
662
|
+
let dims;
|
|
663
|
+
if (typeof arg0 === "object" && "location" in arg0) {
|
|
664
|
+
this.dataLocation = arg0.location;
|
|
665
|
+
type = arg0.type;
|
|
666
|
+
dims = arg0.dims;
|
|
667
|
+
switch (arg0.location) {
|
|
668
|
+
case "cpu-pinned": {
|
|
669
|
+
const expectedTypedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(type);
|
|
670
|
+
if (!expectedTypedArrayConstructor) {
|
|
671
|
+
throw new TypeError(`unsupported type "${type}" to create tensor from pinned buffer`);
|
|
672
|
+
}
|
|
673
|
+
if (!(arg0.data instanceof expectedTypedArrayConstructor)) {
|
|
674
|
+
throw new TypeError(`buffer should be of type ${expectedTypedArrayConstructor.name}`);
|
|
675
|
+
}
|
|
676
|
+
this.cpuData = arg0.data;
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
case "texture": {
|
|
680
|
+
if (type !== "float32") {
|
|
681
|
+
throw new TypeError(`unsupported type "${type}" to create tensor from texture`);
|
|
682
|
+
}
|
|
683
|
+
this.gpuTextureData = arg0.texture;
|
|
684
|
+
this.downloader = arg0.download;
|
|
685
|
+
this.disposer = arg0.dispose;
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
case "gpu-buffer": {
|
|
689
|
+
if (type !== "float32" && type !== "float16" && type !== "int32" && type !== "int64" && type !== "uint32" && type !== "uint8" && type !== "bool" && type !== "uint4" && type !== "int4") {
|
|
690
|
+
throw new TypeError(`unsupported type "${type}" to create tensor from gpu buffer`);
|
|
691
|
+
}
|
|
692
|
+
this.gpuBufferData = arg0.gpuBuffer;
|
|
693
|
+
this.downloader = arg0.download;
|
|
694
|
+
this.disposer = arg0.dispose;
|
|
695
|
+
break;
|
|
696
|
+
}
|
|
697
|
+
case "ml-tensor": {
|
|
698
|
+
if (type !== "float32" && type !== "float16" && type !== "int32" && type !== "int64" && type !== "uint32" && type !== "uint64" && type !== "int8" && type !== "uint8" && type !== "bool" && type !== "uint4" && type !== "int4") {
|
|
699
|
+
throw new TypeError(`unsupported type "${type}" to create tensor from MLTensor`);
|
|
700
|
+
}
|
|
701
|
+
this.mlTensorData = arg0.mlTensor;
|
|
702
|
+
this.downloader = arg0.download;
|
|
703
|
+
this.disposer = arg0.dispose;
|
|
704
|
+
break;
|
|
705
|
+
}
|
|
706
|
+
default:
|
|
707
|
+
throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`);
|
|
708
|
+
}
|
|
709
|
+
} else {
|
|
710
|
+
let data;
|
|
711
|
+
let maybeDims;
|
|
712
|
+
if (typeof arg0 === "string") {
|
|
713
|
+
type = arg0;
|
|
714
|
+
maybeDims = arg2;
|
|
715
|
+
if (arg0 === "string") {
|
|
716
|
+
if (!Array.isArray(arg1)) {
|
|
717
|
+
throw new TypeError("A string tensor's data must be a string array.");
|
|
718
|
+
}
|
|
719
|
+
data = arg1;
|
|
720
|
+
} else {
|
|
721
|
+
const typedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(arg0);
|
|
722
|
+
if (typedArrayConstructor === void 0) {
|
|
723
|
+
throw new TypeError(`Unsupported tensor type: ${arg0}.`);
|
|
724
|
+
}
|
|
725
|
+
if (Array.isArray(arg1)) {
|
|
726
|
+
if (arg0 === "float16" && typedArrayConstructor === Uint16Array || arg0 === "uint4" || arg0 === "int4") {
|
|
727
|
+
throw new TypeError(`Creating a ${arg0} tensor from number array is not supported. Please use ${typedArrayConstructor.name} as data.`);
|
|
728
|
+
} else if (arg0 === "uint64" || arg0 === "int64") {
|
|
729
|
+
data = typedArrayConstructor.from(arg1, BigInt);
|
|
730
|
+
} else {
|
|
731
|
+
data = typedArrayConstructor.from(arg1);
|
|
732
|
+
}
|
|
733
|
+
} else if (arg1 instanceof typedArrayConstructor) {
|
|
734
|
+
data = arg1;
|
|
735
|
+
} else if (arg1 instanceof Uint8ClampedArray) {
|
|
736
|
+
if (arg0 === "uint8") {
|
|
737
|
+
data = Uint8Array.from(arg1);
|
|
738
|
+
} else {
|
|
739
|
+
throw new TypeError(`A Uint8ClampedArray tensor's data must be type of uint8`);
|
|
740
|
+
}
|
|
741
|
+
} else if (arg0 === "float16" && arg1 instanceof Uint16Array && typedArrayConstructor !== Uint16Array) {
|
|
742
|
+
data = new globalThis.Float16Array(arg1.buffer, arg1.byteOffset, arg1.length);
|
|
743
|
+
} else {
|
|
744
|
+
throw new TypeError(`A ${type} tensor's data must be type of ${typedArrayConstructor}`);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
} else {
|
|
748
|
+
maybeDims = arg1;
|
|
749
|
+
if (Array.isArray(arg0)) {
|
|
750
|
+
if (arg0.length === 0) {
|
|
751
|
+
throw new TypeError("Tensor type cannot be inferred from an empty array.");
|
|
752
|
+
}
|
|
753
|
+
const firstElementType = typeof arg0[0];
|
|
754
|
+
if (firstElementType === "string") {
|
|
755
|
+
type = "string";
|
|
756
|
+
data = arg0;
|
|
757
|
+
} else if (firstElementType === "boolean") {
|
|
758
|
+
type = "bool";
|
|
759
|
+
data = Uint8Array.from(arg0);
|
|
760
|
+
} else {
|
|
761
|
+
throw new TypeError(`Invalid element type of data array: ${firstElementType}.`);
|
|
762
|
+
}
|
|
763
|
+
} else if (arg0 instanceof Uint8ClampedArray) {
|
|
764
|
+
type = "uint8";
|
|
765
|
+
data = Uint8Array.from(arg0);
|
|
766
|
+
} else {
|
|
767
|
+
const mappedType = NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.get(arg0.constructor);
|
|
768
|
+
if (mappedType === void 0) {
|
|
769
|
+
throw new TypeError(`Unsupported type for tensor data: ${arg0.constructor}.`);
|
|
770
|
+
}
|
|
771
|
+
type = mappedType;
|
|
772
|
+
data = arg0;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
if (maybeDims === void 0) {
|
|
776
|
+
maybeDims = [data.length];
|
|
777
|
+
} else if (!Array.isArray(maybeDims)) {
|
|
778
|
+
throw new TypeError("A tensor's dims must be a number array");
|
|
779
|
+
}
|
|
780
|
+
dims = maybeDims;
|
|
781
|
+
this.cpuData = data;
|
|
782
|
+
this.dataLocation = "cpu";
|
|
783
|
+
}
|
|
784
|
+
const size = calculateSize(dims);
|
|
785
|
+
if (this.cpuData && size !== this.cpuData.length) {
|
|
786
|
+
if ((type === "uint4" || type === "int4") && Math.ceil(size / 2) === this.cpuData.length) {
|
|
787
|
+
} else {
|
|
788
|
+
throw new Error(`Tensor's size(${size}) does not match data length(${this.cpuData.length}).`);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
this.type = type;
|
|
792
|
+
this.dims = dims;
|
|
793
|
+
this.size = size;
|
|
794
|
+
}
|
|
795
|
+
// #endregion
|
|
796
|
+
// #region factory
|
|
797
|
+
static async fromImage(image, options) {
|
|
798
|
+
return tensorFromImage(image, options);
|
|
799
|
+
}
|
|
800
|
+
static fromTexture(texture, options) {
|
|
801
|
+
return tensorFromTexture(texture, options);
|
|
802
|
+
}
|
|
803
|
+
static fromGpuBuffer(gpuBuffer, options) {
|
|
804
|
+
return tensorFromGpuBuffer(gpuBuffer, options);
|
|
805
|
+
}
|
|
806
|
+
static fromMLTensor(mlTensor, options) {
|
|
807
|
+
return tensorFromMLTensor(mlTensor, options);
|
|
808
|
+
}
|
|
809
|
+
static fromPinnedBuffer(type, buffer, dims) {
|
|
810
|
+
return tensorFromPinnedBuffer(type, buffer, dims);
|
|
811
|
+
}
|
|
812
|
+
// #endregion
|
|
813
|
+
// #region conversions
|
|
814
|
+
toDataURL(options) {
|
|
815
|
+
return tensorToDataURL(this, options);
|
|
816
|
+
}
|
|
817
|
+
toImageData(options) {
|
|
818
|
+
return tensorToImageData(this, options);
|
|
819
|
+
}
|
|
820
|
+
// #endregion
|
|
821
|
+
// #region properties
|
|
822
|
+
get data() {
|
|
823
|
+
this.ensureValid();
|
|
824
|
+
if (!this.cpuData) {
|
|
825
|
+
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.");
|
|
826
|
+
}
|
|
827
|
+
return this.cpuData;
|
|
828
|
+
}
|
|
829
|
+
get location() {
|
|
830
|
+
return this.dataLocation;
|
|
831
|
+
}
|
|
832
|
+
get texture() {
|
|
833
|
+
this.ensureValid();
|
|
834
|
+
if (!this.gpuTextureData) {
|
|
835
|
+
throw new Error("The data is not stored as a WebGL texture.");
|
|
836
|
+
}
|
|
837
|
+
return this.gpuTextureData;
|
|
838
|
+
}
|
|
839
|
+
get gpuBuffer() {
|
|
840
|
+
this.ensureValid();
|
|
841
|
+
if (!this.gpuBufferData) {
|
|
842
|
+
throw new Error("The data is not stored as a WebGPU buffer.");
|
|
843
|
+
}
|
|
844
|
+
return this.gpuBufferData;
|
|
845
|
+
}
|
|
846
|
+
get mlTensor() {
|
|
847
|
+
this.ensureValid();
|
|
848
|
+
if (!this.mlTensorData) {
|
|
849
|
+
throw new Error("The data is not stored as a WebNN MLTensor.");
|
|
850
|
+
}
|
|
851
|
+
return this.mlTensorData;
|
|
852
|
+
}
|
|
853
|
+
// #endregion
|
|
854
|
+
// #region methods
|
|
855
|
+
async getData(releaseData) {
|
|
856
|
+
this.ensureValid();
|
|
857
|
+
switch (this.dataLocation) {
|
|
858
|
+
case "cpu":
|
|
859
|
+
case "cpu-pinned":
|
|
860
|
+
return this.data;
|
|
861
|
+
case "texture":
|
|
862
|
+
case "gpu-buffer":
|
|
863
|
+
case "ml-tensor": {
|
|
864
|
+
if (!this.downloader) {
|
|
865
|
+
throw new Error("The current tensor is not created with a specified data downloader.");
|
|
866
|
+
}
|
|
867
|
+
if (this.isDownloading) {
|
|
868
|
+
throw new Error("The current tensor is being downloaded.");
|
|
869
|
+
}
|
|
870
|
+
try {
|
|
871
|
+
this.isDownloading = true;
|
|
872
|
+
const data = await this.downloader();
|
|
873
|
+
this.downloader = void 0;
|
|
874
|
+
this.dataLocation = "cpu";
|
|
875
|
+
this.cpuData = data;
|
|
876
|
+
if (releaseData && this.disposer) {
|
|
877
|
+
this.disposer();
|
|
878
|
+
this.disposer = void 0;
|
|
879
|
+
}
|
|
880
|
+
return data;
|
|
881
|
+
} finally {
|
|
882
|
+
this.isDownloading = false;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
default:
|
|
886
|
+
throw new Error(`cannot get data from location: ${this.dataLocation}`);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
dispose() {
|
|
890
|
+
if (this.isDownloading) {
|
|
891
|
+
throw new Error("The current tensor is being downloaded.");
|
|
892
|
+
}
|
|
893
|
+
if (this.disposer) {
|
|
894
|
+
this.disposer();
|
|
895
|
+
this.disposer = void 0;
|
|
896
|
+
}
|
|
897
|
+
this.cpuData = void 0;
|
|
898
|
+
this.gpuTextureData = void 0;
|
|
899
|
+
this.gpuBufferData = void 0;
|
|
900
|
+
this.mlTensorData = void 0;
|
|
901
|
+
this.downloader = void 0;
|
|
902
|
+
this.isDownloading = void 0;
|
|
903
|
+
this.dataLocation = "none";
|
|
904
|
+
}
|
|
905
|
+
// #endregion
|
|
906
|
+
// #region tensor utilities
|
|
907
|
+
ensureValid() {
|
|
908
|
+
if (this.dataLocation === "none") {
|
|
909
|
+
throw new Error("The tensor is disposed.");
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
reshape(dims) {
|
|
913
|
+
this.ensureValid();
|
|
914
|
+
if (this.downloader || this.disposer) {
|
|
915
|
+
throw new Error("Cannot reshape a tensor that owns GPU resource.");
|
|
916
|
+
}
|
|
917
|
+
return tensorReshape(this, dims);
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/tensor.js
|
|
922
|
+
var Tensor2 = Tensor;
|
|
923
|
+
|
|
924
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/trace.js
|
|
925
|
+
init_define_import_meta_env();
|
|
926
|
+
var TRACE = (deviceType, label) => {
|
|
927
|
+
if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
console.timeStamp(`${deviceType}::ORT::${label}`);
|
|
931
|
+
};
|
|
932
|
+
var TRACE_FUNC = (msg, extraMsg) => {
|
|
933
|
+
const stack = new Error().stack?.split(/\r\n|\r|\n/g) || [];
|
|
934
|
+
let hasTraceFunc = false;
|
|
935
|
+
for (let i = 0; i < stack.length; i++) {
|
|
936
|
+
if (hasTraceFunc && !stack[i].includes("TRACE_FUNC")) {
|
|
937
|
+
let label = `FUNC_${msg}::${stack[i].trim().split(" ")[1]}`;
|
|
938
|
+
if (extraMsg) {
|
|
939
|
+
label += `::${extraMsg}`;
|
|
940
|
+
}
|
|
941
|
+
TRACE("CPU", label);
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
if (stack[i].includes("TRACE_FUNC")) {
|
|
945
|
+
hasTraceFunc = true;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
var TRACE_FUNC_BEGIN = (extraMsg) => {
|
|
950
|
+
if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
TRACE_FUNC("BEGIN", extraMsg);
|
|
954
|
+
};
|
|
955
|
+
var TRACE_FUNC_END = (extraMsg) => {
|
|
956
|
+
if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
TRACE_FUNC("END", extraMsg);
|
|
960
|
+
};
|
|
961
|
+
var TRACE_EVENT_BEGIN = (extraMsg) => {
|
|
962
|
+
if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
console.time(`ORT::${extraMsg}`);
|
|
966
|
+
};
|
|
967
|
+
var TRACE_EVENT_END = (extraMsg) => {
|
|
968
|
+
if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
971
|
+
console.timeEnd(`ORT::${extraMsg}`);
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/inference-session-impl.js
|
|
975
|
+
var InferenceSession = class _InferenceSession {
|
|
976
|
+
constructor(handler) {
|
|
977
|
+
this.handler = handler;
|
|
978
|
+
}
|
|
979
|
+
async run(feeds, arg1, arg2) {
|
|
980
|
+
TRACE_FUNC_BEGIN();
|
|
981
|
+
TRACE_EVENT_BEGIN("InferenceSession.run");
|
|
982
|
+
const fetches = {};
|
|
983
|
+
let options = {};
|
|
984
|
+
if (typeof feeds !== "object" || feeds === null || feeds instanceof Tensor2 || Array.isArray(feeds)) {
|
|
985
|
+
throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");
|
|
986
|
+
}
|
|
987
|
+
let isFetchesEmpty = true;
|
|
988
|
+
if (typeof arg1 === "object") {
|
|
989
|
+
if (arg1 === null) {
|
|
990
|
+
throw new TypeError("Unexpected argument[1]: cannot be null.");
|
|
991
|
+
}
|
|
992
|
+
if (arg1 instanceof Tensor2) {
|
|
993
|
+
throw new TypeError("'fetches' cannot be a Tensor");
|
|
994
|
+
}
|
|
995
|
+
if (Array.isArray(arg1)) {
|
|
996
|
+
if (arg1.length === 0) {
|
|
997
|
+
throw new TypeError("'fetches' cannot be an empty array.");
|
|
998
|
+
}
|
|
999
|
+
isFetchesEmpty = false;
|
|
1000
|
+
for (const name of arg1) {
|
|
1001
|
+
if (typeof name !== "string") {
|
|
1002
|
+
throw new TypeError("'fetches' must be a string array or an object.");
|
|
1003
|
+
}
|
|
1004
|
+
if (this.outputNames.indexOf(name) === -1) {
|
|
1005
|
+
throw new RangeError(`'fetches' contains invalid output name: ${name}.`);
|
|
1006
|
+
}
|
|
1007
|
+
fetches[name] = null;
|
|
1008
|
+
}
|
|
1009
|
+
if (typeof arg2 === "object" && arg2 !== null) {
|
|
1010
|
+
options = arg2;
|
|
1011
|
+
} else if (typeof arg2 !== "undefined") {
|
|
1012
|
+
throw new TypeError("'options' must be an object.");
|
|
1013
|
+
}
|
|
1014
|
+
} else {
|
|
1015
|
+
let isFetches = false;
|
|
1016
|
+
const arg1Keys = Object.getOwnPropertyNames(arg1);
|
|
1017
|
+
for (const name of this.outputNames) {
|
|
1018
|
+
if (arg1Keys.indexOf(name) !== -1) {
|
|
1019
|
+
const v = arg1[name];
|
|
1020
|
+
if (v === null || v instanceof Tensor2) {
|
|
1021
|
+
isFetches = true;
|
|
1022
|
+
isFetchesEmpty = false;
|
|
1023
|
+
fetches[name] = v;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
if (isFetches) {
|
|
1028
|
+
if (typeof arg2 === "object" && arg2 !== null) {
|
|
1029
|
+
options = arg2;
|
|
1030
|
+
} else if (typeof arg2 !== "undefined") {
|
|
1031
|
+
throw new TypeError("'options' must be an object.");
|
|
1032
|
+
}
|
|
1033
|
+
} else {
|
|
1034
|
+
options = arg1;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
} else if (typeof arg1 !== "undefined") {
|
|
1038
|
+
throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");
|
|
1039
|
+
}
|
|
1040
|
+
for (const name of this.inputNames) {
|
|
1041
|
+
if (typeof feeds[name] === "undefined") {
|
|
1042
|
+
throw new Error(`input '${name}' is missing in 'feeds'.`);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (isFetchesEmpty) {
|
|
1046
|
+
for (const name of this.outputNames) {
|
|
1047
|
+
fetches[name] = null;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
const results = await this.handler.run(feeds, fetches, options);
|
|
1051
|
+
const returnValue = {};
|
|
1052
|
+
for (const key in results) {
|
|
1053
|
+
if (Object.hasOwnProperty.call(results, key)) {
|
|
1054
|
+
const result = results[key];
|
|
1055
|
+
if (result instanceof Tensor2) {
|
|
1056
|
+
returnValue[key] = result;
|
|
1057
|
+
} else {
|
|
1058
|
+
returnValue[key] = new Tensor2(result.type, result.data, result.dims);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
TRACE_EVENT_END("InferenceSession.run");
|
|
1063
|
+
TRACE_FUNC_END();
|
|
1064
|
+
return returnValue;
|
|
1065
|
+
}
|
|
1066
|
+
async release() {
|
|
1067
|
+
return this.handler.dispose();
|
|
1068
|
+
}
|
|
1069
|
+
static async create(arg0, arg1, arg2, arg3) {
|
|
1070
|
+
TRACE_FUNC_BEGIN();
|
|
1071
|
+
TRACE_EVENT_BEGIN("InferenceSession.create");
|
|
1072
|
+
let filePathOrUint8Array;
|
|
1073
|
+
let options = {};
|
|
1074
|
+
if (typeof arg0 === "string") {
|
|
1075
|
+
filePathOrUint8Array = arg0;
|
|
1076
|
+
if (typeof arg1 === "object" && arg1 !== null) {
|
|
1077
|
+
options = arg1;
|
|
1078
|
+
} else if (typeof arg1 !== "undefined") {
|
|
1079
|
+
throw new TypeError("'options' must be an object.");
|
|
1080
|
+
}
|
|
1081
|
+
} else if (arg0 instanceof Uint8Array) {
|
|
1082
|
+
filePathOrUint8Array = arg0;
|
|
1083
|
+
if (typeof arg1 === "object" && arg1 !== null) {
|
|
1084
|
+
options = arg1;
|
|
1085
|
+
} else if (typeof arg1 !== "undefined") {
|
|
1086
|
+
throw new TypeError("'options' must be an object.");
|
|
1087
|
+
}
|
|
1088
|
+
} else if (arg0 instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && arg0 instanceof SharedArrayBuffer) {
|
|
1089
|
+
const buffer = arg0;
|
|
1090
|
+
let byteOffset = 0;
|
|
1091
|
+
let byteLength = arg0.byteLength;
|
|
1092
|
+
if (typeof arg1 === "object" && arg1 !== null) {
|
|
1093
|
+
options = arg1;
|
|
1094
|
+
} else if (typeof arg1 === "number") {
|
|
1095
|
+
byteOffset = arg1;
|
|
1096
|
+
if (!Number.isSafeInteger(byteOffset)) {
|
|
1097
|
+
throw new RangeError("'byteOffset' must be an integer.");
|
|
1098
|
+
}
|
|
1099
|
+
if (byteOffset < 0 || byteOffset >= buffer.byteLength) {
|
|
1100
|
+
throw new RangeError(`'byteOffset' is out of range [0, ${buffer.byteLength}).`);
|
|
1101
|
+
}
|
|
1102
|
+
byteLength = arg0.byteLength - byteOffset;
|
|
1103
|
+
if (typeof arg2 === "number") {
|
|
1104
|
+
byteLength = arg2;
|
|
1105
|
+
if (!Number.isSafeInteger(byteLength)) {
|
|
1106
|
+
throw new RangeError("'byteLength' must be an integer.");
|
|
1107
|
+
}
|
|
1108
|
+
if (byteLength <= 0 || byteOffset + byteLength > buffer.byteLength) {
|
|
1109
|
+
throw new RangeError(`'byteLength' is out of range (0, ${buffer.byteLength - byteOffset}].`);
|
|
1110
|
+
}
|
|
1111
|
+
if (typeof arg3 === "object" && arg3 !== null) {
|
|
1112
|
+
options = arg3;
|
|
1113
|
+
} else if (typeof arg3 !== "undefined") {
|
|
1114
|
+
throw new TypeError("'options' must be an object.");
|
|
1115
|
+
}
|
|
1116
|
+
} else if (typeof arg2 !== "undefined") {
|
|
1117
|
+
throw new TypeError("'byteLength' must be a number.");
|
|
1118
|
+
}
|
|
1119
|
+
} else if (typeof arg1 !== "undefined") {
|
|
1120
|
+
throw new TypeError("'options' must be an object.");
|
|
1121
|
+
}
|
|
1122
|
+
filePathOrUint8Array = new Uint8Array(buffer, byteOffset, byteLength);
|
|
1123
|
+
} else {
|
|
1124
|
+
throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");
|
|
1125
|
+
}
|
|
1126
|
+
const [backend, optionsWithValidatedEPs] = await resolveBackendAndExecutionProviders(options);
|
|
1127
|
+
const handler = await backend.createInferenceSessionHandler(filePathOrUint8Array, optionsWithValidatedEPs);
|
|
1128
|
+
TRACE_EVENT_END("InferenceSession.create");
|
|
1129
|
+
TRACE_FUNC_END();
|
|
1130
|
+
return new _InferenceSession(handler);
|
|
1131
|
+
}
|
|
1132
|
+
startProfiling() {
|
|
1133
|
+
this.handler.startProfiling();
|
|
1134
|
+
}
|
|
1135
|
+
endProfiling() {
|
|
1136
|
+
this.handler.endProfiling();
|
|
1137
|
+
}
|
|
1138
|
+
get inputNames() {
|
|
1139
|
+
return this.handler.inputNames;
|
|
1140
|
+
}
|
|
1141
|
+
get outputNames() {
|
|
1142
|
+
return this.handler.outputNames;
|
|
1143
|
+
}
|
|
1144
|
+
get inputMetadata() {
|
|
1145
|
+
return this.handler.inputMetadata;
|
|
1146
|
+
}
|
|
1147
|
+
get outputMetadata() {
|
|
1148
|
+
return this.handler.outputMetadata;
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/inference-session.js
|
|
1153
|
+
var InferenceSession2 = InferenceSession;
|
|
1154
|
+
|
|
1155
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/tensor-conversion.js
|
|
1156
|
+
init_define_import_meta_env();
|
|
1157
|
+
|
|
1158
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/tensor-factory.js
|
|
1159
|
+
init_define_import_meta_env();
|
|
1160
|
+
|
|
1161
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/onnx-model.js
|
|
1162
|
+
init_define_import_meta_env();
|
|
1163
|
+
|
|
1164
|
+
// node_modules/onnxruntime-web/node_modules/onnxruntime-common/dist/esm/onnx-value.js
|
|
1165
|
+
init_define_import_meta_env();
|
|
1166
|
+
|
|
1167
|
+
// node_modules/onnxruntime-web/dist/ort.node.min.mjs
|
|
1168
|
+
var require2 = createRequire(import.meta.url);
|
|
1169
|
+
var pe = Object.defineProperty;
|
|
1170
|
+
var Et = Object.getOwnPropertyDescriptor;
|
|
1171
|
+
var St = Object.getOwnPropertyNames;
|
|
1172
|
+
var ht = Object.prototype.hasOwnProperty;
|
|
1173
|
+
var de = ((e) => typeof require2 < "u" ? require2 : typeof Proxy < "u" ? new Proxy(e, { get: (t, n) => (typeof require2 < "u" ? require2 : t)[n] }) : e)(function(e) {
|
|
1174
|
+
if (typeof require2 < "u") return require2.apply(this, arguments);
|
|
1175
|
+
throw Error('Dynamic require of "' + e + '" is not supported');
|
|
1176
|
+
});
|
|
1177
|
+
var C = (e, t, n) => () => {
|
|
1178
|
+
if (n) throw n[0];
|
|
1179
|
+
try {
|
|
1180
|
+
return e && (t = e(e = 0)), t;
|
|
1181
|
+
} catch (o) {
|
|
1182
|
+
throw n = [o], o;
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
var Ot = (e, t) => {
|
|
1186
|
+
for (var n in t) pe(e, n, { get: t[n], enumerable: true });
|
|
1187
|
+
};
|
|
1188
|
+
var It = (e, t, n, o) => {
|
|
1189
|
+
if (t && typeof t == "object" || typeof t == "function") for (let r of St(t)) !ht.call(e, r) && r !== n && pe(e, r, { get: () => t[r], enumerable: !(o = Et(t, r)) || o.enumerable });
|
|
1190
|
+
return e;
|
|
1191
|
+
};
|
|
1192
|
+
var Tt = (e) => It(pe({}, "__esModule", { value: true }), e);
|
|
1193
|
+
var j;
|
|
1194
|
+
var ne = C(() => {
|
|
1195
|
+
"use strict";
|
|
1196
|
+
j = !!(typeof process < "u" && process.versions && process.versions.node);
|
|
1197
|
+
});
|
|
1198
|
+
var Ae;
|
|
1199
|
+
var Lt;
|
|
1200
|
+
var Bt;
|
|
1201
|
+
var $;
|
|
1202
|
+
var xe;
|
|
1203
|
+
var ve;
|
|
1204
|
+
var _t;
|
|
1205
|
+
var Pt;
|
|
1206
|
+
var Dt;
|
|
1207
|
+
var vt;
|
|
1208
|
+
var Ue;
|
|
1209
|
+
var Ce;
|
|
1210
|
+
var me = C(() => {
|
|
1211
|
+
"use strict";
|
|
1212
|
+
ne();
|
|
1213
|
+
Ae = j || typeof location > "u" ? void 0 : location.origin, Lt = import.meta.url > "file:" && import.meta.url < "file;", Bt = () => {
|
|
1214
|
+
if (!j) {
|
|
1215
|
+
if (Lt) {
|
|
1216
|
+
let e = URL;
|
|
1217
|
+
return new URL(new e("ort.node.min.mjs", import.meta.url).href, Ae).href;
|
|
1218
|
+
}
|
|
1219
|
+
return import.meta.url;
|
|
1220
|
+
}
|
|
1221
|
+
}, $ = Bt(), xe = () => {
|
|
1222
|
+
if ($ && !$.startsWith("blob:")) return $.substring(0, $.lastIndexOf("/") + 1);
|
|
1223
|
+
}, ve = (e, t) => {
|
|
1224
|
+
try {
|
|
1225
|
+
let n = t ?? $;
|
|
1226
|
+
return (n ? new URL(e, n) : new URL(e)).origin === Ae;
|
|
1227
|
+
} catch {
|
|
1228
|
+
return false;
|
|
1229
|
+
}
|
|
1230
|
+
}, _t = (e, t) => {
|
|
1231
|
+
let n = t ?? $;
|
|
1232
|
+
try {
|
|
1233
|
+
return (n ? new URL(e, n) : new URL(e)).href;
|
|
1234
|
+
} catch {
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
}, Pt = (e, t) => `${t ?? "./"}${e}`, Dt = async (e) => {
|
|
1238
|
+
let n = await (await fetch(e, { credentials: "same-origin" })).blob();
|
|
1239
|
+
return URL.createObjectURL(n);
|
|
1240
|
+
}, vt = async (e) => (await import(
|
|
1241
|
+
/*webpackIgnore:true*/
|
|
1242
|
+
/*@vite-ignore*/
|
|
1243
|
+
e
|
|
1244
|
+
)).default, Ue = void 0, Ce = async (e, t, n, o) => {
|
|
1245
|
+
let r = Ue && !(e || t);
|
|
1246
|
+
if (r) if ($) r = ve($) || o && !n;
|
|
1247
|
+
else if (o && !n) r = true;
|
|
1248
|
+
else throw new Error("cannot determine the script source URL.");
|
|
1249
|
+
if (r) return [void 0, Ue];
|
|
1250
|
+
{
|
|
1251
|
+
let a = "ort-wasm-simd-threaded.mjs", s = e ?? _t(a, t), i = !j && n && s && !ve(s, t), u = i ? await Dt(s) : s ?? Pt(a, t);
|
|
1252
|
+
return [i ? u : void 0, await vt(u)];
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
});
|
|
1256
|
+
var be;
|
|
1257
|
+
var we;
|
|
1258
|
+
var oe;
|
|
1259
|
+
var Me;
|
|
1260
|
+
var Ut;
|
|
1261
|
+
var At;
|
|
1262
|
+
var xt;
|
|
1263
|
+
var We;
|
|
1264
|
+
var E;
|
|
1265
|
+
var V = C(() => {
|
|
1266
|
+
"use strict";
|
|
1267
|
+
me();
|
|
1268
|
+
we = false, oe = false, Me = false, Ut = () => {
|
|
1269
|
+
if (typeof SharedArrayBuffer > "u") return false;
|
|
1270
|
+
try {
|
|
1271
|
+
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]));
|
|
1272
|
+
} catch {
|
|
1273
|
+
return false;
|
|
1274
|
+
}
|
|
1275
|
+
}, At = () => {
|
|
1276
|
+
try {
|
|
1277
|
+
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]));
|
|
1278
|
+
} catch {
|
|
1279
|
+
return false;
|
|
1280
|
+
}
|
|
1281
|
+
}, xt = () => {
|
|
1282
|
+
try {
|
|
1283
|
+
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]));
|
|
1284
|
+
} catch {
|
|
1285
|
+
return false;
|
|
1286
|
+
}
|
|
1287
|
+
}, We = async (e) => {
|
|
1288
|
+
if (we) return Promise.resolve();
|
|
1289
|
+
if (oe) throw new Error("multiple calls to 'initializeWebAssembly()' detected.");
|
|
1290
|
+
if (Me) throw new Error("previous call to 'initializeWebAssembly()' failed.");
|
|
1291
|
+
oe = true;
|
|
1292
|
+
let t = e.initTimeout, n = e.numThreads;
|
|
1293
|
+
if (e.simd !== false) {
|
|
1294
|
+
if (e.simd === "relaxed") {
|
|
1295
|
+
if (!xt()) throw new Error("Relaxed WebAssembly SIMD is not supported in the current environment.");
|
|
1296
|
+
} else if (!At()) throw new Error("WebAssembly SIMD is not supported in the current environment.");
|
|
1297
|
+
}
|
|
1298
|
+
let o = Ut();
|
|
1299
|
+
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);
|
|
1300
|
+
let r = e.wasmPaths, a = typeof r == "string" ? r : void 0, s = r?.mjs, i = s?.href ?? s, u = r?.wasm, l = u?.href ?? u, w = e.wasmBinary, [f, c] = await Ce(i, a, n > 1, !!w || !!l), p = false, S = [];
|
|
1301
|
+
if (t > 0 && S.push(new Promise((h) => {
|
|
1302
|
+
setTimeout(() => {
|
|
1303
|
+
p = true, h();
|
|
1304
|
+
}, t);
|
|
1305
|
+
})), S.push(new Promise((h, P) => {
|
|
1306
|
+
let m = { numThreads: n };
|
|
1307
|
+
if (w) m.wasmBinary = w, m.locateFile = (b) => b;
|
|
1308
|
+
else if (l || a) m.locateFile = (b) => l ?? a + b;
|
|
1309
|
+
else if (i && i.indexOf("blob:") !== 0) m.locateFile = (b) => new URL(b, i).href;
|
|
1310
|
+
else if (f) {
|
|
1311
|
+
let b = xe();
|
|
1312
|
+
b && (m.locateFile = (M) => b + M);
|
|
1313
|
+
}
|
|
1314
|
+
c(m).then((b) => {
|
|
1315
|
+
oe = false, we = true, be = b, h(), f && URL.revokeObjectURL(f);
|
|
1316
|
+
}, (b) => {
|
|
1317
|
+
oe = false, Me = true, P(b);
|
|
1318
|
+
});
|
|
1319
|
+
})), await Promise.race(S), p) throw new Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`);
|
|
1320
|
+
}, E = () => {
|
|
1321
|
+
if (we && be) return be;
|
|
1322
|
+
throw new Error("WebAssembly is not initialized yet.");
|
|
1323
|
+
};
|
|
1324
|
+
});
|
|
1325
|
+
var A;
|
|
1326
|
+
var Q;
|
|
1327
|
+
var g;
|
|
1328
|
+
var se = C(() => {
|
|
1329
|
+
"use strict";
|
|
1330
|
+
V();
|
|
1331
|
+
A = (e, t) => {
|
|
1332
|
+
let n = E(), o = n.lengthBytesUTF8(e) + 1, r = n._malloc(o);
|
|
1333
|
+
return n.stringToUTF8(e, r, o), t.push(r), r;
|
|
1334
|
+
}, Q = (e, t, n, o) => {
|
|
1335
|
+
if (typeof e == "object" && e !== null) {
|
|
1336
|
+
if (n.has(e)) throw new Error("Circular reference in options");
|
|
1337
|
+
n.add(e);
|
|
1338
|
+
}
|
|
1339
|
+
Object.entries(e).forEach(([r, a]) => {
|
|
1340
|
+
let s = t ? t + r : r;
|
|
1341
|
+
if (typeof a == "object") Q(a, s + ".", n, o);
|
|
1342
|
+
else if (typeof a == "string" || typeof a == "number") o(s, a.toString());
|
|
1343
|
+
else if (typeof a == "boolean") o(s, a ? "1" : "0");
|
|
1344
|
+
else throw new Error(`Can't handle extra config type: ${typeof a}`);
|
|
1345
|
+
});
|
|
1346
|
+
}, g = (e) => {
|
|
1347
|
+
let t = E(), n = t.stackSave();
|
|
1348
|
+
try {
|
|
1349
|
+
let o = t.PTR_SIZE, r = t.stackAlloc(2 * o);
|
|
1350
|
+
t._OrtGetLastError(r, r + o);
|
|
1351
|
+
let a = Number(t.getValue(r, o === 4 ? "i32" : "i64")), s = t.getValue(r + o, "*"), i = s ? t.UTF8ToString(s) : "";
|
|
1352
|
+
throw new Error(`${e} ERROR_CODE: ${a}, ERROR_MESSAGE: ${i}`);
|
|
1353
|
+
} finally {
|
|
1354
|
+
t.stackRestore(n);
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
});
|
|
1358
|
+
var ke;
|
|
1359
|
+
var Fe = C(() => {
|
|
1360
|
+
"use strict";
|
|
1361
|
+
V();
|
|
1362
|
+
se();
|
|
1363
|
+
ke = (e) => {
|
|
1364
|
+
let t = E(), n = 0, o = [], r = e || {};
|
|
1365
|
+
try {
|
|
1366
|
+
if (e?.logSeverityLevel === void 0) r.logSeverityLevel = 2;
|
|
1367
|
+
else if (typeof e.logSeverityLevel != "number" || !Number.isInteger(e.logSeverityLevel) || e.logSeverityLevel < 0 || e.logSeverityLevel > 4) throw new Error(`log severity level is not valid: ${e.logSeverityLevel}`);
|
|
1368
|
+
if (e?.logVerbosityLevel === void 0) r.logVerbosityLevel = 0;
|
|
1369
|
+
else if (typeof e.logVerbosityLevel != "number" || !Number.isInteger(e.logVerbosityLevel)) throw new Error(`log verbosity level is not valid: ${e.logVerbosityLevel}`);
|
|
1370
|
+
e?.terminate === void 0 && (r.terminate = false);
|
|
1371
|
+
let a = 0;
|
|
1372
|
+
return e?.tag !== void 0 && (a = A(e.tag, o)), n = t._OrtCreateRunOptions(r.logSeverityLevel, r.logVerbosityLevel, !!r.terminate, a), n === 0 && g("Can't create run options."), e?.extra !== void 0 && Q(e.extra, "", /* @__PURE__ */ new WeakSet(), (s, i) => {
|
|
1373
|
+
let u = A(s, o), l = A(i, o);
|
|
1374
|
+
t._OrtAddRunConfigEntry(n, u, l) !== 0 && g(`Can't set a run config entry: ${s} - ${i}.`);
|
|
1375
|
+
}), [n, o];
|
|
1376
|
+
} catch (a) {
|
|
1377
|
+
throw n !== 0 && t._OrtReleaseRunOptions(n), o.forEach((s) => t._free(s)), a;
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
});
|
|
1381
|
+
var Ct;
|
|
1382
|
+
var Mt;
|
|
1383
|
+
var Wt;
|
|
1384
|
+
var q;
|
|
1385
|
+
var kt;
|
|
1386
|
+
var Re;
|
|
1387
|
+
var Ne = C(() => {
|
|
1388
|
+
"use strict";
|
|
1389
|
+
V();
|
|
1390
|
+
se();
|
|
1391
|
+
Ct = (e) => {
|
|
1392
|
+
switch (e) {
|
|
1393
|
+
case "disabled":
|
|
1394
|
+
return 0;
|
|
1395
|
+
case "basic":
|
|
1396
|
+
return 1;
|
|
1397
|
+
case "extended":
|
|
1398
|
+
return 2;
|
|
1399
|
+
case "layout":
|
|
1400
|
+
return 3;
|
|
1401
|
+
case "all":
|
|
1402
|
+
return 99;
|
|
1403
|
+
default:
|
|
1404
|
+
throw new Error(`unsupported graph optimization level: ${e}`);
|
|
1405
|
+
}
|
|
1406
|
+
}, Mt = (e) => {
|
|
1407
|
+
switch (e) {
|
|
1408
|
+
case "sequential":
|
|
1409
|
+
return 0;
|
|
1410
|
+
case "parallel":
|
|
1411
|
+
return 1;
|
|
1412
|
+
default:
|
|
1413
|
+
throw new Error(`unsupported execution mode: ${e}`);
|
|
1414
|
+
}
|
|
1415
|
+
}, Wt = (e) => {
|
|
1416
|
+
e.extra || (e.extra = {}), e.extra.session || (e.extra.session = {});
|
|
1417
|
+
let t = e.extra.session;
|
|
1418
|
+
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 = false);
|
|
1419
|
+
}, q = (e, t, n, o) => {
|
|
1420
|
+
let r = A(t, o), a = A(n, o);
|
|
1421
|
+
E()._OrtAddSessionConfigEntry(e, r, a) !== 0 && g(`Can't set a session config entry: ${t} - ${n}.`);
|
|
1422
|
+
}, kt = async (e, t, n) => {
|
|
1423
|
+
let o = t.executionProviders;
|
|
1424
|
+
for (let r of o) {
|
|
1425
|
+
let a = typeof r == "string" ? r : r.name, s = [];
|
|
1426
|
+
switch (a) {
|
|
1427
|
+
case "webnn":
|
|
1428
|
+
if (a = "WEBNN", q(e, "session.disable_quant_qdq", "1", n), q(e, "session.disable_qdq_constant_folding", "1", n), typeof r != "string") {
|
|
1429
|
+
let c = r?.deviceType;
|
|
1430
|
+
c && q(e, "deviceType", c, n);
|
|
1431
|
+
}
|
|
1432
|
+
break;
|
|
1433
|
+
case "webgpu":
|
|
1434
|
+
if (a = "JS", typeof r != "string") {
|
|
1435
|
+
let f = r;
|
|
1436
|
+
if (f?.preferredLayout) {
|
|
1437
|
+
if (f.preferredLayout !== "NCHW" && f.preferredLayout !== "NHWC") throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${f.preferredLayout}`);
|
|
1438
|
+
q(e, "preferredLayout", f.preferredLayout, n);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
break;
|
|
1442
|
+
case "wasm":
|
|
1443
|
+
case "cpu":
|
|
1444
|
+
continue;
|
|
1445
|
+
default:
|
|
1446
|
+
throw new Error(`not supported execution provider: ${a}`);
|
|
1447
|
+
}
|
|
1448
|
+
let i = A(a, n), u = s.length, l = 0, w = 0;
|
|
1449
|
+
if (u > 0) {
|
|
1450
|
+
l = E()._malloc(u * E().PTR_SIZE), n.push(l), w = E()._malloc(u * E().PTR_SIZE), n.push(w);
|
|
1451
|
+
for (let f = 0; f < u; f++) E().setValue(l + f * E().PTR_SIZE, s[f][0], "*"), E().setValue(w + f * E().PTR_SIZE, s[f][1], "*");
|
|
1452
|
+
}
|
|
1453
|
+
await E()._OrtAppendExecutionProvider(e, i, l, w, u) !== 0 && g(`Can't append execution provider: ${a}.`);
|
|
1454
|
+
}
|
|
1455
|
+
}, Re = async (e) => {
|
|
1456
|
+
let t = E(), n = 0, o = [], r = e || {};
|
|
1457
|
+
Wt(r);
|
|
1458
|
+
try {
|
|
1459
|
+
let a = Ct(r.graphOptimizationLevel ?? "all"), s = Mt(r.executionMode ?? "sequential"), i = typeof r.logId == "string" ? A(r.logId, o) : 0, u = r.logSeverityLevel ?? 2;
|
|
1460
|
+
if (!Number.isInteger(u) || u < 0 || u > 4) throw new Error(`log severity level is not valid: ${u}`);
|
|
1461
|
+
let l = r.logVerbosityLevel ?? 0;
|
|
1462
|
+
if (!Number.isInteger(l) || l < 0 || l > 4) throw new Error(`log verbosity level is not valid: ${l}`);
|
|
1463
|
+
let w = typeof r.optimizedModelFilePath == "string" ? A(r.optimizedModelFilePath, o) : 0;
|
|
1464
|
+
if (n = t._OrtCreateSessionOptions(a, !!r.enableCpuMemArena, !!r.enableMemPattern, s, !!r.enableProfiling, 0, i, u, l, w), n === 0 && g("Can't create session options."), r.executionProviders && await kt(n, r, o), r.enableGraphCapture !== void 0) {
|
|
1465
|
+
if (typeof r.enableGraphCapture != "boolean") throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);
|
|
1466
|
+
q(n, "enableGraphCapture", r.enableGraphCapture.toString(), o);
|
|
1467
|
+
}
|
|
1468
|
+
if (r.freeDimensionOverrides) for (let [f, c] of Object.entries(r.freeDimensionOverrides)) {
|
|
1469
|
+
if (typeof f != "string") throw new Error(`free dimension override name must be a string: ${f}`);
|
|
1470
|
+
if (typeof c != "number" || !Number.isInteger(c) || c < 0) throw new Error(`free dimension override value must be a non-negative integer: ${c}`);
|
|
1471
|
+
let p = A(f, o);
|
|
1472
|
+
t._OrtAddFreeDimensionOverride(n, p, c) !== 0 && g(`Can't set a free dimension override: ${f} - ${c}.`);
|
|
1473
|
+
}
|
|
1474
|
+
return r.extra !== void 0 && Q(r.extra, "", /* @__PURE__ */ new WeakSet(), (f, c) => {
|
|
1475
|
+
q(n, f, c, o);
|
|
1476
|
+
}), [n, o];
|
|
1477
|
+
} catch (a) {
|
|
1478
|
+
throw n !== 0 && t._OrtReleaseSessionOptions(n) !== 0 && g("Can't release session options."), o.forEach((s) => t._free(s)), a;
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
});
|
|
1482
|
+
var J;
|
|
1483
|
+
var ae;
|
|
1484
|
+
var Y;
|
|
1485
|
+
var Ge;
|
|
1486
|
+
var je;
|
|
1487
|
+
var ie;
|
|
1488
|
+
var ue;
|
|
1489
|
+
var $e;
|
|
1490
|
+
var ge = C(() => {
|
|
1491
|
+
"use strict";
|
|
1492
|
+
J = (e) => {
|
|
1493
|
+
switch (e) {
|
|
1494
|
+
case "int8":
|
|
1495
|
+
return 3;
|
|
1496
|
+
case "uint8":
|
|
1497
|
+
return 2;
|
|
1498
|
+
case "bool":
|
|
1499
|
+
return 9;
|
|
1500
|
+
case "int16":
|
|
1501
|
+
return 5;
|
|
1502
|
+
case "uint16":
|
|
1503
|
+
return 4;
|
|
1504
|
+
case "int32":
|
|
1505
|
+
return 6;
|
|
1506
|
+
case "uint32":
|
|
1507
|
+
return 12;
|
|
1508
|
+
case "float16":
|
|
1509
|
+
return 10;
|
|
1510
|
+
case "float32":
|
|
1511
|
+
return 1;
|
|
1512
|
+
case "float64":
|
|
1513
|
+
return 11;
|
|
1514
|
+
case "string":
|
|
1515
|
+
return 8;
|
|
1516
|
+
case "int64":
|
|
1517
|
+
return 7;
|
|
1518
|
+
case "uint64":
|
|
1519
|
+
return 13;
|
|
1520
|
+
case "int4":
|
|
1521
|
+
return 22;
|
|
1522
|
+
case "uint4":
|
|
1523
|
+
return 21;
|
|
1524
|
+
default:
|
|
1525
|
+
throw new Error(`unsupported data type: ${e}`);
|
|
1526
|
+
}
|
|
1527
|
+
}, ae = (e) => {
|
|
1528
|
+
switch (e) {
|
|
1529
|
+
case 3:
|
|
1530
|
+
return "int8";
|
|
1531
|
+
case 2:
|
|
1532
|
+
return "uint8";
|
|
1533
|
+
case 9:
|
|
1534
|
+
return "bool";
|
|
1535
|
+
case 5:
|
|
1536
|
+
return "int16";
|
|
1537
|
+
case 4:
|
|
1538
|
+
return "uint16";
|
|
1539
|
+
case 6:
|
|
1540
|
+
return "int32";
|
|
1541
|
+
case 12:
|
|
1542
|
+
return "uint32";
|
|
1543
|
+
case 10:
|
|
1544
|
+
return "float16";
|
|
1545
|
+
case 1:
|
|
1546
|
+
return "float32";
|
|
1547
|
+
case 11:
|
|
1548
|
+
return "float64";
|
|
1549
|
+
case 8:
|
|
1550
|
+
return "string";
|
|
1551
|
+
case 7:
|
|
1552
|
+
return "int64";
|
|
1553
|
+
case 13:
|
|
1554
|
+
return "uint64";
|
|
1555
|
+
case 22:
|
|
1556
|
+
return "int4";
|
|
1557
|
+
case 21:
|
|
1558
|
+
return "uint4";
|
|
1559
|
+
default:
|
|
1560
|
+
throw new Error(`unsupported data type: ${e}`);
|
|
1561
|
+
}
|
|
1562
|
+
}, Y = (e, t) => {
|
|
1563
|
+
let n = [-1, 4, 1, 1, 2, 2, 4, 8, -1, 1, 2, 8, 4, 8, -1, -1, -1, -1, -1, -1, -1, 0.5, 0.5][e], o = typeof t == "number" ? t : t.reduce((r, a) => r * a, 1);
|
|
1564
|
+
return n > 0 ? Math.ceil(o * n) : void 0;
|
|
1565
|
+
}, Ge = (e) => {
|
|
1566
|
+
switch (e) {
|
|
1567
|
+
case "float16":
|
|
1568
|
+
return typeof Float16Array < "u" ? Float16Array : Uint16Array;
|
|
1569
|
+
case "float32":
|
|
1570
|
+
return Float32Array;
|
|
1571
|
+
case "uint8":
|
|
1572
|
+
return Uint8Array;
|
|
1573
|
+
case "int8":
|
|
1574
|
+
return Int8Array;
|
|
1575
|
+
case "uint16":
|
|
1576
|
+
return Uint16Array;
|
|
1577
|
+
case "int16":
|
|
1578
|
+
return Int16Array;
|
|
1579
|
+
case "int32":
|
|
1580
|
+
return Int32Array;
|
|
1581
|
+
case "bool":
|
|
1582
|
+
return Uint8Array;
|
|
1583
|
+
case "float64":
|
|
1584
|
+
return Float64Array;
|
|
1585
|
+
case "uint32":
|
|
1586
|
+
return Uint32Array;
|
|
1587
|
+
case "int64":
|
|
1588
|
+
return BigInt64Array;
|
|
1589
|
+
case "uint64":
|
|
1590
|
+
return BigUint64Array;
|
|
1591
|
+
default:
|
|
1592
|
+
throw new Error(`unsupported type: ${e}`);
|
|
1593
|
+
}
|
|
1594
|
+
}, je = (e) => {
|
|
1595
|
+
switch (e) {
|
|
1596
|
+
case "verbose":
|
|
1597
|
+
return 0;
|
|
1598
|
+
case "info":
|
|
1599
|
+
return 1;
|
|
1600
|
+
case "warning":
|
|
1601
|
+
return 2;
|
|
1602
|
+
case "error":
|
|
1603
|
+
return 3;
|
|
1604
|
+
case "fatal":
|
|
1605
|
+
return 4;
|
|
1606
|
+
default:
|
|
1607
|
+
throw new Error(`unsupported logging level: ${e}`);
|
|
1608
|
+
}
|
|
1609
|
+
}, ie = (e) => e === "float32" || e === "float16" || e === "int32" || e === "int64" || e === "uint32" || e === "uint8" || e === "bool" || e === "uint4" || e === "int4", ue = (e) => e === "float32" || e === "float16" || e === "int32" || e === "int64" || e === "uint32" || e === "uint64" || e === "int8" || e === "uint8" || e === "bool" || e === "uint4" || e === "int4", $e = (e) => {
|
|
1610
|
+
switch (e) {
|
|
1611
|
+
case "none":
|
|
1612
|
+
return 0;
|
|
1613
|
+
case "cpu":
|
|
1614
|
+
return 1;
|
|
1615
|
+
case "cpu-pinned":
|
|
1616
|
+
return 2;
|
|
1617
|
+
case "texture":
|
|
1618
|
+
return 3;
|
|
1619
|
+
case "gpu-buffer":
|
|
1620
|
+
return 4;
|
|
1621
|
+
case "ml-tensor":
|
|
1622
|
+
return 5;
|
|
1623
|
+
default:
|
|
1624
|
+
throw new Error(`unsupported data location: ${e}`);
|
|
1625
|
+
}
|
|
1626
|
+
};
|
|
1627
|
+
});
|
|
1628
|
+
var ee;
|
|
1629
|
+
var ye = C(() => {
|
|
1630
|
+
"use strict";
|
|
1631
|
+
ne();
|
|
1632
|
+
ee = async (e) => {
|
|
1633
|
+
if (typeof e == "string") if (j) try {
|
|
1634
|
+
let { readFile: t } = de("node:fs/promises");
|
|
1635
|
+
return new Uint8Array(await t(e));
|
|
1636
|
+
} catch (t) {
|
|
1637
|
+
if (t.code === "ERR_FS_FILE_TOO_LARGE") {
|
|
1638
|
+
let { createReadStream: n } = de("node:fs"), o = n(e), r = [];
|
|
1639
|
+
for await (let a of o) r.push(a);
|
|
1640
|
+
return new Uint8Array(Buffer.concat(r));
|
|
1641
|
+
}
|
|
1642
|
+
throw t;
|
|
1643
|
+
}
|
|
1644
|
+
else {
|
|
1645
|
+
let t = await fetch(e);
|
|
1646
|
+
if (!t.ok) throw new Error(`failed to load external data file: ${e}`);
|
|
1647
|
+
let n = t.headers.get("Content-Length"), o = n ? parseInt(n, 10) : 0;
|
|
1648
|
+
if (o < 1073741824) return new Uint8Array(await t.arrayBuffer());
|
|
1649
|
+
{
|
|
1650
|
+
if (!t.body) throw new Error(`failed to load external data file: ${e}, no response body.`);
|
|
1651
|
+
let r = t.body.getReader(), a;
|
|
1652
|
+
try {
|
|
1653
|
+
a = new ArrayBuffer(o);
|
|
1654
|
+
} catch (i) {
|
|
1655
|
+
if (i instanceof RangeError) {
|
|
1656
|
+
let u = Math.ceil(o / 65536);
|
|
1657
|
+
a = new WebAssembly.Memory({ initial: u, maximum: u }).buffer;
|
|
1658
|
+
} else throw i;
|
|
1659
|
+
}
|
|
1660
|
+
let s = 0;
|
|
1661
|
+
for (; ; ) {
|
|
1662
|
+
let { done: i, value: u } = await r.read();
|
|
1663
|
+
if (i) break;
|
|
1664
|
+
let l = u.byteLength;
|
|
1665
|
+
new Uint8Array(a, s, l).set(u), s += l;
|
|
1666
|
+
}
|
|
1667
|
+
return new Uint8Array(a, 0, o);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
else return e instanceof Blob ? new Uint8Array(await e.arrayBuffer()) : e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
1671
|
+
};
|
|
1672
|
+
});
|
|
1673
|
+
var Ft;
|
|
1674
|
+
var Je;
|
|
1675
|
+
var Ye;
|
|
1676
|
+
var Z;
|
|
1677
|
+
var Rt;
|
|
1678
|
+
var Ve;
|
|
1679
|
+
var Ee;
|
|
1680
|
+
var Ze;
|
|
1681
|
+
var Xe;
|
|
1682
|
+
var qe;
|
|
1683
|
+
var Ke;
|
|
1684
|
+
var Qe;
|
|
1685
|
+
var et = C(() => {
|
|
1686
|
+
"use strict";
|
|
1687
|
+
Fe();
|
|
1688
|
+
Ne();
|
|
1689
|
+
ge();
|
|
1690
|
+
V();
|
|
1691
|
+
se();
|
|
1692
|
+
ye();
|
|
1693
|
+
Ft = (e, t) => {
|
|
1694
|
+
E()._OrtInit(e, t) !== 0 && g("Can't initialize onnxruntime.");
|
|
1695
|
+
}, Je = async (e) => {
|
|
1696
|
+
Ft(e.wasm.numThreads, je(e.logLevel));
|
|
1697
|
+
}, Ye = async (e, t) => {
|
|
1698
|
+
E().asyncInit?.();
|
|
1699
|
+
let n = e.webgpu.adapter;
|
|
1700
|
+
if (t === "webgpu") {
|
|
1701
|
+
if (typeof navigator > "u" || !navigator.gpu) throw new Error("WebGPU is not supported in current environment");
|
|
1702
|
+
if (n) {
|
|
1703
|
+
if (typeof n.limits != "object" || typeof n.features != "object" || typeof n.requestDevice != "function") throw new Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.");
|
|
1704
|
+
} else {
|
|
1705
|
+
let o = e.webgpu.powerPreference;
|
|
1706
|
+
if (o !== void 0 && o !== "low-power" && o !== "high-performance") throw new Error(`Invalid powerPreference setting: "${o}"`);
|
|
1707
|
+
let r = e.webgpu.forceFallbackAdapter;
|
|
1708
|
+
if (r !== void 0 && typeof r != "boolean") throw new Error(`Invalid forceFallbackAdapter setting: "${r}"`);
|
|
1709
|
+
if (n = await navigator.gpu.requestAdapter({ powerPreference: o, forceFallbackAdapter: r }), !n) throw new Error('Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.');
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
if (t === "webnn" && (typeof navigator > "u" || !navigator.ml)) throw new Error("WebNN is not supported in current environment");
|
|
1713
|
+
}, Z = /* @__PURE__ */ new Map(), Rt = (e) => {
|
|
1714
|
+
let t = E(), n = t.stackSave();
|
|
1715
|
+
try {
|
|
1716
|
+
let o = t.PTR_SIZE, r = t.stackAlloc(2 * o);
|
|
1717
|
+
t._OrtGetInputOutputCount(e, r, r + o) !== 0 && g("Can't get session input/output count.");
|
|
1718
|
+
let s = o === 4 ? "i32" : "i64";
|
|
1719
|
+
return [Number(t.getValue(r, s)), Number(t.getValue(r + o, s))];
|
|
1720
|
+
} finally {
|
|
1721
|
+
t.stackRestore(n);
|
|
1722
|
+
}
|
|
1723
|
+
}, Ve = (e, t) => {
|
|
1724
|
+
let n = E(), o = n.stackSave(), r = 0;
|
|
1725
|
+
try {
|
|
1726
|
+
let a = n.PTR_SIZE, s = n.stackAlloc(2 * a);
|
|
1727
|
+
n._OrtGetInputOutputMetadata(e, t, s, s + a) !== 0 && g("Can't get session input/output metadata.");
|
|
1728
|
+
let u = Number(n.getValue(s, "*"));
|
|
1729
|
+
r = Number(n.getValue(s + a, "*"));
|
|
1730
|
+
let l = n.HEAP32[r / 4];
|
|
1731
|
+
if (l === 0) return [u, 0];
|
|
1732
|
+
let w = n.HEAPU32[r / 4 + 1], f = [];
|
|
1733
|
+
for (let c = 0; c < w; c++) {
|
|
1734
|
+
let p = Number(n.getValue(r + 8 + c * a, "*"));
|
|
1735
|
+
f.push(p !== 0 ? n.UTF8ToString(p) : Number(n.getValue(r + 8 + (c + w) * a, "*")));
|
|
1736
|
+
}
|
|
1737
|
+
return [u, l, f];
|
|
1738
|
+
} finally {
|
|
1739
|
+
n.stackRestore(o), r !== 0 && n._OrtFree(r);
|
|
1740
|
+
}
|
|
1741
|
+
}, Ee = (e) => {
|
|
1742
|
+
let t = E(), n = t._malloc(e.byteLength);
|
|
1743
|
+
if (n === 0) throw new Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);
|
|
1744
|
+
return t.HEAPU8.set(e, n), [n, e.byteLength];
|
|
1745
|
+
}, Ze = async (e, t) => {
|
|
1746
|
+
let n, o, r = E();
|
|
1747
|
+
Array.isArray(e) ? [n, o] = e : e.buffer === r.HEAPU8.buffer ? [n, o] = [e.byteOffset, e.byteLength] : [n, o] = Ee(e);
|
|
1748
|
+
let a = 0, s = 0, i = 0, u = [], l = [], w = [];
|
|
1749
|
+
try {
|
|
1750
|
+
if ([s, u] = await Re(t), t?.externalData && r.mountExternalData) {
|
|
1751
|
+
let y = [];
|
|
1752
|
+
for (let O of t.externalData) {
|
|
1753
|
+
let _ = typeof O == "string" ? O : O.path, U = typeof O == "string" ? O : O.data;
|
|
1754
|
+
y.push(ee(U).then((L) => {
|
|
1755
|
+
r.mountExternalData(_, L);
|
|
1756
|
+
}));
|
|
1757
|
+
}
|
|
1758
|
+
await Promise.all(y);
|
|
1759
|
+
}
|
|
1760
|
+
for (let y of t?.executionProviders ?? []) if ((typeof y == "string" ? y : y.name) === "webnn") {
|
|
1761
|
+
if (r.shouldTransferToMLTensor = false, typeof y != "string") {
|
|
1762
|
+
let _ = y, U = _?.context, L = _?.gpuDevice, X = _?.deviceType, z = _?.powerPreference;
|
|
1763
|
+
U ? r.currentContext = U : L ? r.currentContext = await r.webnnCreateMLContext(L) : r.currentContext = await r.webnnCreateMLContext({ deviceType: X, powerPreference: z });
|
|
1764
|
+
} else r.currentContext = await r.webnnCreateMLContext();
|
|
1765
|
+
break;
|
|
1766
|
+
}
|
|
1767
|
+
a = await r._OrtCreateSession(n, o, s), r.webgpuOnCreateSession?.(a), a === 0 && g("Can't create a session."), r.jsepOnCreateSession?.(), r.currentContext && (r.webnnRegisterMLContext(a, r.currentContext), r.currentContext = void 0, r.shouldTransferToMLTensor = true);
|
|
1768
|
+
let [f, c] = Rt(a), p = !!t?.enableGraphCapture, S = [], h = [], P = [], m = [], b = [];
|
|
1769
|
+
for (let y = 0; y < f; y++) {
|
|
1770
|
+
let [O, _, U] = Ve(a, y);
|
|
1771
|
+
O === 0 && g("Can't get an input name."), l.push(O);
|
|
1772
|
+
let L = r.UTF8ToString(O);
|
|
1773
|
+
S.push(L), P.push(_ === 0 ? { name: L, isTensor: false } : { name: L, isTensor: true, type: ae(_), shape: U });
|
|
1774
|
+
}
|
|
1775
|
+
for (let y = 0; y < c; y++) {
|
|
1776
|
+
let [O, _, U] = Ve(a, y + f);
|
|
1777
|
+
O === 0 && g("Can't get an output name."), w.push(O);
|
|
1778
|
+
let L = r.UTF8ToString(O);
|
|
1779
|
+
h.push(L), m.push(_ === 0 ? { name: L, isTensor: false } : { name: L, isTensor: true, type: ae(_), shape: U });
|
|
1780
|
+
}
|
|
1781
|
+
return Z.set(a, [a, l, w, null, p, false]), [a, S, h, P, m];
|
|
1782
|
+
} catch (f) {
|
|
1783
|
+
throw l.forEach((c) => r._OrtFree(c)), w.forEach((c) => r._OrtFree(c)), i !== 0 && r._OrtReleaseBinding(i) !== 0 && g("Can't release IO binding."), a !== 0 && r._OrtReleaseSession(a) !== 0 && g("Can't release session."), f;
|
|
1784
|
+
} finally {
|
|
1785
|
+
r._free(n), s !== 0 && r._OrtReleaseSessionOptions(s) !== 0 && g("Can't release session options."), u.forEach((f) => r._free(f)), r.unmountExternalData?.();
|
|
1786
|
+
}
|
|
1787
|
+
}, Xe = (e) => {
|
|
1788
|
+
let t = E(), n = Z.get(e);
|
|
1789
|
+
if (!n) throw new Error(`cannot release session. invalid session id: ${e}`);
|
|
1790
|
+
let [o, r, a, s, i] = n;
|
|
1791
|
+
s && (i && t._OrtClearBoundOutputs(s.handle) !== 0 && g("Can't clear bound outputs."), t._OrtReleaseBinding(s.handle) !== 0 && g("Can't release IO binding.")), t.jsepOnReleaseSession?.(e), t.webnnOnReleaseSession?.(e), t.webgpuOnReleaseSession?.(e), r.forEach((u) => t._OrtFree(u)), a.forEach((u) => t._OrtFree(u)), t._OrtReleaseSession(o) !== 0 && g("Can't release session."), Z.delete(e);
|
|
1792
|
+
}, qe = async (e, t, n, o, r, a, s = false) => {
|
|
1793
|
+
if (!e) {
|
|
1794
|
+
t.push(0);
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
let i = E(), u = i.PTR_SIZE, l = e[0], w = e[1], f = e[3], c = f, p, S;
|
|
1798
|
+
if (l === "string" && (f === "gpu-buffer" || f === "ml-tensor")) throw new Error("String tensor is not supported on GPU.");
|
|
1799
|
+
if (s && f !== "gpu-buffer") throw new Error(`External buffer must be provided for input/output index ${a} when enableGraphCapture is true.`);
|
|
1800
|
+
if (f === "gpu-buffer") {
|
|
1801
|
+
let m = e[2].gpuBuffer;
|
|
1802
|
+
S = Y(J(l), w);
|
|
1803
|
+
{
|
|
1804
|
+
let b = i.jsepRegisterBuffer;
|
|
1805
|
+
if (!b) throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');
|
|
1806
|
+
p = b(o, a, m, S);
|
|
1807
|
+
}
|
|
1808
|
+
} else if (f === "ml-tensor") {
|
|
1809
|
+
let m = e[2].mlTensor;
|
|
1810
|
+
S = Y(J(l), w);
|
|
1811
|
+
let b = i.webnnRegisterMLTensor;
|
|
1812
|
+
if (!b) throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');
|
|
1813
|
+
p = b(o, m, J(l), w);
|
|
1814
|
+
} else {
|
|
1815
|
+
let m = e[2];
|
|
1816
|
+
if (Array.isArray(m)) {
|
|
1817
|
+
S = u * m.length, p = i._malloc(S), n.push(p);
|
|
1818
|
+
for (let b = 0; b < m.length; b++) {
|
|
1819
|
+
if (typeof m[b] != "string") throw new TypeError(`tensor data at index ${b} is not a string`);
|
|
1820
|
+
i.setValue(p + b * u, A(m[b], n), "*");
|
|
1821
|
+
}
|
|
1822
|
+
} else {
|
|
1823
|
+
let b = i.webnnIsGraphInput, M = i.webnnIsGraphOutput;
|
|
1824
|
+
if (l !== "string" && b && M) {
|
|
1825
|
+
let y = i.UTF8ToString(r);
|
|
1826
|
+
if (b(o, y) || M(o, y)) {
|
|
1827
|
+
let O = J(l);
|
|
1828
|
+
S = Y(O, w), c = "ml-tensor";
|
|
1829
|
+
let _ = i.webnnCreateTemporaryTensor, U = i.webnnUploadTensor;
|
|
1830
|
+
if (!_ || !U) throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');
|
|
1831
|
+
let L = await _(o, O, w);
|
|
1832
|
+
U(L, new Uint8Array(m.buffer, m.byteOffset, m.byteLength)), p = L;
|
|
1833
|
+
} else S = m.byteLength, p = i._malloc(S), n.push(p), i.HEAPU8.set(new Uint8Array(m.buffer, m.byteOffset, S), p);
|
|
1834
|
+
} else S = m.byteLength, p = i._malloc(S), n.push(p), i.HEAPU8.set(new Uint8Array(m.buffer, m.byteOffset, S), p);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
let h = i.stackSave(), P = i.stackAlloc(4 * w.length);
|
|
1838
|
+
try {
|
|
1839
|
+
w.forEach((b, M) => i.setValue(P + M * u, b, u === 4 ? "i32" : "i64"));
|
|
1840
|
+
let m = i._OrtCreateTensor(J(l), p, S, P, w.length, $e(c));
|
|
1841
|
+
m === 0 && g(`Can't create tensor for input/output. session=${o}, index=${a}.`), t.push(m);
|
|
1842
|
+
} finally {
|
|
1843
|
+
i.stackRestore(h);
|
|
1844
|
+
}
|
|
1845
|
+
}, Ke = async (e, t, n, o, r, a) => {
|
|
1846
|
+
let s = E(), i = s.PTR_SIZE, u = Z.get(e);
|
|
1847
|
+
if (!u) throw new Error(`cannot run inference. invalid session id: ${e}`);
|
|
1848
|
+
let l = u[0], w = u[1], f = u[2], c = u[3], p = u[4], S = u[5], h = t.length, P = o.length, m = 0, b = [], M = [], y = [], O = [], _ = [], U = s.stackSave(), L = s.stackAlloc(h * i), X = s.stackAlloc(h * i), z = s.stackAlloc(P * i), Te = s.stackAlloc(P * i);
|
|
1849
|
+
try {
|
|
1850
|
+
[m, b] = ke(a), TRACE_EVENT_BEGIN("wasm prepareInputOutputTensor");
|
|
1851
|
+
for (let d = 0; d < h; d++) await qe(n[d], M, O, e, w[t[d]], t[d], p);
|
|
1852
|
+
for (let d = 0; d < P; d++) await qe(r[d], y, O, e, f[o[d]], h + o[d], p);
|
|
1853
|
+
TRACE_EVENT_END("wasm prepareInputOutputTensor");
|
|
1854
|
+
for (let d = 0; d < h; d++) s.setValue(L + d * i, M[d], "*"), s.setValue(X + d * i, w[t[d]], "*");
|
|
1855
|
+
for (let d = 0; d < P; d++) s.setValue(z + d * i, y[d], "*"), s.setValue(Te + d * i, f[o[d]], "*");
|
|
1856
|
+
s.jsepOnRunStart?.(l), s.webnnOnRunStart?.(l);
|
|
1857
|
+
let x;
|
|
1858
|
+
x = await s._OrtRun(l, X, L, h, Te, P, z, m), x !== 0 && g("failed to call OrtRun().");
|
|
1859
|
+
let F = [], Le = [];
|
|
1860
|
+
TRACE_EVENT_BEGIN("wasm ProcessOutputTensor");
|
|
1861
|
+
for (let d = 0; d < P; d++) {
|
|
1862
|
+
let W = Number(s.getValue(z + d * i, "*"));
|
|
1863
|
+
if (W === y[d] || _.includes(y[d])) {
|
|
1864
|
+
F.push(r[d]), W !== y[d] && s._OrtReleaseTensor(W) !== 0 && g("Can't release tensor.");
|
|
1865
|
+
continue;
|
|
1866
|
+
}
|
|
1867
|
+
let Be = s.stackSave(), k = s.stackAlloc(4 * i), H = false, T, D = 0;
|
|
1868
|
+
try {
|
|
1869
|
+
s._OrtGetTensorData(W, k, k + i, k + 2 * i, k + 3 * i) !== 0 && g(`Can't access output tensor data on index ${d}.`);
|
|
1870
|
+
let le = i === 4 ? "i32" : "i64", te = Number(s.getValue(k, le));
|
|
1871
|
+
D = s.getValue(k + i, "*");
|
|
1872
|
+
let _e = s.getValue(k + i * 2, "*"), yt = Number(s.getValue(k + i * 3, le)), R = [];
|
|
1873
|
+
for (let B = 0; B < yt; B++) R.push(Number(s.getValue(_e + B * i, le)));
|
|
1874
|
+
s._OrtFree(_e) !== 0 && g("Can't free memory for tensor dims.");
|
|
1875
|
+
let N = R.reduce((B, I) => B * I, 1);
|
|
1876
|
+
T = ae(te);
|
|
1877
|
+
let K = c?.outputPreferredLocations[o[d]];
|
|
1878
|
+
if (T === "string") {
|
|
1879
|
+
if (K === "gpu-buffer" || K === "ml-tensor") throw new Error("String tensor is not supported on GPU.");
|
|
1880
|
+
let B = [];
|
|
1881
|
+
for (let I = 0; I < N; I++) {
|
|
1882
|
+
let G = s.getValue(D + I * i, "*"), re = s.getValue(D + (I + 1) * i, "*"), Pe = I === N - 1 ? void 0 : re - G;
|
|
1883
|
+
B.push(s.UTF8ToString(G, Pe));
|
|
1884
|
+
}
|
|
1885
|
+
F.push([T, R, B, "cpu"]);
|
|
1886
|
+
} else if (K === "gpu-buffer" && N > 0) {
|
|
1887
|
+
let B = s.jsepGetBuffer;
|
|
1888
|
+
if (!B) throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');
|
|
1889
|
+
let I = B(D), G = Y(te, N);
|
|
1890
|
+
if (G === void 0 || !ie(T)) throw new Error(`Unsupported data type: ${T}`);
|
|
1891
|
+
H = true, F.push([T, R, { gpuBuffer: I, download: s.jsepCreateDownloader(I, G, T), dispose: () => {
|
|
1892
|
+
s._OrtReleaseTensor(W) !== 0 && g("Can't release tensor.");
|
|
1893
|
+
} }, "gpu-buffer"]);
|
|
1894
|
+
} else if (K === "ml-tensor" && N > 0) {
|
|
1895
|
+
let B = s.webnnEnsureTensor, I = s.webnnIsGraphInputOutputTypeSupported;
|
|
1896
|
+
if (!B || !I) throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');
|
|
1897
|
+
if (Y(te, N) === void 0 || !ue(T)) throw new Error(`Unsupported data type: ${T}`);
|
|
1898
|
+
if (!I(e, T, false)) throw new Error(`preferredLocation "ml-tensor" for ${T} output is not supported by current WebNN Context.`);
|
|
1899
|
+
let re = await B(e, D, te, R, false);
|
|
1900
|
+
H = true, F.push([T, R, { mlTensor: re, download: s.webnnCreateMLTensorDownloader(D, T), dispose: () => {
|
|
1901
|
+
s.webnnReleaseTensorId(D), s._OrtReleaseTensor(W);
|
|
1902
|
+
} }, "ml-tensor"]);
|
|
1903
|
+
} else if (K === "ml-tensor-cpu-output" && N > 0) {
|
|
1904
|
+
let B = s.webnnCreateMLTensorDownloader(D, T)(), I = F.length;
|
|
1905
|
+
H = true, Le.push((async () => {
|
|
1906
|
+
let G = [I, await B];
|
|
1907
|
+
return s.webnnReleaseTensorId(D), s._OrtReleaseTensor(W), G;
|
|
1908
|
+
})()), F.push([T, R, [], "cpu"]);
|
|
1909
|
+
} else {
|
|
1910
|
+
let B = Ge(T), I = new B(N);
|
|
1911
|
+
new Uint8Array(I.buffer, I.byteOffset, I.byteLength).set(s.HEAPU8.subarray(D, D + I.byteLength)), F.push([T, R, I, "cpu"]);
|
|
1912
|
+
}
|
|
1913
|
+
} finally {
|
|
1914
|
+
s.stackRestore(Be), T === "string" && D && s._free(D), H || s._OrtReleaseTensor(W);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
c && !p && (s._OrtClearBoundOutputs(c.handle) !== 0 && g("Can't clear bound outputs."), Z.set(e, [l, w, f, c, p, false]));
|
|
1918
|
+
for (let [d, W] of await Promise.all(Le)) F[d][2] = W;
|
|
1919
|
+
return TRACE_EVENT_END("wasm ProcessOutputTensor"), F;
|
|
1920
|
+
} finally {
|
|
1921
|
+
s.webnnOnRunEnd?.(l), s.stackRestore(U), M.forEach((x) => s._OrtReleaseTensor(x)), y.forEach((x) => s._OrtReleaseTensor(x)), O.forEach((x) => s._free(x)), m !== 0 && s._OrtReleaseRunOptions(m), b.forEach((x) => s._free(x));
|
|
1922
|
+
}
|
|
1923
|
+
}, Qe = (e) => {
|
|
1924
|
+
let t = E(), n = Z.get(e);
|
|
1925
|
+
if (!n) throw new Error("invalid session id");
|
|
1926
|
+
let o = n[0], r = t._OrtEndProfiling(o);
|
|
1927
|
+
r === 0 && g("Can't get an profile file name."), t._OrtFree(r);
|
|
1928
|
+
};
|
|
1929
|
+
});
|
|
1930
|
+
var Se;
|
|
1931
|
+
var tt;
|
|
1932
|
+
var rt;
|
|
1933
|
+
var nt;
|
|
1934
|
+
var ot;
|
|
1935
|
+
var st;
|
|
1936
|
+
var at;
|
|
1937
|
+
var it;
|
|
1938
|
+
var ut;
|
|
1939
|
+
var ct;
|
|
1940
|
+
var Oe = C(() => {
|
|
1941
|
+
"use strict";
|
|
1942
|
+
et();
|
|
1943
|
+
V();
|
|
1944
|
+
me();
|
|
1945
|
+
Se = false, tt = false, rt = false, nt = async () => {
|
|
1946
|
+
if (!tt) {
|
|
1947
|
+
if (Se) throw new Error("multiple calls to 'initWasm()' detected.");
|
|
1948
|
+
if (rt) throw new Error("previous call to 'initWasm()' failed.");
|
|
1949
|
+
Se = true;
|
|
1950
|
+
try {
|
|
1951
|
+
await We(env2.wasm), await Je(env2), tt = true;
|
|
1952
|
+
} catch (e) {
|
|
1953
|
+
throw rt = true, e;
|
|
1954
|
+
} finally {
|
|
1955
|
+
Se = false;
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
}, ot = async (e) => {
|
|
1959
|
+
await Ye(env2, e);
|
|
1960
|
+
}, st = async (e) => Ee(e), at = async (e, t) => Ze(e, t), it = async (e) => {
|
|
1961
|
+
Xe(e);
|
|
1962
|
+
}, ut = async (e, t, n, o, r, a) => Ke(e, t, n, o, r, a), ct = async (e) => {
|
|
1963
|
+
Qe(e);
|
|
1964
|
+
};
|
|
1965
|
+
});
|
|
1966
|
+
var pt;
|
|
1967
|
+
var Gt;
|
|
1968
|
+
var ce;
|
|
1969
|
+
var dt = C(() => {
|
|
1970
|
+
"use strict";
|
|
1971
|
+
Oe();
|
|
1972
|
+
ge();
|
|
1973
|
+
ne();
|
|
1974
|
+
ye();
|
|
1975
|
+
pt = (e, t) => {
|
|
1976
|
+
switch (e.location) {
|
|
1977
|
+
case "cpu":
|
|
1978
|
+
return [e.type, e.dims, e.data, "cpu"];
|
|
1979
|
+
case "gpu-buffer":
|
|
1980
|
+
return [e.type, e.dims, { gpuBuffer: e.gpuBuffer }, "gpu-buffer"];
|
|
1981
|
+
case "ml-tensor":
|
|
1982
|
+
return [e.type, e.dims, { mlTensor: e.mlTensor }, "ml-tensor"];
|
|
1983
|
+
default:
|
|
1984
|
+
throw new Error(`invalid data location: ${e.location} for ${t()}`);
|
|
1985
|
+
}
|
|
1986
|
+
}, Gt = (e) => {
|
|
1987
|
+
switch (e[3]) {
|
|
1988
|
+
case "cpu":
|
|
1989
|
+
return new Tensor2(e[0], e[2], e[1]);
|
|
1990
|
+
case "gpu-buffer": {
|
|
1991
|
+
let t = e[0];
|
|
1992
|
+
if (!ie(t)) throw new Error(`not supported data type: ${t} for deserializing GPU tensor`);
|
|
1993
|
+
let { gpuBuffer: n, download: o, dispose: r } = e[2];
|
|
1994
|
+
return Tensor2.fromGpuBuffer(n, { dataType: t, dims: e[1], download: o, dispose: r });
|
|
1995
|
+
}
|
|
1996
|
+
case "ml-tensor": {
|
|
1997
|
+
let t = e[0];
|
|
1998
|
+
if (!ue(t)) throw new Error(`not supported data type: ${t} for deserializing MLTensor tensor`);
|
|
1999
|
+
let { mlTensor: n, download: o, dispose: r } = e[2];
|
|
2000
|
+
return Tensor2.fromMLTensor(n, { dataType: t, dims: e[1], download: o, dispose: r });
|
|
2001
|
+
}
|
|
2002
|
+
default:
|
|
2003
|
+
throw new Error(`invalid data location: ${e[3]}`);
|
|
2004
|
+
}
|
|
2005
|
+
}, ce = class {
|
|
2006
|
+
async fetchModelAndCopyToWasmMemory(t) {
|
|
2007
|
+
return st(await ee(t));
|
|
2008
|
+
}
|
|
2009
|
+
async loadModel(t, n) {
|
|
2010
|
+
TRACE_FUNC_BEGIN();
|
|
2011
|
+
let o;
|
|
2012
|
+
typeof t == "string" ? j ? o = await ee(t) : o = await this.fetchModelAndCopyToWasmMemory(t) : o = t, [this.sessionId, this.inputNames, this.outputNames, this.inputMetadata, this.outputMetadata] = await at(o, n), TRACE_FUNC_END();
|
|
2013
|
+
}
|
|
2014
|
+
async dispose() {
|
|
2015
|
+
return it(this.sessionId);
|
|
2016
|
+
}
|
|
2017
|
+
async run(t, n, o) {
|
|
2018
|
+
TRACE_FUNC_BEGIN();
|
|
2019
|
+
let r = [], a = [];
|
|
2020
|
+
Object.entries(t).forEach((c) => {
|
|
2021
|
+
let p = c[0], S = c[1], h = this.inputNames.indexOf(p);
|
|
2022
|
+
if (h === -1) throw new Error(`invalid input '${p}'`);
|
|
2023
|
+
r.push(S), a.push(h);
|
|
2024
|
+
});
|
|
2025
|
+
let s = [], i = [];
|
|
2026
|
+
Object.entries(n).forEach((c) => {
|
|
2027
|
+
let p = c[0], S = c[1], h = this.outputNames.indexOf(p);
|
|
2028
|
+
if (h === -1) throw new Error(`invalid output '${p}'`);
|
|
2029
|
+
s.push(S), i.push(h);
|
|
2030
|
+
});
|
|
2031
|
+
let u = r.map((c, p) => pt(c, () => `input "${this.inputNames[a[p]]}"`)), l = s.map((c, p) => c ? pt(c, () => `output "${this.outputNames[i[p]]}"`) : null), w = await ut(this.sessionId, a, u, i, l, o), f = {};
|
|
2032
|
+
for (let c = 0; c < w.length; c++) f[this.outputNames[i[c]]] = s[c] ?? Gt(w[c]);
|
|
2033
|
+
return TRACE_FUNC_END(), f;
|
|
2034
|
+
}
|
|
2035
|
+
startProfiling() {
|
|
2036
|
+
}
|
|
2037
|
+
endProfiling() {
|
|
2038
|
+
ct(this.sessionId);
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
2041
|
+
});
|
|
2042
|
+
var bt = {};
|
|
2043
|
+
Ot(bt, { OnnxruntimeWebAssemblyBackend: () => fe, initializeFlags: () => mt, wasmBackend: () => jt });
|
|
2044
|
+
var mt;
|
|
2045
|
+
var fe;
|
|
2046
|
+
var jt;
|
|
2047
|
+
var wt = C(() => {
|
|
2048
|
+
"use strict";
|
|
2049
|
+
Oe();
|
|
2050
|
+
dt();
|
|
2051
|
+
mt = () => {
|
|
2052
|
+
(typeof env2.wasm.initTimeout != "number" || env2.wasm.initTimeout < 0) && (env2.wasm.initTimeout = 0);
|
|
2053
|
+
let e = env2.wasm.simd;
|
|
2054
|
+
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.`), env2.wasm.simd = false), typeof env2.wasm.proxy != "boolean" && (env2.wasm.proxy = false), typeof env2.wasm.trace != "boolean" && (env2.wasm.trace = false), typeof env2.wasm.numThreads != "number" || !Number.isInteger(env2.wasm.numThreads) || env2.wasm.numThreads <= 0) if (typeof self < "u" && !self.crossOriginIsolated) env2.wasm.numThreads = 1;
|
|
2055
|
+
else {
|
|
2056
|
+
let t = typeof navigator > "u" ? de("node:os").cpus().length : navigator.hardwareConcurrency;
|
|
2057
|
+
env2.wasm.numThreads = Math.min(4, Math.ceil((t || 1) / 2));
|
|
2058
|
+
}
|
|
2059
|
+
}, fe = class {
|
|
2060
|
+
async init(t) {
|
|
2061
|
+
mt(), await nt(), await ot(t);
|
|
2062
|
+
}
|
|
2063
|
+
async createInferenceSessionHandler(t, n) {
|
|
2064
|
+
let o = new ce();
|
|
2065
|
+
return await o.loadModel(t, n), o;
|
|
2066
|
+
}
|
|
2067
|
+
}, jt = new fe();
|
|
2068
|
+
});
|
|
2069
|
+
var De = "1.30.0";
|
|
2070
|
+
var Hr = esm_exports;
|
|
2071
|
+
{
|
|
2072
|
+
let e = (wt(), Tt(bt)).wasmBackend;
|
|
2073
|
+
registerBackend("cpu", e, 10), registerBackend("wasm", e, 10);
|
|
2074
|
+
}
|
|
2075
|
+
Object.defineProperty(env2.versions, "web", { value: De, enumerable: true });
|
|
2076
|
+
export {
|
|
2077
|
+
InferenceSession2 as InferenceSession,
|
|
2078
|
+
TRACE,
|
|
2079
|
+
TRACE_EVENT_BEGIN,
|
|
2080
|
+
TRACE_EVENT_END,
|
|
2081
|
+
TRACE_FUNC_BEGIN,
|
|
2082
|
+
TRACE_FUNC_END,
|
|
2083
|
+
Tensor2 as Tensor,
|
|
2084
|
+
Hr as default,
|
|
2085
|
+
env2 as env,
|
|
2086
|
+
registerBackend
|
|
2087
|
+
};
|
|
2088
|
+
/*! Bundled license information:
|
|
2089
|
+
|
|
2090
|
+
onnxruntime-web/dist/ort.node.min.mjs:
|
|
2091
|
+
(*!
|
|
2092
|
+
* ONNX Runtime Web v1.30.0
|
|
2093
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2094
|
+
* Licensed under the MIT License.
|
|
2095
|
+
*)
|
|
2096
|
+
*/
|