onnxruntime-web
Version:
A Javascript library for running ONNX models on browsers
7 lines • 57.9 kB
JavaScript
/*!
* ONNX Runtime Web v1.17.3
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
"use strict";var ort=(()=>{var Ke=Object.defineProperty;var Zr=Object.getOwnPropertyDescriptor;var Qr=Object.getOwnPropertyNames;var en=Object.prototype.hasOwnProperty;var P=(r,e)=>()=>(r&&(e=r(r=0)),e);var tn=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),xe=(r,e)=>{for(var t in e)Ke(r,t,{get:e[t],enumerable:!0})},rn=(r,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Qr(e))!en.call(r,o)&&o!==t&&Ke(r,o,{get:()=>e[o],enumerable:!(a=Zr(e,o))||a.enumerable});return r};var Ue=r=>rn(Ke({},"__esModule",{value:!0}),r);var Re,pe,Ee,nn,Le,Fe=P(()=>{"use strict";Re=new Map,pe=[],Ee=(r,e,t)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let a=Re.get(r);if(a===void 0)Re.set(r,{backend:e,priority:t});else{if(a.priority>t)return;if(a.priority===t&&a.backend!==e)throw new Error(`cannot register backend "${r}" using priority ${t}`)}if(t>=0){let o=pe.indexOf(r);o!==-1&&pe.splice(o,1);for(let d=0;d<pe.length;d++)if(Re.get(pe[d]).priority<=t){pe.splice(d,0,r);return}pe.push(r)}return}throw new TypeError("not a valid backend")},nn=async r=>{let e=Re.get(r);if(!e)return"backend not found.";if(e.initialized)return e.backend;if(e.aborted)return e.error;{let t=!!e.initPromise;try{return t||(e.initPromise=e.backend.init(r)),await e.initPromise,e.initialized=!0,e.backend}catch(a){return t||(e.error=`${a}`,e.aborted=!0),e.error}finally{delete e.initPromise}}},Le=async r=>{let e=r.executionProviders||[],t=e.map(f=>typeof f=="string"?f:f.name),a=t.length===0?pe:t,o,d=[],u=new Set;for(let f of a){let c=await nn(f);typeof c=="string"?d.push({name:f,err:c}):(o||(o=c),o===c&&u.add(f))}if(!o)throw new Error(`no available backend found. ERR: ${d.map(f=>`[${f.name}] ${f.err}`).join(", ")}`);for(let{name:f,err:c}of d)t.includes(f)&&console.warn(`removing requested execution provider "${f}" from session options because it is not available: ${c}`);let l=e.filter(f=>u.has(typeof f=="string"?f:f.name));return[o,new Proxy(r,{get:(f,c)=>c==="executionProviders"?l:Reflect.get(f,c)})]}});var _t=P(()=>{"use strict";Fe()});var Dt,Ut=P(()=>{"use strict";Dt="1.17.3"});var Rt,K,Ze=P(()=>{"use strict";Ut();Rt="warning",K={wasm:{},webgl:{},webgpu:{},versions:{common:Dt},set logLevel(r){if(r!==void 0){if(typeof r!="string"||["verbose","info","warning","error","fatal"].indexOf(r)===-1)throw new Error(`Unsupported logging level: ${r}`);Rt=r}},get logLevel(){return Rt}};Object.defineProperty(K,"logLevel",{enumerable:!0})});var U,Lt=P(()=>{"use strict";Ze();U=K});var Ft,Mt,kt=P(()=>{"use strict";Ft=(r,e)=>{let t=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);t.width=r.dims[3],t.height=r.dims[2];let a=t.getContext("2d");if(a!=null){let o,d;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(o=r.dims[2],d=r.dims[3]):(o=r.dims[3],d=r.dims[2]);let u=e?.format!==void 0?e.format:"RGB",l=e?.norm,f,c;l===void 0||l.mean===void 0?f=[255,255,255,255]:typeof l.mean=="number"?f=[l.mean,l.mean,l.mean,l.mean]:(f=[l.mean[0],l.mean[1],l.mean[2],0],l.mean[3]!==void 0&&(f[3]=l.mean[3])),l===void 0||l.bias===void 0?c=[0,0,0,0]:typeof l.bias=="number"?c=[l.bias,l.bias,l.bias,l.bias]:(c=[l.bias[0],l.bias[1],l.bias[2],0],l.bias[3]!==void 0&&(c[3]=l.bias[3]));let y=d*o,w=0,h=y,b=y*2,v=-1;u==="RGBA"?(w=0,h=y,b=y*2,v=y*3):u==="RGB"?(w=0,h=y,b=y*2):u==="RBG"&&(w=0,b=y,h=y*2);for(let O=0;O<d;O++)for(let S=0;S<o;S++){let _=(r.data[w++]-c[0])*f[0],x=(r.data[h++]-c[1])*f[1],B=(r.data[b++]-c[2])*f[2],W=v===-1?255:(r.data[v++]-c[3])*f[3];a.fillStyle="rgba("+_+","+x+","+B+","+W+")",a.fillRect(S,O,1,1)}if("toDataURL"in t)return t.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},Mt=(r,e)=>{let t=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),a;if(t!=null){let o,d,u;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(o=r.dims[2],d=r.dims[1],u=r.dims[3]):(o=r.dims[3],d=r.dims[2],u=r.dims[1]);let l=e!==void 0&&e.format!==void 0?e.format:"RGB",f=e?.norm,c,y;f===void 0||f.mean===void 0?c=[255,255,255,255]:typeof f.mean=="number"?c=[f.mean,f.mean,f.mean,f.mean]:(c=[f.mean[0],f.mean[1],f.mean[2],255],f.mean[3]!==void 0&&(c[3]=f.mean[3])),f===void 0||f.bias===void 0?y=[0,0,0,0]:typeof f.bias=="number"?y=[f.bias,f.bias,f.bias,f.bias]:(y=[f.bias[0],f.bias[1],f.bias[2],0],f.bias[3]!==void 0&&(y[3]=f.bias[3]));let w=d*o;if(e!==void 0&&(e.format!==void 0&&u===4&&e.format!=="RGBA"||u===3&&e.format!=="RGB"&&e.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let h=4,b=0,v=1,O=2,S=3,_=0,x=w,B=w*2,W=-1;l==="RGBA"?(_=0,x=w,B=w*2,W=w*3):l==="RGB"?(_=0,x=w,B=w*2):l==="RBG"&&(_=0,B=w,x=w*2),a=t.createImageData(o,d);for(let k=0;k<d*o;b+=h,v+=h,O+=h,S+=h,k++)a.data[b]=(r.data[_++]-y[0])*c[0],a.data[v]=(r.data[x++]-y[1])*c[1],a.data[O]=(r.data[B++]-y[2])*c[2],a.data[S]=W===-1?255:(r.data[W++]-y[3])*c[3]}else throw new Error("Can not access image data");return a}});var Qe,Nt,Wt,Gt,Ht,$t=P(()=>{"use strict";Me();Qe=(r,e)=>{if(r===void 0)throw new Error("Image buffer must be defined");if(e.height===void 0||e.width===void 0)throw new Error("Image height and width must be defined");if(e.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:t,width:a}=e,o=e.norm??{mean:255,bias:0},d,u;typeof o.mean=="number"?d=[o.mean,o.mean,o.mean,o.mean]:d=[o.mean[0],o.mean[1],o.mean[2],o.mean[3]??255],typeof o.bias=="number"?u=[o.bias,o.bias,o.bias,o.bias]:u=[o.bias[0],o.bias[1],o.bias[2],o.bias[3]??0];let l=e.format!==void 0?e.format:"RGBA",f=e.tensorFormat!==void 0&&e.tensorFormat!==void 0?e.tensorFormat:"RGB",c=t*a,y=f==="RGBA"?new Float32Array(c*4):new Float32Array(c*3),w=4,h=0,b=1,v=2,O=3,S=0,_=c,x=c*2,B=-1;l==="RGB"&&(w=3,h=0,b=1,v=2,O=-1),f==="RGBA"?B=c*3:f==="RBG"?(S=0,x=c,_=c*2):f==="BGR"&&(x=0,_=c,S=c*2);for(let k=0;k<c;k++,h+=w,v+=w,b+=w,O+=w)y[S++]=(r[h]+u[0])/d[0],y[_++]=(r[b]+u[1])/d[1],y[x++]=(r[v]+u[2])/d[2],B!==-1&&O!==-1&&(y[B++]=(r[O]+u[3])/d[3]);return f==="RGBA"?new Y("float32",y,[1,4,t,a]):new Y("float32",y,[1,3,t,a])},Nt=async(r,e)=>{let t=typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement,a=typeof ImageData<"u"&&r instanceof ImageData,o=typeof ImageBitmap<"u"&&r instanceof ImageBitmap,d=typeof r=="string",u,l=e??{},f=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},c=y=>y instanceof HTMLCanvasElement||y instanceof OffscreenCanvas?y.getContext("2d"):null;if(t){let y=f();y.width=r.width,y.height=r.height;let w=c(y);if(w!=null){let h=r.height,b=r.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(h=e.resizedHeight,b=e.resizedWidth),e!==void 0){if(l=e,e.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");l.tensorFormat="RGBA",l.height=h,l.width=b}else l.tensorFormat="RGBA",l.height=h,l.width=b;w.drawImage(r,0,0),u=w.getImageData(0,0,b,h).data}else throw new Error("Can not access image data")}else if(a){let y,w;if(e!==void 0&&e.resizedWidth!==void 0&&e.resizedHeight!==void 0?(y=e.resizedHeight,w=e.resizedWidth):(y=r.height,w=r.width),e!==void 0&&(l=e),l.format="RGBA",l.height=y,l.width=w,e!==void 0){let h=f();h.width=w,h.height=y;let b=c(h);if(b!=null)b.putImageData(r,0,0),u=b.getImageData(0,0,w,y).data;else throw new Error("Can not access image data")}else u=r.data}else if(o){if(e===void 0)throw new Error("Please provide image config with format for Imagebitmap");let y=f();y.width=r.width,y.height=r.height;let w=c(y);if(w!=null){let h=r.height,b=r.width;return w.drawImage(r,0,0,b,h),u=w.getImageData(0,0,b,h).data,l.height=h,l.width=b,Qe(u,l)}else throw new Error("Can not access image data")}else{if(d)return new Promise((y,w)=>{let h=f(),b=c(h);if(!r||!b)return w();let v=new Image;v.crossOrigin="Anonymous",v.src=r,v.onload=()=>{h.width=v.width,h.height=v.height,b.drawImage(v,0,0,h.width,h.height);let O=b.getImageData(0,0,h.width,h.height);l.height=h.height,l.width=h.width,y(Qe(O.data,l))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(u!==void 0)return Qe(u,l);throw new Error("Input data provided is not supported - aborted tensor creation")},Wt=(r,e)=>{let{width:t,height:a,download:o,dispose:d}=e,u=[1,a,t,4];return new Y({location:"texture",type:"float32",texture:r,dims:u,download:o,dispose:d})},Gt=(r,e)=>{let{dataType:t,dims:a,download:o,dispose:d}=e;return new Y({location:"gpu-buffer",type:t??"float32",gpuBuffer:r,dims:a,download:o,dispose:d})},Ht=(r,e,t)=>new Y({location:"cpu-pinned",type:r,data:e,dims:t??[e.length]})});var me,Ie,jt,zt,Yt=P(()=>{"use strict";me=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array]]),Ie=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),jt=!1,zt=()=>{if(!jt){jt=!0;let r=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,t=typeof Float16Array<"u"&&Float16Array.from;r&&(me.set("int64",BigInt64Array),Ie.set(BigInt64Array,"int64")),e&&(me.set("uint64",BigUint64Array),Ie.set(BigUint64Array,"uint64")),t?(me.set("float16",Float16Array),Ie.set(Float16Array,"float16")):me.set("float16",Uint16Array)}}});var qt,Vt,Xt=P(()=>{"use strict";Me();qt=r=>{let e=1;for(let t=0;t<r.length;t++){let a=r[t];if(typeof a!="number"||!Number.isSafeInteger(a))throw new TypeError(`dims[${t}] must be an integer, got: ${a}`);if(a<0)throw new RangeError(`dims[${t}] must be a non-negative integer, got: ${a}`);e*=a}return e},Vt=(r,e)=>{switch(r.location){case"cpu":return new Y(r.type,r.data,e);case"cpu-pinned":return new Y({location:"cpu-pinned",data:r.data,type:r.type,dims:e});case"texture":return new Y({location:"texture",texture:r.texture,type:r.type,dims:e});case"gpu-buffer":return new Y({location:"gpu-buffer",gpuBuffer:r.gpuBuffer,type:r.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${r.location} is not supported`)}}});var Y,Me=P(()=>{"use strict";kt();$t();Yt();Xt();Y=class{constructor(e,t,a){zt();let o,d;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,o=e.type,d=e.dims,e.location){case"cpu-pinned":{let l=me.get(o);if(!l)throw new TypeError(`unsupported type "${o}" to create tensor from pinned buffer`);if(!(e.data instanceof l))throw new TypeError(`buffer should be of type ${l.name}`);this.cpuData=e.data;break}case"texture":{if(o!=="float32")throw new TypeError(`unsupported type "${o}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(o!=="float32"&&o!=="float16"&&o!=="int32"&&o!=="int64"&&o!=="uint32"&&o!=="uint8"&&o!=="bool")throw new TypeError(`unsupported type "${o}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let l,f;if(typeof e=="string")if(o=e,f=a,e==="string"){if(!Array.isArray(t))throw new TypeError("A string tensor's data must be a string array.");l=t}else{let c=me.get(e);if(c===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(t)){if(e==="float16"&&c===Uint16Array)throw new TypeError("Creating a float16 tensor from number array is not supported. Please use Uint16Array as data.");e==="uint64"||e==="int64"?l=c.from(t,BigInt):l=c.from(t)}else if(t instanceof c)l=t;else throw new TypeError(`A ${o} tensor's data must be type of ${c}`)}else if(f=t,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let c=typeof e[0];if(c==="string")o="string",l=e;else if(c==="boolean")o="bool",l=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${c}.`)}else{let c=Ie.get(e.constructor);if(c===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);o=c,l=e}if(f===void 0)f=[l.length];else if(!Array.isArray(f))throw new TypeError("A tensor's dims must be a number array");d=f,this.cpuData=l,this.dataLocation="cpu"}let u=qt(d);if(this.cpuData&&u!==this.cpuData.length)throw new Error(`Tensor's size(${u}) does not match data length(${this.cpuData.length}).`);this.type=o,this.dims=d,this.size=u}static async fromImage(e,t){return Nt(e,t)}static fromTexture(e,t){return Wt(e,t)}static fromGpuBuffer(e,t){return Gt(e,t)}static fromPinnedBuffer(e,t,a){return Ht(e,t,a)}toDataURL(e){return Ft(this,e)}toImageData(e){return Mt(this,e)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let t=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=t,e&&this.disposer&&(this.disposer(),this.disposer=void 0),t}finally{this.isDownloading=!1}}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return Vt(this,e)}}});var H,ke=P(()=>{"use strict";Me();H=Y});var et,Jt,ae,ie,tt=P(()=>{"use strict";Ze();et=(r,e)=>{(typeof K.trace>"u"?!K.wasm.trace:!K.trace)||console.timeStamp(`${r}::ORT::${e}`)},Jt=(r,e)=>{let t=new Error().stack?.split(/\r\n|\r|\n/g)||[],a=!1;for(let o=0;o<t.length;o++){if(a&&!t[o].includes("TRACE_FUNC")){let d=`FUNC_${r}::${t[o].trim().split(" ")[1]}`;e&&(d+=`::${e}`),et("CPU",d);return}t[o].includes("TRACE_FUNC")&&(a=!0)}},ae=r=>{(typeof K.trace>"u"?!K.wasm.trace:!K.trace)||Jt("BEGIN",r)},ie=r=>{(typeof K.trace>"u"?!K.wasm.trace:!K.trace)||Jt("END",r)}});var Ne,Kt=P(()=>{"use strict";Fe();ke();tt();Ne=class r{constructor(e){this.handler=e}async run(e,t,a){ae();let o={},d={};if(typeof e!="object"||e===null||e instanceof H||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let u=!0;if(typeof t=="object"){if(t===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(t instanceof H)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(t)){if(t.length===0)throw new TypeError("'fetches' cannot be an empty array.");u=!1;for(let c of t){if(typeof c!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(c)===-1)throw new RangeError(`'fetches' contains invalid output name: ${c}.`);o[c]=null}if(typeof a=="object"&&a!==null)d=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else{let c=!1,y=Object.getOwnPropertyNames(t);for(let w of this.outputNames)if(y.indexOf(w)!==-1){let h=t[w];(h===null||h instanceof H)&&(c=!0,u=!1,o[w]=h)}if(c){if(typeof a=="object"&&a!==null)d=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else d=t}}else if(typeof t<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let c of this.inputNames)if(typeof e[c]>"u")throw new Error(`input '${c}' is missing in 'feeds'.`);if(u)for(let c of this.outputNames)o[c]=null;let l=await this.handler.run(e,o,d),f={};for(let c in l)if(Object.hasOwnProperty.call(l,c)){let y=l[c];y instanceof H?f[c]=y:f[c]=new H(y.type,y.data,y.dims)}return ie(),f}async release(){return this.handler.dispose()}static async create(e,t,a,o){ae();let d,u={};if(typeof e=="string"){if(d=e,typeof t=="object"&&t!==null)u=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(d=e,typeof t=="object"&&t!==null)u=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){let y=e,w=0,h=e.byteLength;if(typeof t=="object"&&t!==null)u=t;else if(typeof t=="number"){if(w=t,!Number.isSafeInteger(w))throw new RangeError("'byteOffset' must be an integer.");if(w<0||w>=y.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${y.byteLength}).`);if(h=e.byteLength-w,typeof a=="number"){if(h=a,!Number.isSafeInteger(h))throw new RangeError("'byteLength' must be an integer.");if(h<=0||w+h>y.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${y.byteLength-w}].`);if(typeof o=="object"&&o!==null)u=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else if(typeof a<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof t<"u")throw new TypeError("'options' must be an object.");d=new Uint8Array(y,w,h)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[l,f]=await Le(u),c=await l.createInferenceSessionHandler(d,f);return ie(),new r(c)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}});var Zt,Qt=P(()=>{"use strict";Kt();Zt=Ne});var er=P(()=>{"use strict"});var tr=P(()=>{"use strict"});var rr=P(()=>{"use strict"});var nr=P(()=>{"use strict"});var on,We,or=P(()=>{"use strict";Fe();ke();on="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",We=class r{constructor(e,t,a){this.handler=e,this.hasOptimizerModel=t,this.hasEvalModel=a}get trainingInputNames(){return this.handler.inputNames}get trainingOutputNames(){return this.handler.outputNames}get evalInputNames(){if(this.hasEvalModel)return this.handler.evalInputNames;throw new Error("This training session has no evalModel loaded.")}get evalOutputNames(){if(this.hasEvalModel)return this.handler.evalOutputNames;throw new Error("This training session has no evalModel loaded.")}static async create(e,t){let a=e.evalModel||"",o=e.optimizerModel||"",d=t||{},[u,l]=await Le(d);if(u.createTrainingSessionHandler){let f=await u.createTrainingSessionHandler(e.checkpointState,e.trainModel,a,o,l);return new r(f,!!e.optimizerModel,!!e.evalModel)}else throw new Error(on)}typeNarrowingForRunStep(e,t,a,o,d){let u={},l={};if(typeof a!="object"||a===null||a instanceof H||Array.isArray(a))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let f=!0;if(typeof o=="object"){if(o===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(o instanceof H)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(o)){if(o.length===0)throw new TypeError("'fetches' cannot be an empty array.");f=!1;for(let c of o){if(typeof c!="string")throw new TypeError("'fetches' must be a string array or an object.");if(t.indexOf(c)===-1)throw new RangeError(`'fetches' contains invalid output name: ${c}.`);u[c]=null}if(typeof d=="object"&&d!==null)l=d;else if(typeof d<"u")throw new TypeError("'options' must be an object.")}else{let c=!1,y=Object.getOwnPropertyNames(o);for(let w of t)if(y.indexOf(w)!==-1){let h=o[w];(h===null||h instanceof H)&&(c=!0,f=!1,u[w]=h)}if(c){if(typeof d=="object"&&d!==null)l=d;else if(typeof d<"u")throw new TypeError("'options' must be an object.")}else l=o}}else if(typeof o<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let c of e)if(typeof a[c]>"u")throw new Error(`input '${c}' is missing in 'feeds'.`);if(f)for(let c of t)u[c]=null;return[u,l]}convertHandlerReturnTypeToMapOfTensors(e){let t={};for(let a in e)if(Object.hasOwnProperty.call(e,a)){let o=e[a];o instanceof H?t[a]=o:t[a]=new H(o.type,o.data,o.dims)}return t}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(e,t,a){let[o,d]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,e,t,a),u=await this.handler.runTrainStep(e,o,d);return this.convertHandlerReturnTypeToMapOfTensors(u)}async runOptimizerStep(e){if(this.hasOptimizerModel)await this.handler.runOptimizerStep(e||{});else throw new Error("This TrainingSession has no OptimizerModel loaded.")}async runEvalStep(e,t,a){if(this.hasEvalModel){let[o,d]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,e,t,a),u=await this.handler.runEvalStep(e,o,d);return this.convertHandlerReturnTypeToMapOfTensors(u)}else throw new Error("This TrainingSession has no EvalModel loaded.")}async getParametersSize(e=!0){return this.handler.getParametersSize(e)}async loadParametersBuffer(e,t=!0){let a=await this.getParametersSize(t);if(e.length!==4*a)throw new Error("Size of the buffer passed into loadParametersBuffer must match the number of parameters in the model. Please use getParametersSize method to check.");return this.handler.loadParametersBuffer(e,t)}async getContiguousParameters(e=!0){return this.handler.getContiguousParameters(e)}async release(){return this.handler.dispose()}}});var sr,ar=P(()=>{"use strict";or();sr=We});var rt={};xe(rt,{InferenceSession:()=>Zt,TRACE:()=>et,TRACE_FUNC_BEGIN:()=>ae,TRACE_FUNC_END:()=>ie,Tensor:()=>H,TrainingSession:()=>sr,env:()=>U,registerBackend:()=>Ee});var he=P(()=>{"use strict";_t();Lt();Qt();ke();er();tr();tt();rr();nr();ar()});var fr={};xe(fr,{createReadStream:()=>ur,readFile:()=>sn,readFileSync:()=>an});var sn,an,ur,lr=P(()=>{sn=void 0,an=void 0,ur=void 0});var cr={};xe(cr,{join:()=>un});var un,dr=P(()=>{un=void 0});var hr=tn((mr,nt)=>{"use strict";var pr=(()=>{var r=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return typeof __filename<"u"&&(r=r||__filename),function(e={}){var t=e,a,o;t.ready=new Promise((n,s)=>{a=n,o=s});var d=Object.assign({},t),u="./this.program",l=typeof window=="object",f=typeof importScripts=="function",c=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",y="",w,h,b;if(c){var v=(lr(),Ue(fr)),O=(dr(),Ue(cr));y=f?O.dirname(y)+"/":__dirname+"/",w=(n,s)=>(n=fe(n)?new URL(n):O.normalize(n),v.readFileSync(n,s?void 0:"utf8")),b=n=>(n=w(n,!0),n.buffer||(n=new Uint8Array(n)),n),h=(n,s,i,m=!0)=>{n=fe(n)?new URL(n):O.normalize(n),v.readFile(n,m?void 0:"utf8",(g,T)=>{g?i(g):s(m?T.buffer:T)})},!t.thisProgram&&1<process.argv.length&&(u=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2),t.inspect=()=>"[Emscripten Module object]"}else(l||f)&&(f?y=self.location.href:typeof document<"u"&&document.currentScript&&(y=document.currentScript.src),r&&(y=r),y.indexOf("blob:")!==0?y=y.substr(0,y.replace(/[?#].*/,"").lastIndexOf("/")+1):y="",w=n=>{var s=new XMLHttpRequest;return s.open("GET",n,!1),s.send(null),s.responseText},f&&(b=n=>{var s=new XMLHttpRequest;return s.open("GET",n,!1),s.responseType="arraybuffer",s.send(null),new Uint8Array(s.response)}),h=(n,s,i)=>{var m=new XMLHttpRequest;m.open("GET",n,!0),m.responseType="arraybuffer",m.onload=()=>{m.status==200||m.status==0&&m.response?s(m.response):i()},m.onerror=i,m.send(null)});var S=console.log.bind(console),_=console.error.bind(console);Object.assign(t,d),d=null,typeof WebAssembly!="object"&&C("no native wasm support detected");var x,B=!1,W,k,E,N,ye;function Oe(){var n=x.buffer;t.HEAP8=W=new Int8Array(n),t.HEAP16=new Int16Array(n),t.HEAPU8=k=new Uint8Array(n),t.HEAPU16=new Uint16Array(n),t.HEAP32=E=new Int32Array(n),t.HEAPU32=N=new Uint32Array(n),t.HEAPF32=new Float32Array(n),t.HEAPF64=ye=new Float64Array(n)}var X=[],Ae=[],Ce=[],ue=0,we=null,Q=null;function C(n){throw n="Aborted("+n+")",_(n),B=!0,n=new WebAssembly.RuntimeError(n+". Build with -sASSERTIONS for more info."),o(n),n}var ne=n=>n.startsWith("data:application/octet-stream;base64,"),fe=n=>n.startsWith("file://"),J;if(J="ort-wasm.wasm",!ne(J)){var le=J;J=t.locateFile?t.locateFile(le,y):y+le}function j(n){if(b)return b(n);throw"both async and sync fetching of the wasm failed"}function ee(n){if(l||f){if(typeof fetch=="function"&&!fe(n))return fetch(n,{credentials:"same-origin"}).then(s=>{if(!s.ok)throw"failed to load wasm binary file at '"+n+"'";return s.arrayBuffer()}).catch(()=>j(n));if(h)return new Promise((s,i)=>{h(n,m=>s(new Uint8Array(m)),i)})}return Promise.resolve().then(()=>j(n))}function Ye(n,s,i){return ee(n).then(m=>WebAssembly.instantiate(m,s)).then(m=>m).then(i,m=>{_(`failed to asynchronously prepare wasm: ${m}`),C(m)})}function ge(n,s){var i=J;return typeof WebAssembly.instantiateStreaming!="function"||ne(i)||fe(i)||c||typeof fetch!="function"?Ye(i,n,s):fetch(i,{credentials:"same-origin"}).then(m=>WebAssembly.instantiateStreaming(m,n).then(s,function(g){return _(`wasm streaming compile failed: ${g}`),_("falling back to ArrayBuffer instantiation"),Ye(i,n,s)}))}var re,_e={920016:(n,s,i,m)=>{if(typeof t>"u"||!t.za)return 1;if(n=G(n>>>0),n.startsWith("./")&&(n=n.substring(2)),n=t.za.get(n),!n)return 2;if(s>>>=0,i>>>=0,s+i>n.byteLength)return 3;try{return k.set(n.subarray(s,s+i),m>>>0>>>0),0}catch{return 4}}};function qe(n){this.xa=n-24,this.Ha=function(s){N[this.xa+4>>>2>>>0]=s},this.Ga=function(s){N[this.xa+8>>>2>>>0]=s},this.Aa=function(s,i){this.Fa(),this.Ha(s),this.Ga(i)},this.Fa=function(){N[this.xa+16>>>2>>>0]=0}}var oe=0,ce=0,Se=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,$=(n,s,i)=>{s>>>=0;var m=s+i;for(i=s;n[i]&&!(i>=m);)++i;if(16<i-s&&n.buffer&&Se)return Se.decode(n.subarray(s,i));for(m="";s<i;){var g=n[s++];if(g&128){var T=n[s++]&63;if((g&224)==192)m+=String.fromCharCode((g&31)<<6|T);else{var I=n[s++]&63;g=(g&240)==224?(g&15)<<12|T<<6|I:(g&7)<<18|T<<12|I<<6|n[s++]&63,65536>g?m+=String.fromCharCode(g):(g-=65536,m+=String.fromCharCode(55296|g>>10,56320|g&1023))}}else m+=String.fromCharCode(g)}return m},G=(n,s)=>(n>>>=0)?$(k,n,s):"",te=n=>{for(var s=0,i=0;i<n.length;++i){var m=n.charCodeAt(i);127>=m?s++:2047>=m?s+=2:55296<=m&&57343>=m?(s+=4,++i):s+=3}return s},be=(n,s,i,m)=>{if(i>>>=0,!(0<m))return 0;var g=i;m=i+m-1;for(var T=0;T<n.length;++T){var I=n.charCodeAt(T);if(55296<=I&&57343>=I){var z=n.charCodeAt(++T);I=65536+((I&1023)<<10)|z&1023}if(127>=I){if(i>=m)break;s[i++>>>0]=I}else{if(2047>=I){if(i+1>=m)break;s[i++>>>0]=192|I>>6}else{if(65535>=I){if(i+2>=m)break;s[i++>>>0]=224|I>>12}else{if(i+3>=m)break;s[i++>>>0]=240|I>>18,s[i++>>>0]=128|I>>12&63}s[i++>>>0]=128|I>>6&63}s[i++>>>0]=128|I&63}}return s[i>>>0]=0,i-g},se=n=>n%4===0&&(n%100!==0||n%400===0),mt=[0,31,60,91,121,152,182,213,244,274,305,335],ht=[0,31,59,90,120,151,181,212,243,273,304,334],yt=n=>{var s=te(n)+1,i=Tt(s);return i&&be(n,k,i,s),i},Ve=[],Xe={},wt=()=>{if(!Je){var n={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:u||"./this.program"},s;for(s in Xe)Xe[s]===void 0?delete n[s]:n[s]=Xe[s];var i=[];for(s in n)i.push(`${s}=${n[s]}`);Je=i}return Je},Je,Vr=[null,[],[]],gt=[31,29,31,30,31,30,31,31,30,31,30,31],bt=[31,28,31,30,31,30,31,31,30,31,30,31];function Xr(n){var s=Array(te(n)+1);return be(n,s,0,s.length),s}function Et(n,s,i,m){function g(p,D,F){for(p=typeof p=="number"?p.toString():p||"";p.length<D;)p=F[0]+p;return p}function T(p,D){return g(p,D,"0")}function I(p,D){function F(Ct){return 0>Ct?-1:0<Ct?1:0}var de;return(de=F(p.getFullYear()-D.getFullYear()))===0&&(de=F(p.getMonth()-D.getMonth()))===0&&(de=F(p.getDate()-D.getDate())),de}function z(p){switch(p.getDay()){case 0:return new Date(p.getFullYear()-1,11,29);case 1:return p;case 2:return new Date(p.getFullYear(),0,3);case 3:return new Date(p.getFullYear(),0,2);case 4:return new Date(p.getFullYear(),0,1);case 5:return new Date(p.getFullYear()-1,11,31);case 6:return new Date(p.getFullYear()-1,11,30)}}function Z(p){var D=p.ta;for(p=new Date(new Date(p.ua+1900,0,1).getTime());0<D;){var F=p.getMonth(),de=(se(p.getFullYear())?gt:bt)[F];if(D>de-p.getDate())D-=de-p.getDate()+1,p.setDate(1),11>F?p.setMonth(F+1):(p.setMonth(0),p.setFullYear(p.getFullYear()+1));else{p.setDate(p.getDate()+D);break}}return F=new Date(p.getFullYear()+1,0,4),D=z(new Date(p.getFullYear(),0,4)),F=z(F),0>=I(D,p)?0>=I(F,p)?p.getFullYear()+1:p.getFullYear():p.getFullYear()-1}n>>>=0,s>>>=0,i>>>=0,m>>>=0;var q=N[m+40>>>2>>>0];m={Da:E[m>>>2>>>0],Ca:E[m+4>>>2>>>0],va:E[m+8>>>2>>>0],ya:E[m+12>>>2>>>0],wa:E[m+16>>>2>>>0],ua:E[m+20>>>2>>>0],oa:E[m+24>>>2>>>0],ta:E[m+28>>>2>>>0],Ia:E[m+32>>>2>>>0],Ba:E[m+36>>>2>>>0],Ea:q?G(q):""},i=G(i),q={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var V in q)i=i.replace(new RegExp(V,"g"),q[V]);var Pt="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),Bt="January February March April May June July August September October November December".split(" ");q={"%a":p=>Pt[p.oa].substring(0,3),"%A":p=>Pt[p.oa],"%b":p=>Bt[p.wa].substring(0,3),"%B":p=>Bt[p.wa],"%C":p=>T((p.ua+1900)/100|0,2),"%d":p=>T(p.ya,2),"%e":p=>g(p.ya,2," "),"%g":p=>Z(p).toString().substring(2),"%G":p=>Z(p),"%H":p=>T(p.va,2),"%I":p=>(p=p.va,p==0?p=12:12<p&&(p-=12),T(p,2)),"%j":p=>{for(var D=0,F=0;F<=p.wa-1;D+=(se(p.ua+1900)?gt:bt)[F++]);return T(p.ya+D,3)},"%m":p=>T(p.wa+1,2),"%M":p=>T(p.Ca,2),"%n":()=>`
`,"%p":p=>0<=p.va&&12>p.va?"AM":"PM","%S":p=>T(p.Da,2),"%t":()=>" ","%u":p=>p.oa||7,"%U":p=>T(Math.floor((p.ta+7-p.oa)/7),2),"%V":p=>{var D=Math.floor((p.ta+7-(p.oa+6)%7)/7);if(2>=(p.oa+371-p.ta-2)%7&&D++,D)D==53&&(F=(p.oa+371-p.ta)%7,F==4||F==3&&se(p.ua)||(D=1));else{D=52;var F=(p.oa+7-p.ta-1)%7;(F==4||F==5&&se(p.ua%400-1))&&D++}return T(D,2)},"%w":p=>p.oa,"%W":p=>T(Math.floor((p.ta+7-(p.oa+6)%7)/7),2),"%y":p=>(p.ua+1900).toString().substring(2),"%Y":p=>p.ua+1900,"%z":p=>{p=p.Ba;var D=0<=p;return p=Math.abs(p)/60,(D?"+":"-")+("0000"+(p/60*100+p%60)).slice(-4)},"%Z":p=>p.Ea,"%%":()=>"%"},i=i.replace(/%%/g,"\0\0");for(V in q)i.includes(V)&&(i=i.replace(new RegExp(V,"g"),q[V](m)));return i=i.replace(/\0\0/g,"%"),V=Xr(i),V.length>s?0:(W.set(V,n>>>0),V.length-1)}var Jr={a:function(n,s,i){throw n>>>=0,new qe(n).Aa(s>>>0,i>>>0),oe=n,ce++,oe},e:function(){return 0},H:function(){},x:function(){},z:function(){},J:function(){return 0},F:function(){},A:function(){},E:function(){},g:function(){},y:function(){},v:function(){},G:function(){},w:function(){},k:()=>1,n:function(n,s,i){n=s+2097152>>>0<4194305-!!n?(n>>>0)+4294967296*s:NaN,i>>>=0,n=new Date(1e3*n),E[i>>>2>>>0]=n.getUTCSeconds(),E[i+4>>>2>>>0]=n.getUTCMinutes(),E[i+8>>>2>>>0]=n.getUTCHours(),E[i+12>>>2>>>0]=n.getUTCDate(),E[i+16>>>2>>>0]=n.getUTCMonth(),E[i+20>>>2>>>0]=n.getUTCFullYear()-1900,E[i+24>>>2>>>0]=n.getUTCDay(),E[i+28>>>2>>>0]=(n.getTime()-Date.UTC(n.getUTCFullYear(),0,1,0,0,0,0))/864e5|0},o:function(n,s,i){n=s+2097152>>>0<4194305-!!n?(n>>>0)+4294967296*s:NaN,i>>>=0,n=new Date(1e3*n),E[i>>>2>>>0]=n.getSeconds(),E[i+4>>>2>>>0]=n.getMinutes(),E[i+8>>>2>>>0]=n.getHours(),E[i+12>>>2>>>0]=n.getDate(),E[i+16>>>2>>>0]=n.getMonth(),E[i+20>>>2>>>0]=n.getFullYear()-1900,E[i+24>>>2>>>0]=n.getDay(),E[i+28>>>2>>>0]=(se(n.getFullYear())?mt:ht)[n.getMonth()]+n.getDate()-1|0,E[i+36>>>2>>>0]=-(60*n.getTimezoneOffset()),s=new Date(n.getFullYear(),6,1).getTimezoneOffset();var m=new Date(n.getFullYear(),0,1).getTimezoneOffset();E[i+32>>>2>>>0]=(s!=m&&n.getTimezoneOffset()==Math.min(m,s))|0},p:function(n){n>>>=0;var s=new Date(E[n+20>>>2>>>0]+1900,E[n+16>>>2>>>0],E[n+12>>>2>>>0],E[n+8>>>2>>>0],E[n+4>>>2>>>0],E[n>>>2>>>0],0),i=E[n+32>>>2>>>0],m=s.getTimezoneOffset(),g=new Date(s.getFullYear(),6,1).getTimezoneOffset(),T=new Date(s.getFullYear(),0,1).getTimezoneOffset(),I=Math.min(T,g);return 0>i?E[n+32>>>2>>>0]=+(g!=T&&I==m):0<i!=(I==m)&&(g=Math.max(T,g),s.setTime(s.getTime()+6e4*((0<i?I:g)-m))),E[n+24>>>2>>>0]=s.getDay(),E[n+28>>>2>>>0]=(se(s.getFullYear())?mt:ht)[s.getMonth()]+s.getDate()-1|0,E[n>>>2>>>0]=s.getSeconds(),E[n+4>>>2>>>0]=s.getMinutes(),E[n+8>>>2>>>0]=s.getHours(),E[n+12>>>2>>>0]=s.getDate(),E[n+16>>>2>>>0]=s.getMonth(),E[n+20>>>2>>>0]=s.getYear(),n=s.getTime(),isNaN(n)?(E[vt()>>>2>>>0]=61,n=-1):n/=1e3,Ot((re=n,1<=+Math.abs(re)?0<re?+Math.floor(re/4294967296)>>>0:~~+Math.ceil((re-+(~~re>>>0))/4294967296)>>>0:0)),n>>>0},l:function(){return-52},m:function(){},t:function(n,s,i){function m(Z){return(Z=Z.toTimeString().match(/\(([A-Za-z ]+)\)$/))?Z[1]:"GMT"}i>>>=0;var g=new Date().getFullYear(),T=new Date(g,0,1),I=new Date(g,6,1);g=T.getTimezoneOffset();var z=I.getTimezoneOffset();N[n>>>0>>>2>>>0]=60*Math.max(g,z),E[s>>>0>>>2>>>0]=+(g!=z),n=m(T),s=m(I),n=yt(n),s=yt(s),z<g?(N[i>>>2>>>0]=n,N[i+4>>>2>>>0]=s):(N[i>>>2>>>0]=s,N[i+4>>>2>>>0]=n)},d:()=>{C("")},B:function(n,s,i){n>>>=0,s>>>=0,i>>>=0,Ve.length=0;for(var m;m=k[s++>>>0];){var g=m!=105;g&=m!=112,i+=g&&i%8?4:0,Ve.push(m==112?N[i>>>2>>>0]:m==105?E[i>>>2>>>0]:ye[i>>>3>>>0]),i+=g?8:4}return _e[n].apply(null,Ve)},h:()=>Date.now(),u:function(){return 4294901760},b:()=>performance.now(),I:function(n,s,i){return s>>>=0,k.copyWithin(n>>>0>>>0,s>>>0,s+(i>>>0)>>>0)},s:function(n){n>>>=0;var s=k.length;if(4294901760<n)return!1;for(var i=1;4>=i;i*=2){var m=s*(1+.2/i);m=Math.min(m,n+100663296);var g=Math;m=Math.max(n,m);e:{g=(g.min.call(g,4294901760,m+(65536-m%65536)%65536)-x.buffer.byteLength+65535)/65536;try{x.grow(g),Oe();var T=1;break e}catch{}T=void 0}if(T)return!0}return!1},C:function(n,s){n>>>=0,s>>>=0;var i=0;return wt().forEach((m,g)=>{var T=s+i;for(g=N[n+4*g>>>2>>>0]=T,T=0;T<m.length;++T)W[g++>>>0>>>0]=m.charCodeAt(T);W[g>>>0>>>0]=0,i+=m.length+1}),0},D:function(n,s){n>>>=0,s>>>=0;var i=wt();N[n>>>2>>>0]=i.length;var m=0;return i.forEach(g=>m+=g.length+1),N[s>>>2>>>0]=m,0},f:()=>52,j:function(){return 52},q:function(){return 70},i:function(n,s,i,m){s>>>=0,i>>>=0,m>>>=0;for(var g=0,T=0;T<i;T++){var I=N[s>>>2>>>0],z=N[s+4>>>2>>>0];s+=8;for(var Z=0;Z<z;Z++){var q=k[I+Z>>>0],V=Vr[n];q===0||q===10?((n===1?S:_)($(V,0)),V.length=0):V.push(q)}g+=z}return N[m>>>2>>>0]=g,0},r:Et,c:function(n,s,i,m){return Et(n>>>0,s>>>0,i>>>0,m>>>0)}},A=function(){function n(i){return A=i.exports,A=Kr(),x=A.K,Oe(),Ae.unshift(A.L),ue--,ue==0&&(we!==null&&(clearInterval(we),we=null),Q&&(i=Q,Q=null,i())),A}var s={a:Jr};if(ue++,t.instantiateWasm)try{return t.instantiateWasm(s,n)}catch(i){_(`Module.instantiateWasm callback failed with error: ${i}`),o(i)}return ge(s,function(i){n(i.instance)}).catch(o),{}}();t._OrtInit=(n,s)=>(t._OrtInit=A.M)(n,s),t._OrtGetLastError=(n,s)=>(t._OrtGetLastError=A.N)(n,s),t._OrtCreateSessionOptions=(n,s,i,m,g,T,I,z,Z,q)=>(t._OrtCreateSessionOptions=A.O)(n,s,i,m,g,T,I,z,Z,q),t._OrtAppendExecutionProvider=(n,s)=>(t._OrtAppendExecutionProvider=A.P)(n,s),t._OrtAddFreeDimensionOverride=(n,s,i)=>(t._OrtAddFreeDimensionOverride=A.Q)(n,s,i),t._OrtAddSessionConfigEntry=(n,s,i)=>(t._OrtAddSessionConfigEntry=A.R)(n,s,i),t._OrtReleaseSessionOptions=n=>(t._OrtReleaseSessionOptions=A.S)(n),t._OrtCreateSession=(n,s,i)=>(t._OrtCreateSession=A.T)(n,s,i),t._OrtReleaseSession=n=>(t._OrtReleaseSession=A.U)(n),t._OrtGetInputOutputCount=(n,s,i)=>(t._OrtGetInputOutputCount=A.V)(n,s,i),t._OrtGetInputName=(n,s)=>(t._OrtGetInputName=A.W)(n,s),t._OrtGetOutputName=(n,s)=>(t._OrtGetOutputName=A.X)(n,s),t._OrtFree=n=>(t._OrtFree=A.Y)(n),t._OrtCreateTensor=(n,s,i,m,g,T)=>(t._OrtCreateTensor=A.Z)(n,s,i,m,g,T),t._OrtGetTensorData=(n,s,i,m,g)=>(t._OrtGetTensorData=A._)(n,s,i,m,g),t._OrtReleaseTensor=n=>(t._OrtReleaseTensor=A.$)(n),t._OrtCreateRunOptions=(n,s,i,m)=>(t._OrtCreateRunOptions=A.aa)(n,s,i,m),t._OrtAddRunConfigEntry=(n,s,i)=>(t._OrtAddRunConfigEntry=A.ba)(n,s,i),t._OrtReleaseRunOptions=n=>(t._OrtReleaseRunOptions=A.ca)(n),t._OrtCreateBinding=n=>(t._OrtCreateBinding=A.da)(n),t._OrtBindInput=(n,s,i)=>(t._OrtBindInput=A.ea)(n,s,i),t._OrtBindOutput=(n,s,i,m)=>(t._OrtBindOutput=A.fa)(n,s,i,m),t._OrtClearBoundOutputs=n=>(t._OrtClearBoundOutputs=A.ga)(n),t._OrtReleaseBinding=n=>(t._OrtReleaseBinding=A.ha)(n),t._OrtRunWithBinding=(n,s,i,m,g)=>(t._OrtRunWithBinding=A.ia)(n,s,i,m,g),t._OrtRun=(n,s,i,m,g,T,I,z)=>(t._OrtRun=A.ja)(n,s,i,m,g,T,I,z),t._OrtEndProfiling=n=>(t._OrtEndProfiling=A.ka)(n);var vt=()=>(vt=A.la)(),Tt=t._malloc=n=>(Tt=t._malloc=A.ma)(n);t._free=n=>(t._free=A.na)(n);var Ot=n=>(Ot=A.pa)(n),At=()=>(At=A.qa)(),St=n=>(St=A.ra)(n),xt=n=>(xt=A.sa)(n);function Kr(){var n=A;n=Object.assign({},n);var s=m=>()=>m()>>>0,i=m=>g=>m(g)>>>0;return n.la=s(n.la),n.ma=i(n.ma),n.qa=s(n.qa),n.sa=i(n.sa),n}t.stackAlloc=xt,t.stackSave=At,t.stackRestore=St,t.UTF8ToString=G,t.stringToUTF8=(n,s,i)=>be(n,k,s,i),t.lengthBytesUTF8=te;var De;Q=function n(){De||It(),De||(Q=n)};function It(){if(!(0<ue)){if(t.preRun)for(typeof t.preRun=="function"&&(t.preRun=[t.preRun]);t.preRun.length;){var n=t.preRun.shift();X.unshift(n)}for(;0<X.length;)X.shift()(t);if(!(0<ue||De||(De=!0,t.calledRun=!0,B))){for(;0<Ae.length;)Ae.shift()(t);for(a(t);0<Ce.length;)Ce.shift()(t)}}}return It(),e.ready}})();typeof mr=="object"&&typeof nt=="object"?nt.exports=pr:typeof define=="function"&&define.amd&&define([],()=>pr)});var at,fn,ot,st,Ge,yr,ln,cn,dn,wr,M,ve=P(()=>{"use strict";at=hr();fn=at,st=!1,Ge=!1,yr=!1,ln=r=>{if(r===1)return!1;if(typeof SharedArrayBuffer>"u")return typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+r+", but this will not work unless you enable crossOriginIsolated mode. See https://web.dev/cross-origin-isolation-guide/ for more info."),!1;typeof process<"u"&&process.versions&&process.versions.node&&console.warn("env.wasm.numThreads is set to "+r+", however, currently onnxruntime-web does not support multi-threads in Node.js. Please consider using onnxruntime-node for performance critical scenarios.");try{return typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch{return!1}},cn=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch{return!1}},dn=(r,e)=>r?e?"ort-wasm-simd-threaded.wasm":"ort-wasm-simd.wasm":e?"ort-wasm-threaded.wasm":"ort-wasm.wasm",wr=async r=>{if(st)return Promise.resolve();if(Ge)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(yr)throw new Error("previous call to 'initializeWebAssembly()' failed.");Ge=!0;let e=r.initTimeout,t=r.numThreads,a=r.simd,o=ln(t),d=a&&cn(),u=r.wasmPaths,l=typeof u=="string"?u:void 0,f=dn(d,o),c=typeof u=="object"?u[f]:void 0,y=!1,w=[];if(e>0&&w.push(new Promise(h=>{setTimeout(()=>{y=!0,h()},e)})),w.push(new Promise((h,b)=>{(o?fn:at)({locateFile:(S,_)=>S.endsWith(".wasm")?c||(l??_)+f:_+S}).then(S=>{Ge=!1,st=!0,ot=S,h()},S=>{Ge=!1,yr=!0,b(S)})})),await Promise.race(w),y)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},M=()=>{if(st&&ot)return ot;throw new Error("WebAssembly is not initialized yet.")}});var R,Pe,L,He=P(()=>{"use strict";ve();R=(r,e)=>{let t=M(),a=t.lengthBytesUTF8(r)+1,o=t._malloc(a);return t.stringToUTF8(r,o,a),e.push(o),o},Pe=(r,e,t,a)=>{if(typeof r=="object"&&r!==null){if(t.has(r))throw new Error("Circular reference in options");t.add(r)}Object.entries(r).forEach(([o,d])=>{let u=e?e+o:o;if(typeof d=="object")Pe(d,u+".",t,a);else if(typeof d=="string"||typeof d=="number")a(u,d.toString());else if(typeof d=="boolean")a(u,d?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof d}`)})},L=r=>{let e=M(),t=e.stackSave();try{let a=e.stackAlloc(8);e._OrtGetLastError(a,a+4);let o=e.HEAP32[a/4],d=e.HEAPU32[a/4+1],u=d?e.UTF8ToString(d):"";throw new Error(`${r} ERROR_CODE: ${o}, ERROR_MESSAGE: ${u}`)}finally{e.stackRestore(t)}}});var gr,br=P(()=>{"use strict";ve();He();gr=r=>{let e=M(),t=0,a=[],o=r||{};try{if(r?.logSeverityLevel===void 0)o.logSeverityLevel=2;else if(typeof r.logSeverityLevel!="number"||!Number.isInteger(r.logSeverityLevel)||r.logSeverityLevel<0||r.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${r.logSeverityLevel}`);if(r?.logVerbosityLevel===void 0)o.logVerbosityLevel=0;else if(typeof r.logVerbosityLevel!="number"||!Number.isInteger(r.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${r.logVerbosityLevel}`);r?.terminate===void 0&&(o.terminate=!1);let d=0;return r?.tag!==void 0&&(d=R(r.tag,a)),t=e._OrtCreateRunOptions(o.logSeverityLevel,o.logVerbosityLevel,!!o.terminate,d),t===0&&L("Can't create run options."),r?.extra!==void 0&&Pe(r.extra,"",new WeakSet,(u,l)=>{let f=R(u,a),c=R(l,a);e._OrtAddRunConfigEntry(t,f,c)!==0&&L(`Can't set a run config entry: ${u} - ${l}.`)}),[t,a]}catch(d){throw t!==0&&e._OrtReleaseRunOptions(t),a.forEach(u=>e._free(u)),d}}});var pn,mn,hn,yn,Er,vr=P(()=>{"use strict";ve();He();pn=r=>{switch(r){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${r}`)}},mn=r=>{switch(r){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${r}`)}},hn=r=>{r.extra||(r.extra={}),r.extra.session||(r.extra.session={});let e=r.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),r.executionProviders&&r.executionProviders.some(t=>(typeof t=="string"?t:t.name)==="webgpu")&&(r.enableMemPattern=!1)},yn=(r,e,t)=>{for(let a of e){let o=typeof a=="string"?a:a.name;switch(o){case"webnn":if(o="WEBNN",typeof a!="string"){let u=a;if(u?.deviceType){let l=R("deviceType",t),f=R(u.deviceType,t);M()._OrtAddSessionConfigEntry(r,l,f)!==0&&L(`Can't set a session config entry: 'deviceType' - ${u.deviceType}.`)}if(u?.numThreads){let l=u.numThreads;(typeof l!="number"||!Number.isInteger(l)||l<0)&&(l=0);let f=R("numThreads",t),c=R(l.toString(),t);M()._OrtAddSessionConfigEntry(r,f,c)!==0&&L(`Can't set a session config entry: 'numThreads' - ${u.numThreads}.`)}if(u?.powerPreference){let l=R("powerPreference",t),f=R(u.powerPreference,t);M()._OrtAddSessionConfigEntry(r,l,f)!==0&&L(`Can't set a session config entry: 'powerPreference' - ${u.powerPreference}.`)}}break;case"webgpu":if(o="JS",typeof a!="string"){let u=a;if(u?.preferredLayout){if(u.preferredLayout!=="NCHW"&&u.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${u.preferredLayout}`);let l=R("preferredLayout",t),f=R(u.preferredLayout,t);M()._OrtAddSessionConfigEntry(r,l,f)!==0&&L(`Can't set a session config entry: 'preferredLayout' - ${u.preferredLayout}.`)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${o}`)}let d=R(o,t);M()._OrtAppendExecutionProvider(r,d)!==0&&L(`Can't append execution provider: ${o}.`)}},Er=r=>{let e=M(),t=0,a=[],o=r||{};hn(o);try{let d=pn(o.graphOptimizationLevel??"all"),u=mn(o.executionMode??"sequential"),l=typeof o.logId=="string"?R(o.logId,a):0,f=o.logSeverityLevel??2;if(!Number.isInteger(f)||f<0||f>4)throw new Error(`log serverity level is not valid: ${f}`);let c=o.logVerbosityLevel??0;if(!Number.isInteger(c)||c<0||c>4)throw new Error(`log verbosity level is not valid: ${c}`);let y=typeof o.optimizedModelFilePath=="string"?R(o.optimizedModelFilePath,a):0;if(t=e._OrtCreateSessionOptions(d,!!o.enableCpuMemArena,!!o.enableMemPattern,u,!!o.enableProfiling,0,l,f,c,y),t===0&&L("Can't create session options."),o.executionProviders&&yn(t,o.executionProviders,a),o.enableGraphCapture!==void 0){if(typeof o.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${o.enableGraphCapture}`);let w=R("enableGraphCapture",a),h=R(o.enableGraphCapture.toString(),a);e._OrtAddSessionConfigEntry(t,w,h)!==0&&L(`Can't set a session config entry: 'enableGraphCapture' - ${o.enableGraphCapture}.`)}if(o.freeDimensionOverrides)for(let[w,h]of Object.entries(o.freeDimensionOverrides)){if(typeof w!="string")throw new Error(`free dimension override name must be a string: ${w}`);if(typeof h!="number"||!Number.isInteger(h)||h<0)throw new Error(`free dimension override value must be a non-negative integer: ${h}`);let b=R(w,a);e._OrtAddFreeDimensionOverride(t,b,h)!==0&&L(`Can't set a free dimension override: ${w} - ${h}.`)}return o.extra!==void 0&&Pe(o.extra,"",new WeakSet,(w,h)=>{let b=R(w,a),v=R(h,a);e._OrtAddSessionConfigEntry(t,b,v)!==0&&L(`Can't set a session config entry: ${w} - ${h}.`)}),[t,a]}catch(d){throw t!==0&&e._OrtReleaseSessionOptions(t),a.forEach(u=>e._free(u)),d}}});var it,Tr,ut,Or,Ar,$e,Sr,ft=P(()=>{"use strict";it=r=>{switch(r){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float16":return 10;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;default:throw new Error(`unsupported data type: ${r}`)}},Tr=r=>{switch(r){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 10:return"float16";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";default:throw new Error(`unsupported data type: ${r}`)}},ut=r=>[void 0,4,1,1,2,2,4,8,void 0,1,2,8,4,8,void 0,void 0,void 0][r],Or=r=>{switch(r){case"float16":return typeof Float16Array<"u"&&Float16Array.from?Float16Array:Uint16Array;case"float32":return Float32Array;case"uint8":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"bool":return Uint8Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${r}`)}},Ar=r=>{switch(r){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${r}`)}},$e=r=>r==="float32"||r==="float16"||r==="int32"||r==="int64"||r==="uint32"||r==="uint8"||r==="bool",Sr=r=>{switch(r){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;default:throw new Error(`unsupported data location: ${r}`)}}});var Be,lt=P(()=>{"use strict";Be=async r=>{if(typeof r=="string")if(typeof process<"u"&&process.versions&&process.versions.node)try{return new Uint8Array(await(void 0)(r))}catch(e){if(e.code==="ERR_FS_FILE_TOO_LARGE"){let t=(void 0)(r),a=[];for await(let o of t)a.push(o);return new Uint8Array(Buffer.concat(a))}throw e}else{let e=await fetch(r);if(!e.ok)throw new Error(`failed to load external data file: ${r}`);let t=e.headers.get("Content-Length"),a=t?parseInt(t,10):0;if(a<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${r}, no response body.`);let o=e.body.getReader(),d;try{d=new ArrayBuffer(a)}catch(l){if(l instanceof RangeError){let f=Math.ceil(a/65536);d=new WebAssembly.Memory({initial:f,maximum:f}).buffer}else throw l}let u=0;for(;;){let{done:l,value:f}=await o.read();if(l)break;let c=f.byteLength;new Uint8Array(d,u,c).set(f),u+=c}return new Uint8Array(d,0,a)}}else return r instanceof Blob?new Uint8Array(await r.arrayBuffer()):r instanceof Uint8Array?r:new Uint8Array(r)}});var wn,Ir,Pr,Te,gn,ct,Br,Cr,xr,_r,Dr,Ur=P(()=>{"use strict";br();vr();ft();ve();He();lt();wn=(r,e)=>{M()._OrtInit(r,e)!==0&&L("Can't initialize onnxruntime.")},Ir=async r=>{wn(r.wasm.numThreads,Ar(r.logLevel))},Pr=async(r,e)=>{},Te=new Map,gn=r=>{let e=M(),t=e.stackSave();try{let a=e.stackAlloc(8);return e._OrtGetInputOutputCount(r,a,a+4)!==0&&L("Can't get session input/output count."),[e.HEAP32[a/4],e.HEAP32[a/4+1]]}finally{e.stackRestore(t)}},ct=r=>{let e=M(),t=e._malloc(r.byteLength);if(t===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${r.byteLength}.`);return e.HEAPU8.set(r,t),[t,r.byteLength]},Br=async(r,e)=>{let t,a,o=M();Array.isArray(r)?[t,a]=r:r.buffer===o.HEAPU8.buffer?[t,a]=[r.byteOffset,r.byteLength]:[t,a]=ct(r);let d=0,u=0,l=0,f=[],c=[],y=[];try{if([u,f]=Er(e),e?.externalData&&o.mountExternalData){let x=[];for(let B of e.externalData){let W=typeof B=="string"?B:B.path;x.push(Be(typeof B=="string"?B:B.data).then(k=>{o.mountExternalData(W,k)}))}await Promise.all(x)}d=await o._OrtCreateSession(t,a,u),d===0&&L("Can't create a session.");let[w,h]=gn(d),b=!!e?.enableGraphCapture,v=[],O=[],S=[];for(let x=0;x<w;x++){let B=o._OrtGetInputName(d,x);B==