UNPKG

onnxruntime-web

Version:

A Javascript library for running ONNX models on browsers

9 lines 156 kB
/*! * ONNX Runtime Web v1.17.3 * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ "use strict";var ort=(()=>{var br=Object.defineProperty;var Xa=Object.getOwnPropertyDescriptor;var Qa=Object.getOwnPropertyNames;var Za=Object.prototype.hasOwnProperty;var W=(n,r)=>()=>(n&&(r=n(n=0)),r);var ft=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports),lt=(n,r)=>{for(var t in r)br(n,t,{get:r[t],enumerable:!0})},Ka=(n,r,t,u)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of Qa(r))!Za.call(n,a)&&a!==t&&br(n,a,{get:()=>r[a],enumerable:!(u=Xa(r,a))||u.enumerable});return n};var Xe=n=>Ka(br({},"__esModule",{value:!0}),n);var Gt,Qe,ct,eo,$t,zt=W(()=>{"use strict";Gt=new Map,Qe=[],ct=(n,r,t)=>{if(r&&typeof r.init=="function"&&typeof r.createInferenceSessionHandler=="function"){let u=Gt.get(n);if(u===void 0)Gt.set(n,{backend:r,priority:t});else{if(u.priority>t)return;if(u.priority===t&&u.backend!==r)throw new Error(`cannot register backend "${n}" using priority ${t}`)}if(t>=0){let a=Qe.indexOf(n);a!==-1&&Qe.splice(a,1);for(let d=0;d<Qe.length;d++)if(Gt.get(Qe[d]).priority<=t){Qe.splice(d,0,n);return}Qe.push(n)}return}throw new TypeError("not a valid backend")},eo=async n=>{let r=Gt.get(n);if(!r)return"backend not found.";if(r.initialized)return r.backend;if(r.aborted)return r.error;{let t=!!r.initPromise;try{return t||(r.initPromise=r.backend.init(n)),await r.initPromise,r.initialized=!0,r.backend}catch(u){return t||(r.error=`${u}`,r.aborted=!0),r.error}finally{delete r.initPromise}}},$t=async n=>{let r=n.executionProviders||[],t=r.map(m=>typeof m=="string"?m:m.name),u=t.length===0?Qe:t,a,d=[],f=new Set;for(let m of u){let h=await eo(m);typeof h=="string"?d.push({name:m,err:h}):(a||(a=h),a===h&&f.add(m))}if(!a)throw new Error(`no available backend found. ERR: ${d.map(m=>`[${m.name}] ${m.err}`).join(", ")}`);for(let{name:m,err:h}of d)t.includes(m)&&console.warn(`removing requested execution provider "${m}" from session options because it is not available: ${h}`);let s=r.filter(m=>f.has(typeof m=="string"?m:m.name));return[a,new Proxy(n,{get:(m,h)=>h==="executionProviders"?s:Reflect.get(m,h)})]}});var On=W(()=>{"use strict";zt()});var vn,Tn=W(()=>{"use strict";vn="1.17.3"});var _n,ve,Or=W(()=>{"use strict";Tn();_n="warning",ve={wasm:{},webgl:{},webgpu:{},versions:{common:vn},set logLevel(n){if(n!==void 0){if(typeof n!="string"||["verbose","info","warning","error","fatal"].indexOf(n)===-1)throw new Error(`Unsupported logging level: ${n}`);_n=n}},get logLevel(){return _n}};Object.defineProperty(ve,"logLevel",{enumerable:!0})});var Y,En=W(()=>{"use strict";Or();Y=ve});var Sn,An,Mn=W(()=>{"use strict";Sn=(n,r)=>{let t=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);t.width=n.dims[3],t.height=n.dims[2];let u=t.getContext("2d");if(u!=null){let a,d;r?.tensorLayout!==void 0&&r.tensorLayout==="NHWC"?(a=n.dims[2],d=n.dims[3]):(a=n.dims[3],d=n.dims[2]);let f=r?.format!==void 0?r.format:"RGB",s=r?.norm,m,h;s===void 0||s.mean===void 0?m=[255,255,255,255]:typeof s.mean=="number"?m=[s.mean,s.mean,s.mean,s.mean]:(m=[s.mean[0],s.mean[1],s.mean[2],0],s.mean[3]!==void 0&&(m[3]=s.mean[3])),s===void 0||s.bias===void 0?h=[0,0,0,0]:typeof s.bias=="number"?h=[s.bias,s.bias,s.bias,s.bias]:(h=[s.bias[0],s.bias[1],s.bias[2],0],s.bias[3]!==void 0&&(h[3]=s.bias[3]));let y=d*a,O=0,b=y,M=y*2,P=-1;f==="RGBA"?(O=0,b=y,M=y*2,P=y*3):f==="RGB"?(O=0,b=y,M=y*2):f==="RBG"&&(O=0,M=y,b=y*2);for(let A=0;A<d;A++)for(let S=0;S<a;S++){let B=(n.data[O++]-h[0])*m[0],L=(n.data[b++]-h[1])*m[1],k=(n.data[M++]-h[2])*m[2],$=P===-1?255:(n.data[P++]-h[3])*m[3];u.fillStyle="rgba("+B+","+L+","+k+","+$+")",u.fillRect(S,A,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")},An=(n,r)=>{let t=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),u;if(t!=null){let a,d,f;r?.tensorLayout!==void 0&&r.tensorLayout==="NHWC"?(a=n.dims[2],d=n.dims[1],f=n.dims[3]):(a=n.dims[3],d=n.dims[2],f=n.dims[1]);let s=r!==void 0&&r.format!==void 0?r.format:"RGB",m=r?.norm,h,y;m===void 0||m.mean===void 0?h=[255,255,255,255]:typeof m.mean=="number"?h=[m.mean,m.mean,m.mean,m.mean]:(h=[m.mean[0],m.mean[1],m.mean[2],255],m.mean[3]!==void 0&&(h[3]=m.mean[3])),m===void 0||m.bias===void 0?y=[0,0,0,0]:typeof m.bias=="number"?y=[m.bias,m.bias,m.bias,m.bias]:(y=[m.bias[0],m.bias[1],m.bias[2],0],m.bias[3]!==void 0&&(y[3]=m.bias[3]));let O=d*a;if(r!==void 0&&(r.format!==void 0&&f===4&&r.format!=="RGBA"||f===3&&r.format!=="RGB"&&r.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let b=4,M=0,P=1,A=2,S=3,B=0,L=O,k=O*2,$=-1;s==="RGBA"?(B=0,L=O,k=O*2,$=O*3):s==="RGB"?(B=0,L=O,k=O*2):s==="RBG"&&(B=0,k=O,L=O*2),u=t.createImageData(a,d);for(let j=0;j<d*a;M+=b,P+=b,A+=b,S+=b,j++)u.data[M]=(n.data[B++]-y[0])*h[0],u.data[P]=(n.data[L++]-y[1])*h[1],u.data[A]=(n.data[k++]-y[2])*h[2],u.data[S]=$===-1?255:(n.data[$++]-y[3])*h[3]}else throw new Error("Can not access image data");return u}});var vr,Cn,Pn,Rn,xn,In=W(()=>{"use strict";jt();vr=(n,r)=>{if(n===void 0)throw new Error("Image buffer must be defined");if(r.height===void 0||r.width===void 0)throw new Error("Image height and width must be defined");if(r.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:t,width:u}=r,a=r.norm??{mean:255,bias:0},d,f;typeof a.mean=="number"?d=[a.mean,a.mean,a.mean,a.mean]:d=[a.mean[0],a.mean[1],a.mean[2],a.mean[3]??255],typeof a.bias=="number"?f=[a.bias,a.bias,a.bias,a.bias]:f=[a.bias[0],a.bias[1],a.bias[2],a.bias[3]??0];let s=r.format!==void 0?r.format:"RGBA",m=r.tensorFormat!==void 0&&r.tensorFormat!==void 0?r.tensorFormat:"RGB",h=t*u,y=m==="RGBA"?new Float32Array(h*4):new Float32Array(h*3),O=4,b=0,M=1,P=2,A=3,S=0,B=h,L=h*2,k=-1;s==="RGB"&&(O=3,b=0,M=1,P=2,A=-1),m==="RGBA"?k=h*3:m==="RBG"?(S=0,L=h,B=h*2):m==="BGR"&&(L=0,B=h,S=h*2);for(let j=0;j<h;j++,b+=O,P+=O,M+=O,A+=O)y[S++]=(n[b]+f[0])/d[0],y[B++]=(n[M]+f[1])/d[1],y[L++]=(n[P]+f[2])/d[2],k!==-1&&A!==-1&&(y[k++]=(n[A]+f[3])/d[3]);return m==="RGBA"?new ge("float32",y,[1,4,t,u]):new ge("float32",y,[1,3,t,u])},Cn=async(n,r)=>{let t=typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement,u=typeof ImageData<"u"&&n instanceof ImageData,a=typeof ImageBitmap<"u"&&n instanceof ImageBitmap,d=typeof n=="string",f,s=r??{},m=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},h=y=>y instanceof HTMLCanvasElement||y instanceof OffscreenCanvas?y.getContext("2d"):null;if(t){let y=m();y.width=n.width,y.height=n.height;let O=h(y);if(O!=null){let b=n.height,M=n.width;if(r!==void 0&&r.resizedHeight!==void 0&&r.resizedWidth!==void 0&&(b=r.resizedHeight,M=r.resizedWidth),r!==void 0){if(s=r,r.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");s.tensorFormat="RGBA",s.height=b,s.width=M}else s.tensorFormat="RGBA",s.height=b,s.width=M;O.drawImage(n,0,0),f=O.getImageData(0,0,M,b).data}else throw new Error("Can not access image data")}else if(u){let y,O;if(r!==void 0&&r.resizedWidth!==void 0&&r.resizedHeight!==void 0?(y=r.resizedHeight,O=r.resizedWidth):(y=n.height,O=n.width),r!==void 0&&(s=r),s.format="RGBA",s.height=y,s.width=O,r!==void 0){let b=m();b.width=O,b.height=y;let M=h(b);if(M!=null)M.putImageData(n,0,0),f=M.getImageData(0,0,O,y).data;else throw new Error("Can not access image data")}else f=n.data}else if(a){if(r===void 0)throw new Error("Please provide image config with format for Imagebitmap");let y=m();y.width=n.width,y.height=n.height;let O=h(y);if(O!=null){let b=n.height,M=n.width;return O.drawImage(n,0,0,M,b),f=O.getImageData(0,0,M,b).data,s.height=b,s.width=M,vr(f,s)}else throw new Error("Can not access image data")}else{if(d)return new Promise((y,O)=>{let b=m(),M=h(b);if(!n||!M)return O();let P=new Image;P.crossOrigin="Anonymous",P.src=n,P.onload=()=>{b.width=P.width,b.height=P.height,M.drawImage(P,0,0,b.width,b.height);let A=M.getImageData(0,0,b.width,b.height);s.height=b.height,s.width=b.width,y(vr(A.data,s))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(f!==void 0)return vr(f,s);throw new Error("Input data provided is not supported - aborted tensor creation")},Pn=(n,r)=>{let{width:t,height:u,download:a,dispose:d}=r,f=[1,u,t,4];return new ge({location:"texture",type:"float32",texture:n,dims:f,download:a,dispose:d})},Rn=(n,r)=>{let{dataType:t,dims:u,download:a,dispose:d}=r;return new ge({location:"gpu-buffer",type:t??"float32",gpuBuffer:n,dims:u,download:a,dispose:d})},xn=(n,r,t)=>new ge({location:"cpu-pinned",type:n,data:r,dims:t??[r.length]})});var Ze,St,Dn,Un,Bn=W(()=>{"use strict";Ze=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array]]),St=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Dn=!1,Un=()=>{if(!Dn){Dn=!0;let n=typeof BigInt64Array<"u"&&BigInt64Array.from,r=typeof BigUint64Array<"u"&&BigUint64Array.from,t=typeof Float16Array<"u"&&Float16Array.from;n&&(Ze.set("int64",BigInt64Array),St.set(BigInt64Array,"int64")),r&&(Ze.set("uint64",BigUint64Array),St.set(BigUint64Array,"uint64")),t?(Ze.set("float16",Float16Array),St.set(Float16Array,"float16")):Ze.set("float16",Uint16Array)}}});var Fn,kn,Ln=W(()=>{"use strict";jt();Fn=n=>{let r=1;for(let t=0;t<n.length;t++){let u=n[t];if(typeof u!="number"||!Number.isSafeInteger(u))throw new TypeError(`dims[${t}] must be an integer, got: ${u}`);if(u<0)throw new RangeError(`dims[${t}] must be a non-negative integer, got: ${u}`);r*=u}return r},kn=(n,r)=>{switch(n.location){case"cpu":return new ge(n.type,n.data,r);case"cpu-pinned":return new ge({location:"cpu-pinned",data:n.data,type:n.type,dims:r});case"texture":return new ge({location:"texture",texture:n.texture,type:n.type,dims:r});case"gpu-buffer":return new ge({location:"gpu-buffer",gpuBuffer:n.gpuBuffer,type:n.type,dims:r});default:throw new Error(`tensorReshape: tensor location ${n.location} is not supported`)}}});var ge,jt=W(()=>{"use strict";Mn();In();Bn();Ln();ge=class{constructor(r,t,u){Un();let a,d;if(typeof r=="object"&&"location"in r)switch(this.dataLocation=r.location,a=r.type,d=r.dims,r.location){case"cpu-pinned":{let s=Ze.get(a);if(!s)throw new TypeError(`unsupported type "${a}" to create tensor from pinned buffer`);if(!(r.data instanceof s))throw new TypeError(`buffer should be of type ${s.name}`);this.cpuData=r.data;break}case"texture":{if(a!=="float32")throw new TypeError(`unsupported type "${a}" to create tensor from texture`);this.gpuTextureData=r.texture,this.downloader=r.download,this.disposer=r.dispose;break}case"gpu-buffer":{if(a!=="float32"&&a!=="float16"&&a!=="int32"&&a!=="int64"&&a!=="uint32"&&a!=="uint8"&&a!=="bool")throw new TypeError(`unsupported type "${a}" to create tensor from gpu buffer`);this.gpuBufferData=r.gpuBuffer,this.downloader=r.download,this.disposer=r.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let s,m;if(typeof r=="string")if(a=r,m=u,r==="string"){if(!Array.isArray(t))throw new TypeError("A string tensor's data must be a string array.");s=t}else{let h=Ze.get(r);if(h===void 0)throw new TypeError(`Unsupported tensor type: ${r}.`);if(Array.isArray(t)){if(r==="float16"&&h===Uint16Array)throw new TypeError("Creating a float16 tensor from number array is not supported. Please use Uint16Array as data.");r==="uint64"||r==="int64"?s=h.from(t,BigInt):s=h.from(t)}else if(t instanceof h)s=t;else throw new TypeError(`A ${a} tensor's data must be type of ${h}`)}else if(m=t,Array.isArray(r)){if(r.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let h=typeof r[0];if(h==="string")a="string",s=r;else if(h==="boolean")a="bool",s=Uint8Array.from(r);else throw new TypeError(`Invalid element type of data array: ${h}.`)}else{let h=St.get(r.constructor);if(h===void 0)throw new TypeError(`Unsupported type for tensor data: ${r.constructor}.`);a=h,s=r}if(m===void 0)m=[s.length];else if(!Array.isArray(m))throw new TypeError("A tensor's dims must be a number array");d=m,this.cpuData=s,this.dataLocation="cpu"}let f=Fn(d);if(this.cpuData&&f!==this.cpuData.length)throw new Error(`Tensor's size(${f}) does not match data length(${this.cpuData.length}).`);this.type=a,this.dims=d,this.size=f}static async fromImage(r,t){return Cn(r,t)}static fromTexture(r,t){return Pn(r,t)}static fromGpuBuffer(r,t){return Rn(r,t)}static fromPinnedBuffer(r,t,u){return xn(r,t,u)}toDataURL(r){return Sn(this,r)}toImageData(r){return An(this,r)}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(r){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,r&&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(r){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return kn(this,r)}}});var ce,Yt=W(()=>{"use strict";jt();ce=ge});var Tr,Nn,$e,ze,_r=W(()=>{"use strict";Or();Tr=(n,r)=>{(typeof ve.trace>"u"?!ve.wasm.trace:!ve.trace)||console.timeStamp(`${n}::ORT::${r}`)},Nn=(n,r)=>{let t=new Error().stack?.split(/\r\n|\r|\n/g)||[],u=!1;for(let a=0;a<t.length;a++){if(u&&!t[a].includes("TRACE_FUNC")){let d=`FUNC_${n}::${t[a].trim().split(" ")[1]}`;r&&(d+=`::${r}`),Tr("CPU",d);return}t[a].includes("TRACE_FUNC")&&(u=!0)}},$e=n=>{(typeof ve.trace>"u"?!ve.wasm.trace:!ve.trace)||Nn("BEGIN",n)},ze=n=>{(typeof ve.trace>"u"?!ve.wasm.trace:!ve.trace)||Nn("END",n)}});var Vt,Hn=W(()=>{"use strict";zt();Yt();_r();Vt=class n{constructor(r){this.handler=r}async run(r,t,u){$e();let a={},d={};if(typeof r!="object"||r===null||r instanceof ce||Array.isArray(r))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let f=!0;if(typeof t=="object"){if(t===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(t instanceof ce)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.");f=!1;for(let h of t){if(typeof h!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(h)===-1)throw new RangeError(`'fetches' contains invalid output name: ${h}.`);a[h]=null}if(typeof u=="object"&&u!==null)d=u;else if(typeof u<"u")throw new TypeError("'options' must be an object.")}else{let h=!1,y=Object.getOwnPropertyNames(t);for(let O of this.outputNames)if(y.indexOf(O)!==-1){let b=t[O];(b===null||b instanceof ce)&&(h=!0,f=!1,a[O]=b)}if(h){if(typeof u=="object"&&u!==null)d=u;else if(typeof u<"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 h of this.inputNames)if(typeof r[h]>"u")throw new Error(`input '${h}' is missing in 'feeds'.`);if(f)for(let h of this.outputNames)a[h]=null;let s=await this.handler.run(r,a,d),m={};for(let h in s)if(Object.hasOwnProperty.call(s,h)){let y=s[h];y instanceof ce?m[h]=y:m[h]=new ce(y.type,y.data,y.dims)}return ze(),m}async release(){return this.handler.dispose()}static async create(r,t,u,a){$e();let d,f={};if(typeof r=="string"){if(d=r,typeof t=="object"&&t!==null)f=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(r instanceof Uint8Array){if(d=r,typeof t=="object"&&t!==null)f=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(r instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&r instanceof SharedArrayBuffer){let y=r,O=0,b=r.byteLength;if(typeof t=="object"&&t!==null)f=t;else if(typeof t=="number"){if(O=t,!Number.isSafeInteger(O))throw new RangeError("'byteOffset' must be an integer.");if(O<0||O>=y.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${y.byteLength}).`);if(b=r.byteLength-O,typeof u=="number"){if(b=u,!Number.isSafeInteger(b))throw new RangeError("'byteLength' must be an integer.");if(b<=0||O+b>y.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${y.byteLength-O}].`);if(typeof a=="object"&&a!==null)f=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else if(typeof u<"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,O,b)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[s,m]=await $t(f),h=await s.createInferenceSessionHandler(d,m);return ze(),new n(h)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}});var Wn,Gn=W(()=>{"use strict";Hn();Wn=Vt});var $n=W(()=>{"use strict"});var zn=W(()=>{"use strict"});var jn=W(()=>{"use strict"});var Yn=W(()=>{"use strict"});var to,qt,Vn=W(()=>{"use strict";zt();Yt();to="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",qt=class n{constructor(r,t,u){this.handler=r,this.hasOptimizerModel=t,this.hasEvalModel=u}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(r,t){let u=r.evalModel||"",a=r.optimizerModel||"",d=t||{},[f,s]=await $t(d);if(f.createTrainingSessionHandler){let m=await f.createTrainingSessionHandler(r.checkpointState,r.trainModel,u,a,s);return new n(m,!!r.optimizerModel,!!r.evalModel)}else throw new Error(to)}typeNarrowingForRunStep(r,t,u,a,d){let f={},s={};if(typeof u!="object"||u===null||u instanceof ce||Array.isArray(u))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let m=!0;if(typeof a=="object"){if(a===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(a instanceof ce)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(a)){if(a.length===0)throw new TypeError("'fetches' cannot be an empty array.");m=!1;for(let h of a){if(typeof h!="string")throw new TypeError("'fetches' must be a string array or an object.");if(t.indexOf(h)===-1)throw new RangeError(`'fetches' contains invalid output name: ${h}.`);f[h]=null}if(typeof d=="object"&&d!==null)s=d;else if(typeof d<"u")throw new TypeError("'options' must be an object.")}else{let h=!1,y=Object.getOwnPropertyNames(a);for(let O of t)if(y.indexOf(O)!==-1){let b=a[O];(b===null||b instanceof ce)&&(h=!0,m=!1,f[O]=b)}if(h){if(typeof d=="object"&&d!==null)s=d;else if(typeof d<"u")throw new TypeError("'options' must be an object.")}else s=a}}else if(typeof a<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let h of r)if(typeof u[h]>"u")throw new Error(`input '${h}' is missing in 'feeds'.`);if(m)for(let h of t)f[h]=null;return[f,s]}convertHandlerReturnTypeToMapOfTensors(r){let t={};for(let u in r)if(Object.hasOwnProperty.call(r,u)){let a=r[u];a instanceof ce?t[u]=a:t[u]=new ce(a.type,a.data,a.dims)}return t}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(r,t,u){let[a,d]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,r,t,u),f=await this.handler.runTrainStep(r,a,d);return this.convertHandlerReturnTypeToMapOfTensors(f)}async runOptimizerStep(r){if(this.hasOptimizerModel)await this.handler.runOptimizerStep(r||{});else throw new Error("This TrainingSession has no OptimizerModel loaded.")}async runEvalStep(r,t,u){if(this.hasEvalModel){let[a,d]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,r,t,u),f=await this.handler.runEvalStep(r,a,d);return this.convertHandlerReturnTypeToMapOfTensors(f)}else throw new Error("This TrainingSession has no EvalModel loaded.")}async getParametersSize(r=!0){return this.handler.getParametersSize(r)}async loadParametersBuffer(r,t=!0){let u=await this.getParametersSize(t);if(r.length!==4*u)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(r,t)}async getContiguousParameters(r=!0){return this.handler.getContiguousParameters(r)}async release(){return this.handler.dispose()}}});var qn,Jn=W(()=>{"use strict";Vn();qn=qt});var Er={};lt(Er,{InferenceSession:()=>Wn,TRACE:()=>Tr,TRACE_FUNC_BEGIN:()=>$e,TRACE_FUNC_END:()=>ze,Tensor:()=>ce,TrainingSession:()=>qn,env:()=>Y,registerBackend:()=>ct});var Ke=W(()=>{"use strict";On();En();Gn();Yt();$n();zn();_r();jn();Yn();Jn()});var Sr={};lt(Sr,{createReadStream:()=>Qn,readFile:()=>ro,readFileSync:()=>no});var ro,no,Qn,Ar=W(()=>{ro=void 0,no=void 0,Qn=void 0});var Mr={};lt(Mr,{join:()=>ao});var ao,Cr=W(()=>{ao=void 0});var ea=ft((Kn,Pr)=>{"use strict";var Zn=(()=>{var n=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return typeof __filename<"u"&&(n=n||__filename),function(r={}){var t=r,u,a;t.ready=new Promise((o,c)=>{u=o,a=c});var d=Object.assign({},t),f="./this.program",s=typeof window=="object",m=typeof importScripts=="function",h=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",y="",O,b,M;if(h){var P=(Ar(),Xe(Sr)),A=(Cr(),Xe(Mr));y=m?A.dirname(y)+"/":__dirname+"/",O=(o,c)=>(o=Pe(o)?new URL(o):A.normalize(o),P.readFileSync(o,c?void 0:"utf8")),M=o=>(o=O(o,!0),o.buffer||(o=new Uint8Array(o)),o),b=(o,c,p,w=!0)=>{o=Pe(o)?new URL(o):A.normalize(o),P.readFile(o,w?void 0:"utf8",(C,I)=>{C?p(C):c(w?I.buffer:I)})},!t.thisProgram&&1<process.argv.length&&(f=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2),t.inspect=()=>"[Emscripten Module object]"}else(s||m)&&(m?y=self.location.href:typeof document<"u"&&document.currentScript&&(y=document.currentScript.src),n&&(y=n),y.indexOf("blob:")!==0?y=y.substr(0,y.replace(/[?#].*/,"").lastIndexOf("/")+1):y="",O=o=>{var c=new XMLHttpRequest;return c.open("GET",o,!1),c.send(null),c.responseText},m&&(M=o=>{var c=new XMLHttpRequest;return c.open("GET",o,!1),c.responseType="arraybuffer",c.send(null),new Uint8Array(c.response)}),b=(o,c,p)=>{var w=new XMLHttpRequest;w.open("GET",o,!0),w.responseType="arraybuffer",w.onload=()=>{w.status==200||w.status==0&&w.response?c(w.response):p()},w.onerror=p,w.send(null)});var S=console.log.bind(console),B=console.error.bind(console);Object.assign(t,d),d=null,typeof WebAssembly!="object"&&N("no native wasm support detected");var L,k=!1,$,j,x,q,Fe;function We(){var o=L.buffer;t.HEAP8=$=new Int8Array(o),t.HEAP16=new Int16Array(o),t.HEAPU8=j=new Uint8Array(o),t.HEAPU16=new Uint16Array(o),t.HEAP32=x=new Int32Array(o),t.HEAPU32=q=new Uint32Array(o),t.HEAPF32=new Float32Array(o),t.HEAPF64=Fe=new Float64Array(o)}var me=[],se=[],ne=[],Ce=0,_e=null,ie=null;function N(o){throw o="Aborted("+o+")",B(o),k=!0,o=new WebAssembly.RuntimeError(o+". Build with -sASSERTIONS for more info."),a(o),o}var Ee=o=>o.startsWith("data:application/octet-stream;base64,"),Pe=o=>o.startsWith("file://"),de;if(de="ort-training-wasm-simd.wasm",!Ee(de)){var Re=de;de=t.locateFile?t.locateFile(Re,y):y+Re}function Z(o){if(M)return M(o);throw"both async and sync fetching of the wasm failed"}function ye(o){if(s||m){if(typeof fetch=="function"&&!Pe(o))return fetch(o,{credentials:"same-origin"}).then(c=>{if(!c.ok)throw"failed to load wasm binary file at '"+o+"'";return c.arrayBuffer()}).catch(()=>Z(o));if(b)return new Promise((c,p)=>{b(o,w=>c(new Uint8Array(w)),p)})}return Promise.resolve().then(()=>Z(o))}function je(o,c,p){return ye(o).then(w=>WebAssembly.instantiate(w,c)).then(w=>w).then(p,w=>{B(`failed to asynchronously prepare wasm: ${w}`),N(w)})}function xe(o,c){var p=de;return typeof WebAssembly.instantiateStreaming!="function"||Ee(p)||Pe(p)||h||typeof fetch!="function"?je(p,o,c):fetch(p,{credentials:"same-origin"}).then(w=>WebAssembly.instantiateStreaming(w,o).then(c,function(C){return B(`wasm streaming compile failed: ${C}`),B("falling back to ArrayBuffer instantiation"),je(p,o,c)}))}var Se,Ae={990528:(o,c,p,w)=>{if(typeof t>"u"||!t.Qa)return 1;if(o=K(o>>>0),o.startsWith("./")&&(o=o.substring(2)),o=t.Qa.get(o),!o)return 2;if(c>>>=0,p>>>=0,c+p>o.byteLength)return 3;try{return j.set(o.subarray(c,c+p),w>>>0>>>0),0}catch{return 4}}};function Ye(o){this.Ka=o-24,this.Pa=function(c){q[this.Ka+4>>>2>>>0]=c},this.Oa=function(c){q[this.Ka+8>>>2>>>0]=c},this.Ma=function(c,p){this.Na(),this.Pa(c),this.Oa(p)},this.Na=function(){q[this.Ka+16>>>2>>>0]=0}}var we=0,Ie=0,ke=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,oe=(o,c,p)=>{c>>>=0;var w=c+p;for(p=c;o[p]&&!(p>=w);)++p;if(16<p-c&&o.buffer&&ke)return ke.decode(o.subarray(c,p));for(w="";c<p;){var C=o[c++];if(C&128){var I=o[c++]&63;if((C&224)==192)w+=String.fromCharCode((C&31)<<6|I);else{var H=o[c++]&63;C=(C&240)==224?(C&15)<<12|I<<6|H:(C&7)<<18|I<<12|H<<6|o[c++]&63,65536>C?w+=String.fromCharCode(C):(C-=65536,w+=String.fromCharCode(55296|C>>10,56320|C&1023))}}else w+=String.fromCharCode(C)}return w},K=(o,c)=>(o>>>=0)?oe(j,o,c):"",pe=o=>{for(var c=0,p=0;p<o.length;++p){var w=o.charCodeAt(p);127>=w?c++:2047>=w?c+=2:55296<=w&&57343>=w?(c+=4,++p):c+=3}return c},Le=(o,c,p,w)=>{if(p>>>=0,!(0<w))return 0;var C=p;w=p+w-1;for(var I=0;I<o.length;++I){var H=o.charCodeAt(I);if(55296<=H&&57343>=H){var ae=o.charCodeAt(++I);H=65536+((H&1023)<<10)|ae&1023}if(127>=H){if(p>=w)break;c[p++>>>0]=H}else{if(2047>=H){if(p+1>=w)break;c[p++>>>0]=192|H>>6}else{if(65535>=H){if(p+2>=w)break;c[p++>>>0]=224|H>>12}else{if(p+3>=w)break;c[p++>>>0]=240|H>>18,c[p++>>>0]=128|H>>12&63}c[p++>>>0]=128|H>>6&63}c[p++>>>0]=128|H&63}}return c[p>>>0]=0,p-C},De=o=>o%4===0&&(o%100!==0||o%400===0),yt=[0,31,60,91,121,152,182,213,244,274,305,335],Dt=[0,31,59,90,120,151,181,212,243,273,304,334],Ne=o=>{var c=pe(o)+1,p=Bt(c);return p&&Le(o,j,p,c),p},nt=[],Ge={},at=()=>{if(!ot){var o={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",_:f||"./this.program"},c;for(c in Ge)Ge[c]===void 0?delete o[c]:o[c]=Ge[c];var p=[];for(c in o)p.push(`${c}=${o[c]}`);ot=p}return ot},ot,Ve=[null,[],[]],wt=[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 st(o){var c=Array(pe(o)+1);return Le(o,c,0,c.length),c}function Ut(o,c,p,w){function C(v,z,Q){for(v=typeof v=="number"?v.toString():v||"";v.length<z;)v=Q[0]+v;return v}function I(v,z){return C(v,z,"0")}function H(v,z){function Q(Et){return 0>Et?-1:0<Et?1:0}var Ue;return(Ue=Q(v.getFullYear()-z.getFullYear()))===0&&(Ue=Q(v.getMonth()-z.getMonth()))===0&&(Ue=Q(v.getDate()-z.getDate())),Ue}function ae(v){switch(v.getDay()){case 0:return new Date(v.getFullYear()-1,11,29);case 1:return v;case 2:return new Date(v.getFullYear(),0,3);case 3:return new Date(v.getFullYear(),0,2);case 4:return new Date(v.getFullYear(),0,1);case 5:return new Date(v.getFullYear()-1,11,31);case 6:return new Date(v.getFullYear()-1,11,30)}}function he(v){var z=v.Ga;for(v=new Date(new Date(v.Ha+1900,0,1).getTime());0<z;){var Q=v.getMonth(),Ue=(De(v.getFullYear())?wt:bt)[Q];if(z>Ue-v.getDate())z-=Ue-v.getDate()+1,v.setDate(1),11>Q?v.setMonth(Q+1):(v.setMonth(0),v.setFullYear(v.getFullYear()+1));else{v.setDate(v.getDate()+z);break}}return Q=new Date(v.getFullYear()+1,0,4),z=ae(new Date(v.getFullYear(),0,4)),Q=ae(Q),0>=H(z,v)?0>=H(Q,v)?v.getFullYear()+1:v.getFullYear():v.getFullYear()-1}o>>>=0,c>>>=0,p>>>=0,w>>>=0;var fe=q[w+40>>>2>>>0];w={Ta:x[w>>>2>>>0],Sa:x[w+4>>>2>>>0],Ia:x[w+8>>>2>>>0],La:x[w+12>>>2>>>0],Ja:x[w+16>>>2>>>0],Ha:x[w+20>>>2>>>0],Ba:x[w+24>>>2>>>0],Ga:x[w+28>>>2>>>0],Va:x[w+32>>>2>>>0],Ra:x[w+36>>>2>>>0],Ua:fe?K(fe):""},p=K(p),fe={"%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 le in fe)p=p.replace(new RegExp(le,"g"),fe[le]);var Tt="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),_t="January February March April May June July August September October November December".split(" ");fe={"%a":v=>Tt[v.Ba].substring(0,3),"%A":v=>Tt[v.Ba],"%b":v=>_t[v.Ja].substring(0,3),"%B":v=>_t[v.Ja],"%C":v=>I((v.Ha+1900)/100|0,2),"%d":v=>I(v.La,2),"%e":v=>C(v.La,2," "),"%g":v=>he(v).toString().substring(2),"%G":v=>he(v),"%H":v=>I(v.Ia,2),"%I":v=>(v=v.Ia,v==0?v=12:12<v&&(v-=12),I(v,2)),"%j":v=>{for(var z=0,Q=0;Q<=v.Ja-1;z+=(De(v.Ha+1900)?wt:bt)[Q++]);return I(v.La+z,3)},"%m":v=>I(v.Ja+1,2),"%M":v=>I(v.Sa,2),"%n":()=>` `,"%p":v=>0<=v.Ia&&12>v.Ia?"AM":"PM","%S":v=>I(v.Ta,2),"%t":()=>" ","%u":v=>v.Ba||7,"%U":v=>I(Math.floor((v.Ga+7-v.Ba)/7),2),"%V":v=>{var z=Math.floor((v.Ga+7-(v.Ba+6)%7)/7);if(2>=(v.Ba+371-v.Ga-2)%7&&z++,z)z==53&&(Q=(v.Ba+371-v.Ga)%7,Q==4||Q==3&&De(v.Ha)||(z=1));else{z=52;var Q=(v.Ba+7-v.Ga-1)%7;(Q==4||Q==5&&De(v.Ha%400-1))&&z++}return I(z,2)},"%w":v=>v.Ba,"%W":v=>I(Math.floor((v.Ga+7-(v.Ba+6)%7)/7),2),"%y":v=>(v.Ha+1900).toString().substring(2),"%Y":v=>v.Ha+1900,"%z":v=>{v=v.Ra;var z=0<=v;return v=Math.abs(v)/60,(z?"+":"-")+("0000"+(v/60*100+v%60)).slice(-4)},"%Z":v=>v.Ua,"%%":()=>"%"},p=p.replace(/%%/g,"\0\0");for(le in fe)p.includes(le)&&(p=p.replace(new RegExp(le,"g"),fe[le](w)));return p=p.replace(/\0\0/g,"%"),le=st(p),le.length>c?0:($.set(le,o>>>0),le.length-1)}var J={a:function(o,c,p){throw o>>>=0,new Ye(o).Ma(c>>>0,p>>>0),we=o,Ie++,we},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(o,c,p){o=c+2097152>>>0<4194305-!!o?(o>>>0)+4294967296*c:NaN,p>>>=0,o=new Date(1e3*o),x[p>>>2>>>0]=o.getUTCSeconds(),x[p+4>>>2>>>0]=o.getUTCMinutes(),x[p+8>>>2>>>0]=o.getUTCHours(),x[p+12>>>2>>>0]=o.getUTCDate(),x[p+16>>>2>>>0]=o.getUTCMonth(),x[p+20>>>2>>>0]=o.getUTCFullYear()-1900,x[p+24>>>2>>>0]=o.getUTCDay(),x[p+28>>>2>>>0]=(o.getTime()-Date.UTC(o.getUTCFullYear(),0,1,0,0,0,0))/864e5|0},o:function(o,c,p){o=c+2097152>>>0<4194305-!!o?(o>>>0)+4294967296*c:NaN,p>>>=0,o=new Date(1e3*o),x[p>>>2>>>0]=o.getSeconds(),x[p+4>>>2>>>0]=o.getMinutes(),x[p+8>>>2>>>0]=o.getHours(),x[p+12>>>2>>>0]=o.getDate(),x[p+16>>>2>>>0]=o.getMonth(),x[p+20>>>2>>>0]=o.getFullYear()-1900,x[p+24>>>2>>>0]=o.getDay(),x[p+28>>>2>>>0]=(De(o.getFullYear())?yt:Dt)[o.getMonth()]+o.getDate()-1|0,x[p+36>>>2>>>0]=-(60*o.getTimezoneOffset()),c=new Date(o.getFullYear(),6,1).getTimezoneOffset();var w=new Date(o.getFullYear(),0,1).getTimezoneOffset();x[p+32>>>2>>>0]=(c!=w&&o.getTimezoneOffset()==Math.min(w,c))|0},p:function(o){o>>>=0;var c=new Date(x[o+20>>>2>>>0]+1900,x[o+16>>>2>>>0],x[o+12>>>2>>>0],x[o+8>>>2>>>0],x[o+4>>>2>>>0],x[o>>>2>>>0],0),p=x[o+32>>>2>>>0],w=c.getTimezoneOffset(),C=new Date(c.getFullYear(),6,1).getTimezoneOffset(),I=new Date(c.getFullYear(),0,1).getTimezoneOffset(),H=Math.min(I,C);return 0>p?x[o+32>>>2>>>0]=+(C!=I&&H==w):0<p!=(H==w)&&(C=Math.max(I,C),c.setTime(c.getTime()+6e4*((0<p?H:C)-w))),x[o+24>>>2>>>0]=c.getDay(),x[o+28>>>2>>>0]=(De(c.getFullYear())?yt:Dt)[c.getMonth()]+c.getDate()-1|0,x[o>>>2>>>0]=c.getSeconds(),x[o+4>>>2>>>0]=c.getMinutes(),x[o+8>>>2>>>0]=c.getHours(),x[o+12>>>2>>>0]=c.getDate(),x[o+16>>>2>>>0]=c.getMonth(),x[o+20>>>2>>>0]=c.getYear(),o=c.getTime(),isNaN(o)?(x[it()>>>2>>>0]=61,o=-1):o/=1e3,Ot((Se=o,1<=+Math.abs(Se)?0<Se?+Math.floor(Se/4294967296)>>>0:~~+Math.ceil((Se-+(~~Se>>>0))/4294967296)>>>0:0)),o>>>0},l:function(){return-52},m:function(){},t:function(o,c,p){function w(he){return(he=he.toTimeString().match(/\(([A-Za-z ]+)\)$/))?he[1]:"GMT"}p>>>=0;var C=new Date().getFullYear(),I=new Date(C,0,1),H=new Date(C,6,1);C=I.getTimezoneOffset();var ae=H.getTimezoneOffset();q[o>>>0>>>2>>>0]=60*Math.max(C,ae),x[c>>>0>>>2>>>0]=+(C!=ae),o=w(I),c=w(H),o=Ne(o),c=Ne(c),ae<C?(q[p>>>2>>>0]=o,q[p+4>>>2>>>0]=c):(q[p>>>2>>>0]=c,q[p+4>>>2>>>0]=o)},d:()=>{N("")},B:function(o,c,p){o>>>=0,c>>>=0,p>>>=0,nt.length=0;for(var w;w=j[c++>>>0];){var C=w!=105;C&=w!=112,p+=C&&p%8?4:0,nt.push(w==112?q[p>>>2>>>0]:w==105?x[p>>>2>>>0]:Fe[p>>>3>>>0]),p+=C?8:4}return Ae[o].apply(null,nt)},h:()=>Date.now(),u:function(){return 4294901760},b:()=>performance.now(),I:function(o,c,p){return c>>>=0,j.copyWithin(o>>>0>>>0,c>>>0,c+(p>>>0)>>>0)},s:function(o){o>>>=0;var c=j.length;if(4294901760<o)return!1;for(var p=1;4>=p;p*=2){var w=c*(1+.2/p);w=Math.min(w,o+100663296);var C=Math;w=Math.max(o,w);e:{C=(C.min.call(C,4294901760,w+(65536-w%65536)%65536)-L.buffer.byteLength+65535)/65536;try{L.grow(C),We();var I=1;break e}catch{}I=void 0}if(I)return!0}return!1},C:function(o,c){o>>>=0,c>>>=0;var p=0;return at().forEach((w,C)=>{var I=c+p;for(C=q[o+4*C>>>2>>>0]=I,I=0;I<w.length;++I)$[C++>>>0>>>0]=w.charCodeAt(I);$[C>>>0>>>0]=0,p+=w.length+1}),0},D:function(o,c){o>>>=0,c>>>=0;var p=at();q[o>>>2>>>0]=p.length;var w=0;return p.forEach(C=>w+=C.length+1),q[c>>>2>>>0]=w,0},f:()=>52,j:function(){return 52},q:function(){return 70},i:function(o,c,p,w){c>>>=0,p>>>=0,w>>>=0;for(var C=0,I=0;I<p;I++){var H=q[c>>>2>>>0],ae=q[c+4>>>2>>>0];c+=8;for(var he=0;he<ae;he++){var fe=j[H+he>>>0],le=Ve[o];fe===0||fe===10?((o===1?S:B)(oe(le,0)),le.length=0):le.push(fe)}C+=ae}return q[w>>>2>>>0]=C,0},r:Ut,c:function(o,c,p,w){return Ut(o>>>0,c>>>0,p>>>0,w>>>0)}},D=function(){function o(p){return D=p.exports,D=kt(),L=D.K,We(),se.unshift(D.L),Ce--,Ce==0&&(_e!==null&&(clearInterval(_e),_e=null),ie&&(p=ie,ie=null,p())),D}var c={a:J};if(Ce++,t.instantiateWasm)try{return t.instantiateWasm(c,o)}catch(p){B(`Module.instantiateWasm callback failed with error: ${p}`),a(p)}return xe(c,function(p){o(p.instance)}).catch(a),{}}();t._OrtInit=(o,c)=>(t._OrtInit=D.M)(o,c),t._OrtGetLastError=(o,c)=>(t._OrtGetLastError=D.N)(o,c),t._OrtCreateSessionOptions=(o,c,p,w,C,I,H,ae,he,fe)=>(t._OrtCreateSessionOptions=D.O)(o,c,p,w,C,I,H,ae,he,fe),t._OrtAppendExecutionProvider=(o,c)=>(t._OrtAppendExecutionProvider=D.P)(o,c),t._OrtAddFreeDimensionOverride=(o,c,p)=>(t._OrtAddFreeDimensionOverride=D.Q)(o,c,p),t._OrtAddSessionConfigEntry=(o,c,p)=>(t._OrtAddSessionConfigEntry=D.R)(o,c,p),t._OrtReleaseSessionOptions=o=>(t._OrtReleaseSessionOptions=D.S)(o),t._OrtCreateSession=(o,c,p)=>(t._OrtCreateSession=D.T)(o,c,p),t._OrtReleaseSession=o=>(t._OrtReleaseSession=D.U)(o),t._OrtGetInputOutputCount=(o,c,p)=>(t._OrtGetInputOutputCount=D.V)(o,c,p),t._OrtGetInputName=(o,c)=>(t._OrtGetInputName=D.W)(o,c),t._OrtGetOutputName=(o,c)=>(t._OrtGetOutputName=D.X)(o,c),t._OrtFree=o=>(t._OrtFree=D.Y)(o),t._OrtCreateTensor=(o,c,p,w,C,I)=>(t._OrtCreateTensor=D.Z)(o,c,p,w,C,I),t._OrtGetTensorData=(o,c,p,w,C)=>(t._OrtGetTensorData=D._)(o,c,p,w,C),t._OrtReleaseTensor=o=>(t._OrtReleaseTensor=D.$)(o),t._OrtCreateRunOptions=(o,c,p,w)=>(t._OrtCreateRunOptions=D.aa)(o,c,p,w),t._OrtAddRunConfigEntry=(o,c,p)=>(t._OrtAddRunConfigEntry=D.ba)(o,c,p),t._OrtReleaseRunOptions=o=>(t._OrtReleaseRunOptions=D.ca)(o),t._OrtCreateBinding=o=>(t._OrtCreateBinding=D.da)(o),t._OrtBindInput=(o,c,p)=>(t._OrtBindInput=D.ea)(o,c,p),t._OrtBindOutput=(o,c,p,w)=>(t._OrtBindOutput=D.fa)(o,c,p,w),t._OrtClearBoundOutputs=o=>(t._OrtClearBoundOutputs=D.ga)(o),t._OrtReleaseBinding=o=>(t._OrtReleaseBinding=D.ha)(o),t._OrtRunWithBinding=(o,c,p,w,C)=>(t._OrtRunWithBinding=D.ia)(o,c,p,w,C),t._OrtRun=(o,c,p,w,C,I,H,ae)=>(t._OrtRun=D.ja)(o,c,p,w,C,I,H,ae),t._OrtEndProfiling=o=>(t._OrtEndProfiling=D.ka)(o),t._OrtTrainingLoadCheckpoint=(o,c)=>(t._OrtTrainingLoadCheckpoint=D.la)(o,c),t._OrtTrainingReleaseCheckpoint=o=>(t._OrtTrainingReleaseCheckpoint=D.ma)(o),t._OrtTrainingCreateSession=(o,c,p,w,C,I,H,ae)=>(t._OrtTrainingCreateSession=D.na)(o,c,p,w,C,I,H,ae),t._OrtTrainingLazyResetGrad=o=>(t._OrtTrainingLazyResetGrad=D.oa)(o),t._OrtTrainingRunTrainStep=(o,c,p,w,C,I)=>(t._OrtTrainingRunTrainStep=D.pa)(o,c,p,w,C,I),t._OrtTrainingOptimizerStep=(o,c)=>(t._OrtTrainingOptimizerStep=D.qa)(o,c),t._OrtTrainingEvalStep=(o,c,p,w,C,I)=>(t._OrtTrainingEvalStep=D.ra)(o,c,p,w,C,I),t._OrtTrainingGetParametersSize=(o,c,p)=>(t._OrtTrainingGetParametersSize=D.sa)(o,c,p),t._OrtTrainingCopyParametersToBuffer=(o,c,p,w)=>(t._OrtTrainingCopyParametersToBuffer=D.ta)(o,c,p,w),t._OrtTrainingCopyParametersFromBuffer=(o,c,p,w)=>(t._OrtTrainingCopyParametersFromBuffer=D.ua)(o,c,p,w),t._OrtTrainingGetModelInputOutputCount=(o,c,p,w)=>(t._OrtTrainingGetModelInputOutputCount=D.va)(o,c,p,w),t._OrtTrainingGetModelInputOutputName=(o,c,p,w)=>(t._OrtTrainingGetModelInputOutputName=D.wa)(o,c,p,w),t._OrtTrainingReleaseSession=o=>(t._OrtTrainingReleaseSession=D.xa)(o);var it=()=>(it=D.ya)(),Bt=t._malloc=o=>(Bt=t._malloc=D.za)(o);t._free=o=>(t._free=D.Aa)(o);var Ot=o=>(Ot=D.Ca)(o),Ft=()=>(Ft=D.Da)(),F=o=>(F=D.Ea)(o),qe=o=>(qe=D.Fa)(o);function kt(){var o=D;o=Object.assign({},o);var c=w=>()=>w()>>>0,p=w=>C=>w(C)>>>0;return o.ya=c(o.ya),o.za=p(o.za),o.Da=c(o.Da),o.Fa=p(o.Fa),o}t.stackAlloc=qe,t.stackSave=Ft,t.stackRestore=F,t.UTF8ToString=K,t.stringToUTF8=(o,c,p)=>Le(o,j,c,p),t.lengthBytesUTF8=pe;var He;ie=function o(){He||vt(),He||(ie=o)};function vt(){if(!(0<Ce)){if(t.preRun)for(typeof t.preRun=="function"&&(t.preRun=[t.preRun]);t.preRun.length;){var o=t.preRun.shift();me.unshift(o)}for(;0<me.length;)me.shift()(t);if(!(0<Ce||He||(He=!0,t.calledRun=!0,k))){for(;0<se.length;)se.shift()(t);for(u(t);0<ne.length;)ne.shift()(t)}}}return vt(),r.ready}})();typeof Kn=="object"&&typeof Pr=="object"?Pr.exports=Zn:typeof define=="function"&&define.amd&&define([],()=>Zn)});var ta=ft(()=>{});var ra=ft(()=>{});var na={};lt(na,{cpus:()=>oo});var oo,aa=W(()=>{oo=void 0});var ia=ft((sa,Rr)=>{"use strict";var oa=(()=>{var n=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return typeof __filename<"u"&&(n=n||__filename),function(r={}){function t(){return ne.buffer!=N.buffer&&Z(),N}function u(){return ne.buffer!=N.buffer&&Z(),Ee}function a(){return ne.buffer!=N.buffer&&Z(),Pe}function d(){return ne.buffer!=N.buffer&&Z(),de}function f(){return ne.buffer!=N.buffer&&Z(),Re}var s=r,m,h;s.ready=new Promise((e,i)=>{m=e,h=i});var y=Object.assign({},s),O="./this.program",b=(e,i)=>{throw i},M=typeof window=="object",P=typeof importScripts=="function",A=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",S=s.ENVIRONMENT_IS_PTHREAD||!1,B="";function L(e){return s.locateFile?s.locateFile(e,B):B+e}var k,$,j;if(A){var x=(Ar(),Xe(Sr)),q=(Cr(),Xe(Mr));B=P?q.dirname(B)+"/":__dirname+"/",k=(i,l)=>(i=K(i)?new URL(i):q.normalize(i),x.readFileSync(i,l?void 0:"utf8")),j=i=>(i=k(i,!0),i.buffer||(i=new Uint8Array(i)),i),$=(i,l,g,_=!0)=>{i=K(i)?new URL(i):q.normalize(i),x.readFile(i,_?void 0:"utf8",(E,R)=>{E?g(E):l(_?R.buffer:R)})},!s.thisProgram&&1<process.argv.length&&(O=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2),b=(i,l)=>{throw process.exitCode=i,l},s.inspect=()=>"[Emscripten Module object]";let e;try{e=ta()}catch(i){throw console.error('The "worker_threads" module is not supported in this node.js build - perhaps a newer version is needed?'),i}global.Worker=e.Worker}else(M||P)&&(P?B=self.location.href:typeof document<"u"&&document.currentScript&&(B=document.currentScript.src),typeof n<"u"&&n&&(B=n),B.indexOf("blob:")!==0?B=B.substr(0,B.replace(/[?#].*/,"").lastIndexOf("/")+1):B="",A||(k=e=>{var i=new XMLHttpRequest;return i.open("GET",e,!1),i.send(null),i.responseText},P&&(j=e=>{var i=new XMLHttpRequest;return i.open("GET",e,!1),i.responseType="arraybuffer",i.send(null),new Uint8Array(i.response)}),$=(e,i,l)=>{var g=new XMLHttpRequest;g.open("GET",e,!0),g.responseType="arraybuffer",g.onload=()=>{g.status==200||g.status==0&&g.response?i(g.response):l()},g.onerror=l,g.send(null)}));A&&typeof performance>"u"&&(global.performance=ra().performance);var Fe=console.log.bind(console),We=console.error.bind(console);A&&(Fe=(...e)=>x.writeSync(1,e.join(" ")+` `),We=(...e)=>x.writeSync(2,e.join(" ")+` `));var me=Fe,se=We;Object.assign(s,y),y=null,typeof WebAssembly!="object"&&ke("no native wasm support detected");var ne,Ce,_e=!1,ie,N,Ee,Pe,de,Re;function Z(){var e=ne.buffer;s.HEAP8=N=new Int8Array(e),s.HEAP16=new Int16Array(e),s.HEAPU8=Ee=new Uint8Array(e),s.HEAPU16=new Uint16Array(e),s.HEAP32=Pe=new Int32Array(e),s.HEAPU32=de=new Uint32Array(e),s.HEAPF32=new Float32Array(e),s.HEAPF64=Re=new Float64Array(e)}var ye=16777216;if(S)ne=s.wasmMemory;else if(s.wasmMemory)ne=s.wasmMemory;else if(ne=new WebAssembly.Memory({initial:ye/65536,maximum:65536,shared:!0}),!(ne.buffer instanceof SharedArrayBuffer))throw se("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),A&&se("(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and/or recent version)"),Error("bad memory");Z(),ye=ne.buffer.byteLength;var je=[],xe=[],Se=[],Ae=0,Ye=null,we=null;function Ie(){if(Ae--,Ae==0&&(Ye!==null&&(clearInterval(Ye),Ye=null),we)){var e=we;we=null,e()}}function ke(e){throw e="Aborted("+e+")",se(e),_e=!0,ie=1,e=new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info."),h(e),e}var oe=e=>e.startsWith("data:application/octet-stream;base64,"),K=e=>e.startsWith("file://"),pe;pe="ort-wasm-threaded.wasm",oe(pe)||(pe=L(pe));function Le(e){if(j)return j(e);throw"both async and sync fetching of the wasm failed"}function De(e){if(M||P){if(typeof fetch=="function"&&!K(e))return fetch(e,{credentials:"same-origin"}).then(i=>{if(!i.ok)throw"failed to load wasm binary file at '"+e+"'";return i.arrayBuffer()}).catch(()=>Le(e));if($)return new Promise((i,l)=>{$(e,g=>i(new Uint8Array(g)),l)})}return Promise.resolve().then(()=>Le(e))}function yt(e,i,l){return De(e).then(g=>WebAssembly.instantiate(g,i)).then(g=>g).then(l,g=>{se(`failed to asynchronously prepare wasm: ${g}`),ke(g)})}function Dt(e,i){var l=pe;return typeof WebAssembly.instantiateStreaming!="function"||oe(l)||K(l)||A||typeof fetch!="function"?yt(l,e,i):fetch(l,{credentials:"same-origin"}).then(g=>WebAssembly.instantiateStreaming(g,e).then(i,function(_){return se(`wasm streaming compile failed: ${_}`),se("falling back to ArrayBuffer instantiation"),yt(l,e,i)}))}var Ne,nt={921388:(e,i,l,g)=>{if(typeof s>"u"||!s.cb)return 1;if(e=st(e>>>0),e.startsWith("./")&&(e=e.substring(2)),e=s.cb.get(e),!e)return 2;if(i>>>=0,l>>>=0,g>>>=0,i+l>e.byteLength)return 3;try{return u().set(e.subarray(i,i+l),g>>>0),0}catch{return 4}}};function Ge(e){this.name="ExitStatus",this.message=`Program terminated with exit(${e})`,this.status=e}var at=e=>{e.terminate(),e.onmessage=()=>{}},ot=e=>{F.Pa.length==0&&(Ot(),F.Ya(F.Pa[0]));var i=F.Pa.pop();if(!i)return 6;F.Qa.push(i),F.Ma[e.Oa]=i,i.Oa=e.Oa;var l={cmd:"run",start_routine:e.kb,arg:e.hb,pthread_ptr:e.Oa};return A&&i.unref(),i.postMessage(l,e.qb),0},Ve=0,wt=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,bt=(e,i,l)=>{i>>>=0;var g=i+l;for(l=i;e[l]&&!(l>=g);)++l;if(16<l-i&&e.buffer&&wt)return wt.decode(e.buffer instanceof SharedArrayBuffer?e.slice(i,l):e.subarray(i,l));for(g="";i<l;){var _=e[i++];if(_&128){var E=e[i++]&63;if((_&224)==192)g+=String.fromCharCode((_&31)<<6|E);else{var R=e[i++]&63;_=(_&240)==224?(_&15)<<12|E<<6|R:(_&7)<<18|E<<12|R<<6|e[i++]&63,65536>_?g+=String.fromCharCode(_):(_-=65536,g+=String.fromCharCode(55296|_>>10,56320|_&1023))}}else g+=String.fromCharCode(_)}return g},st=(e,i)=>(e>>>=0)?bt(u(),e,i):"",Ut=e=>{var i=yr();return e=e(),Ht(i),e};function J(e,i){var l=arguments.length-2,g=arguments;return Ut(()=>{for(var _=wr(8*l),E=_>>>3,R=0;R<l;R++){var te=g[2+R];f()[E+R>>>0]=te}return dn(e,l,_,i)})}function D(e){if(S)return J(0,1,e);ie=e,0<Ve||(F.lb(),s.onExit?.(e),_e=!0),b(e,new Ge(e))}var it=e=>{if(ie=e,S)throw kt(e),"unwind";D(e)};function Bt(){for(var e=s.numThreads;e--;)Ot();je.unshift(()=>{Ae++,Ft(()=>Ie())})}function Ot(){var e=L("ort-wasm-threaded.worker.js");e=new Worker(e),F.Pa.push(e)}function Ft(e){S?e():Promise.all(F.Pa.map(F.Ya)).then(e)}var F={Pa:[],Qa:[],bb:[],Ma:{},Wa(){S?(F.receiveObjectTransfer=F.jb,F.threadInitTLS=F.ab,F.setExitStatus=F.$a):Bt()},$a:e=>ie=e,tb:["$terminateWorker"],lb:()=>{for(var e of F.Qa)at(e);for(e of F.Pa)at(e);F.Pa=[],F.Qa=[],F.Ma=[]},Za:e=>{var i=e.Oa;delete F.Ma[i],F.Pa.push(e),F.Qa.splice(F.Qa.indexOf(e),1),e.Oa=0,hr(i)},jb(){},ab(){F.bb.forEach(e=>e())},Ya:e=>new Promise(i=>{e.onmessage=E=>{E=E.data;var R=E.cmd;if(E.targetThread&&E.targetThread!=Nt()){var te=F.Ma[E.targetThread];te?te.postMessage(E,E.transferList):se(`Internal error! Worker sent a message "${R}" to target pthread ${E.targetThread}, but that thread no longer exists!`)}else R==="checkMailbox"?Lt():R==="spawnThread"?ot(E):R==="cleanupThread"?F.Za(F.Ma[E.thread]):R==="killThread"?(E=E.thread,R=F.Ma[E],delete F.Ma[E],at(R),hr(E),F.Qa.splice(F.Qa.indexOf(R),1),R.Oa=0):R==="cancelThread"?F.Ma[E.thread].postMessage({cmd:"cancel"}):R==="loaded"?(e.loaded=!0,A&&!e.Oa&&e.unref(),i(e)):R==="alert"?alert(`Thread ${E.threadId}: ${E.text}`):E.target==="setimmediate"?e.postMessage(E):R==="callHandler"?s[E.handler](...E.args):R&&se(`worker sent an unknown command ${R}`)},e.onerror=E=>{throw se(`worker sent an error! ${E.filename}:${E.lineno}: ${E.message}`),E},A&&(e.on("message",E=>e.onmessage({data:E})),e.on("error",E=>e.onerror(E)));var l=[],g=["onExit"],_;for(_ of g)s.hasOwnProperty(_)&&l.push(_);e.postMessage({cmd:"load",handlers:l,urlOrBlob:s.mainScriptUrlOrBlob||n,wasmMemory:ne,wasmModule:Ce})})};s.PThread=F;var qe=e=>{for(;0<e.length;)e.shift()(s)};s.establishStackSpace=()=>{var e=Nt(),i=d()[e+52>>>2>>>0];e=d()[e+56>>>2>>>0],hn(i,i-e),Ht(i)};function kt(e){if(S)return J(1,0,e);it(e)}var He=[],vt;s.invokeEntryPoint=(e,i)=>{var l=He[e];l||(e>=He.length&&(He.length=e+1),He[e]=l=vt.get(e)),e=l(i),0<Ve?F.$a(e):gr(e)};function o(e){this.Va=e-24,this.gb=function(i){d()[this.Va+4>>>2>>>0]=i},this.fb=function(i){d()[this.Va+8>>>2>>>0]=i},this.Wa=function(i,l){this.eb(),this.gb(i),this.fb(l)},this.eb=function(){d()[this.Va+16>>>2>>>0]=0}}var c=0,p=0;function w(e,i,l,g){return S?J(2,1,e,i,l,g):C(e,i,l,g)}function C(e,i,l,g){if(e>>>=0,i>>>=0,l>>>=0,g>>>=0,typeof SharedArrayBuffer>"u")return se("Current environment does not support SharedArrayBuffer, pthreads are not available!"),6;var _=[];return S&&_.length===0?w(e,i,l,g):(e={kb:l,Oa:e,hb:g,qb:_},S?(e.sb="spawnThread",postMessage(e,_),0):ot(e))}function I(e,i,l){return S?J(3,1,e,i,l):0}function H(e,i){if(S)return J(4,1,e,i)}var ae=e=>{for(var i=0,l=0;l<e.length;++l){var g=e.charCodeAt(l);127>=g?i++:2047>=g?i+=2:55296<=g&&57343>=g?(i+=4,++l):i+=3}return i},he=(e,i,l,g)=>{if(l>>>=0,!(0<g))return 0;var _=l;g=l+g-1;for(var E=0;E<e.length;++E){var R=e.charCodeAt(E);if(55296<=R&&57343>=R){var te=e.charCodeAt(++E);R=65536+((R&1023)<<10)|te&1023}if(127>=R){if(l>=g)break;i[l++>>>0]=R}else{if(2047>=R){if(l+1>=g)break;i[l++>>>0]=192|R>>6}else{if(65535>=R){if(l+2>=g)break;i[l++>>>0]=224|R>>12}else{if(l+3>=g)break;i[l++>>>0]=240|R>>18,i[l++>>>0]=128|R>>12&63}i[l++>>>0]=128|R>>6&63}i[l++>>>0]=128|R&63}}return i[l>>>0]=0,l-_},fe=(e,i,l)=>he(e,u(),i,l);function le(e,i){if(S)return J(5,1,e,i)}function Tt(e,i,l){if(S)return J(6,1,e,i,l)}function _t(e,i,l){return S?J(7,1,e,i,l):0}function v(e,i){if(S)return J(8,1,e,i)}function z(e,i,l){if(S)return J(9,1,e,i,l)}function Q(e,i,l,g){if(S)return J(10,1,e,i,l,g)}function Ue(e,i,l,g){if(S)return J(11,1,e,i,l,g)}function Et(e,i,l,g){if(S)return J(12,1,e,i,l,g)}function zr(e){if(S)return J(13,1,e)}function jr(e,i){if(S)return J(14,1,e,i)}function Yr(e,i,l){if(S)return J(15,1,e,i,l)}function lr(e){e>>>=0,typeof Atomics.rb=="function"&&(Atomics.rb(a(),e>>>2,e).value.then(Lt),e+=128,Atomics.store(a(),e>>>2,1))}s.__emscripten_thread_mailbox_await=lr;var Lt=()=>{var e=Nt();if(e&&(lr(e),e=pn,