varHuman=(()=>{vareR=Object.defineProperty;varJg=e=>{if(typeofrequire!="undefined")returnrequire(e);thrownewError('Dynamic require of "'+e+'" is not supported')};varQg=(e,t)=>{for(varnint)eR(e,n,{get:t[n],enumerable:!0})};varR3=(e,t,n)=>{if(!t.has(e))throwTypeError("Cannot "+n)};varFn=(e,t,n)=>(R3(e,t,"read from private field"),n?n.call(e):t.get(e)),wa=(e,t,n)=>{if(t.has(e))throwTypeError("Cannot add the same private member more than once");tinstanceofWeakSet?t.add(e):t.set(e,n)},Ja=(e,t,n,a)=>(R3(e,t,"write to private field"),a?a.call(e,n):t.set(e,n),n);varhwe={};Qg(hwe,{Human:()=>h$,default:()=>h$});functionMt(e,t){letn=e.endsWith("/")?"":"/",r=t.startsWith(".")||t.startsWith("/")||t.startsWith("http:")||t.startsWith("https:")||t.startsWith("file:")?`${t}`:`${e}${n}${t}`;if(!r.toLocaleLowerCase().includes(".json"))thrownewError(`Human: ModelPath Error: ${r} Expecting JSON file`);returnr}functionge(...e){lett=newDate,n=`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`;e&&console.log(n,"Human:",...e)}varst=()=>typeofperformance!="undefined"?performance.now():parseInt((Number(process.hrtime.bigint())/1e3/1e3).toString());functionia(...e){lett=n=>n&&typeofn=="object";returne.reduce((n,a)=>(Object.keys(a||{}).forEach(r=>{lets=n[r],i=a[r];Array.isArray(s)&&Array.isArray(i)?n[r]=s.concat(...i):t(s)&&t(i)?n[r]=ia(s,i):n[r]=i}),n),{})}varF3={backend:"webgl",modelBasePath:"../models/",wasmPath:"../node_modules/@tensorflow/tfjs-backend-wasm/dist/",debug:!0,async:!0,warmup:"full",cacheSensitivity:.75,skipFrame:!1,filter:{enabled:!0,width:0,height:0,flip:!1,return:!0,brightness:0,contrast:0,sharpness:0,blur:0,saturation:0,hue:0,negative:!1,sepia:!1,vintage:!1,kodachrome:!1,technicolor:!1,polaroid:!1,pixelate:0},gesture:{enabled:!0},face:{enabled:!0,detector:{modelPath:"blazeface.json",rotation:!0,maxDetected:15,skipFrames:15,minConfidence:.2,iouThreshold:.1,return:!1},mesh:{enabled:!0,modelPath:"facemesh.json"},iris:{enabled:!0,modelPath:"iris.json"},description:{enabled:!0,modelPath:"faceres.json",skipFrames:11,minConfidence:.1},emotion:{enabled:!0,minConfidence:.1,skipFrames:17,modelPath:"emotion.json"}},body:{enabled:!0,modelPath:"movenet-lightning.json",maxDetected:1,minConfidence:.2,skipFrames:1},hand:{enabled:!0,rotation:!0,skipFrames:18,minConfidence:.1,iouThreshold:.1,maxDetected:2,landmarks:!0,detector:{modelPath:"handdetect.json"},skeleton:{modelPath:"handskeleton.json"}},object:{enabled:!1,modelPath:"mb3-centernet.json",minConfidence:.2,iouThreshold:.4,maxDetected:10,skipFrames:19},segmentation:{enabled:!1,modelPath:"selfie.json"}};functionO3(){lete,t;if(typeofnavigator!="undefined"){letn=navigator.userAgent.match(/\(([^()]+)\)/g);if(n&&n[0]){leta=n[0].match(/\(([^()]+)\)/g);e=a?a[0].replace(/\(|\)/g,""):"",t=navigator.userAgent.replace(n[0],""),e[1]&&(t=t.replace(n[1],"")),t=t.replace(/ /g," ")}}elsetypeofprocess!="undefined"&&(e=`${process.platform}${process.arch}`,t=`NodeJS ${process.version}`);return{platform:e,agent:t}}varbp={};Qg(bp,{Abs:()=>Q3,Acos:()=>ev,Acosh:()=>tv,AdadeltaOptimizer:()=>Oc,AdagradOptimizer:()=>Dc,AdamOptimizer:()=>_c,AdamaxOptimizer:()=>zc,Add:()=>oy,AddN:()=>nv,All:()=>av,Any:()=>rv,ArgMax:()=>sv,ArgMin:()=>iv,Asin:()=>ov,Asinh:()=>lv,Atan:()=>uv,Atan2:()=>hv,Atanh:()=>dv,AvgPool:()=>pv,AvgPool3D:()=>cv,AvgPool3DGrad:()=>sF,AvgPoolGrad:()=>rF,BackendWasm:()=>uM,BatchMatMul:()=>fv,BatchToSpaceND:()=>mv,Bincount:()=>gv,BroadcastTo:()=>iF,Callback:()=>PS,CallbackList:()=>NI,Cast:()=>ly,Ceil:()=>yv,ClipByValue:()=>Av,Complex:()=>xv,ComplexAbs:()=>bv,Concat:()=>vv,Conv2D:()=>wv,Conv2DBackpropFilter:()=>kv,Conv2DBackpropInput:()=>Iv,Conv3D:()=>Sv,Conv3DBackpropFilterV2:()=>oF,Conv3DBackpropInputV2:()=>Nv,Cos:()=>Tv,Cosh:()=>Ev,CropAndResize:()=>Mv,Cumsum:()=>Cv,CustomCallback:()=>EI,DataStorage:()=>zR,DenseBincount:()=>$v,DepthToSpace:()=>Rv,DepthwiseConv2dNative:()=>Fv,DepthwiseConv2dNativeBackpropFilter:()=>Ov,DepthwiseC
`;return p[p.length-1]=" "+p[p.length-1]+"]"+(s?"":m),p}function nd(e){let t=[];for(let n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}var uc=class{constructor(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=Jt(e),n!=null){let a=n.length;L(a===this.size,()=>`Lengthofvalues'${a}'doesnotmatchthesizeinferredbytheshape'${this.size}'.`)}if(t==="complex64")throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=n||U3(t,this.size),this.strides=_o(e)}set(e,...t){t.length===0&&(t=[0]),L(t.length===this.rank,()=>`Thenumberofprovidedcoordinates(${t.length})mustmatchtherank(${this.rank})`);let n=this.locToIndex(t);this.values[n]=e}get(...e){e.length===0&&(e=[0]);let t=0;for(let a of e){if(a<0||a>=this.shape[t]){let r=`Requestedoutofrangeelementat${e}.Buffershape=${this.shape}`;throw new Error(r)}t++}let n=e[e.length-1];for(let a=0;a<e.length-1;++a)n+=this.strides[a]*e[a];return this.values[n]}locToIndex(e){if(this.rank===0)return 0;if(this.rank===1)return e[0];let t=e[e.length-1];for(let n=0;n<e.length-1;++n)t+=this.strides[n]*e[n];return t}indexToLoc(e){if(this.rank===0)return[];if(this.rank===1)return[e];let t=new Array(this.shape.length);for(let n=0;n<t.length-1;++n)t[n]=Math.floor(e/this.strides[n]),e-=t[n]*this.strides[n];return t[t.length-1]=e,t}get rank(){return this.shape.length}toTensor(){return kr().makeTensor(this.values,this.shape,this.dtype)}},kr=null,Wo=null,PF=null;function LF(e){kr=e}function WF(e){Wo=e}function BF(e){PF=e}var St=class{constructor(e,t,n,a){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=Jt(e),this.strides=_o(e),this.dataId=n,this.id=a,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){let e=await this.data();return Wo.buffer(this.shape,this.dtype,e)}bufferSync(){return Wo.buffer(this.shape,this.dtype,this.dataSync())}async array(){let e=await this.data();return zo(this.shape,e,this.dtype==="complex64")}arraySync(){return zo(this.shape,this.dataSync(),this.dtype==="complex64")}async data(){this.throwIfDisposed();let e=kr().read(this.dataId);if(this.dtype==="string"){let t=await e;try{return t.map(n=>oc(n))}catch(n){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}}return e}dataSync(){this.throwIfDisposed();let e=kr().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>oc(t))}catch(t){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return e}async bytes(){this.throwIfDisposed();let e=await kr().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){this.isDisposed||(kr().disposeTensor(this),this.isDisposedInternal=!0)}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return Wo.print(this,e)}clone(){return this.throwIfDisposed(),Wo.clone(this)}toString(e=!1){let t=this.dataSync();return _F(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),Wo.cast(this,e)}variable(e=!0,t,n){return this.throwIfDisposed(),kr().makeVariable(this,e,t,n)}};Object.defineProperty(St,Symbol.hasInstance,{value:e=>!!e&&e.data!=null&&e.dataSync!=null&&e.throwIfDisposed!=null});function VF(){return iy("Tensor",()=>St)}VF();var ad=class extends St{constructor(e,t,n,a){super(e.shape,e.dtype,e.dataId,a);this.trainable=t,this.name=n}assign(e){if(e.dtype!==this.dtype)throw new Error(`dtypeofthenewvalue(${e.dtype})andpreviousvalue(${this.dtype})mustmatch`);if(!Kr(e.shape,this.shape))throw new Error(`shapeofthenewvalue(${e.shape})andpreviousvalue(${this.shape})mustmatch`);kr().disposeTensor(this),this.dataId=e.dataId,kr().incRef(this,null)}dispose(){kr().disposeVariable(this),this.isDisposedInternal=!0}};Object.defineProperty(ad,Symbol.hasInstance,{value:e=>e instanceof St&&e.as
ManifestJSONhasweightswithnames:${o.join(", ")}.`)}let l=r.reduce((c,m,f)=>(m&&c.push(f),c),[]),u=[];l.forEach(c=>{t[c].paths.forEach(m=>{let f=n+(n.endsWith("/")?"":"/")+m;u.push(f)})});let d=await e(u),h={},p=0;return l.forEach(c=>{let m=t[c].paths.length,f=0;for(let x=0;x<m;x++)f+=d[p+x].byteLength;let g=new ArrayBuffer(f),y=new Uint8Array(g),A=0;for(let x=0;x<m;x++){let v=new Uint8Array(d[p+x]);y.set(v,A),A+=v.byteLength}s[c].forEach(x=>{let v=g.slice(x.groupOffset,x.groupOffset+x.sizeBytes),b=Y7(v,[x.manifestEntry]);for(let w in b)h[w]=b[w]}),p+=m}),h}}var LO="application/octet-stream",WO="application/json",_y=class{constructor(e,t){if(this.DEFAULT_METHOD="POST",t==null&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.onProgress=t.onProgress,this.weightUrlConverter=t.weightUrlConverter,t.fetchFunc!=null?(L(typeof t.fetchFunc=="function",()=>"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"),this.fetch=t.fetchFunc):this.fetch=ht().platform.fetch,L(e!=null&&e.length>0,()=>"URL path for http must not be null, undefined or empty."),Array.isArray(e)&&L(e.length===2,()=>`URLpathsforhttpmusthavealengthof2,(actuallengthis${e.length}).`),this.path=e,t.requestInit!=null&&t.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=t.requestInit||{}}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");let t=Object.assign({method:this.DEFAULT_METHOD},this.requestInit);t.body=new FormData;let n=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],a={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,weightsManifest:n};e.signature!=null&&(a.signature=e.signature),e.userDefinedMetadata!=null&&(a.userDefinedMetadata=e.userDefinedMetadata),e.modelInitializer!=null&&(a.modelInitializer=e.modelInitializer),t.body.append("model.json",new Blob([JSON.stringify(a)],{type:WO}),"model.json"),e.weightData!=null&&t.body.append("model.weights.bin",new Blob([e.weightData],{type:LO}),"model.weights.bin");let r=await this.fetch(this.path,t);if(r.ok)return{modelArtifactsInfo:sd(e),responses:[r]};throw new Error(`BrowserHTTPRequest.save()failedduetoHTTPresponsestatus${r.status}.`)}async load(){let e=await this.fetch(this.path,this.requestInit);if(!e.ok)throw new Error(`Requestto${this.path}failedwithstatuscode${e.status}.PleaseverifythisURLpointstothemodelJSONofthemodeltoload.`);let t;try{t=await e.json()}catch(c){let m=`FailedtoparsemodelJSONofresponsefrom${this.path}.`;throw this.path.endsWith(".pb")?m+=" Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository.":m+=" Please make sure the server is serving valid JSON for this request.",new Error(m)}let n=t.modelTopology,a=t.weightsManifest,r=t.generatedBy,s=t.convertedBy,i=t.format,o=t.signature,l=t.userDefinedMetadata;if(n==null&&a==null)throw new Error(`TheJSONfromHTTPpath${this.path}containsneithermodeltopologyormanifestforweights.`);let u,d;a!=null&&([u,d]=await this.loadWeights(a));let h={modelTopology:n,weightSpecs:u,weightData:d,generatedBy:r,convertedBy:s,format:i};o!=null&&(h.signature=o),l!=null&&(h.userDefinedMetadata=l);let p=t.modelInitializer;return p&&(h.modelInitializer=p),h}async loadWeights(e){let t=Array.isArray(this.path)?this.path[1]:this.path,[n,a]=BO(t),r=this.weightPathPrefix||n,s=[];for(let u of e)s.push(...u.weights);let i=[],o=[];for(let u of e)for(let d of u.paths)this.weightUrlConverter!=null?o.push(this.weightUrlConverter(d)):i.push(r+d+a);this.weightUrlConverter&&i.push(...await Promise.all(o));let l=await dk(i,{requestInit:thi
Actual:${r}.
Expected:${s}.`);for(let i=0;i<s.length;++i){let o=r[i],l=s[i];if(!n(o,l))throw new Error(`Arraysdiffer:actual[${i}]=${o},expected[${i}]=${l}.
Actual:${r}.
Expected:${s}.`)}}function hD(e,t){e().then(()=>t.fail(),()=>t())}function pD(e,t){let n=typeof t=="string"||typeof t=="number"||typeof t=="boolean"?[t]:t;return Is(e)||Is(e[0])||Is(t)||Is(t[0])?Hy(e,n,(a,r)=>a==r):Hy(e,t,(a,r)=>Gy(a,r,0))}function cD(e,t,n){if(n==null&&(n=jy()),!Gy(e,t,n))throw new Error(`Numbersdiffer:actual===${e},expected===${t}`)}function Gy(e,t,n){return!isFinite(e)&&!isFinite(t)?!0:!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}function fD(e,t,n){for(let a=0;a<e.length;a++)if(e[a]<t||e[a]>n)throw new Error(`Valueoutofrange:${e[a]}low:${t},high:${n}`)}function mD(e,t){expect(new Float32Array(e)).toEqual(new Float32Array(t))}function Fk(e){for(let t=0;t<e.length;t++){let n=e[t];Array.isArray(n)?Fk(n):e[t]=Qu(n)}return e}var gD="3.7.0";function yD(){ht().set("PROD",!0)}function AD(){ht().set("DEBUG",!0)}function xD(){ht().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")}function Ok(e){ht().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(e+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}BF(Ok);function bD(){V.disposeVariables()}function vD(){return V}function wD(){return V.memory()}function kD(e){return V.profile(e)}function Ue(e,t){return V.tidy(e,t)}function Ve(e){Iy(e).forEach(t=>t.dispose())}function Dk(e){return V.keep(e)}function ID(e){return V.time(e)}function SD(e){return V.setBackend(e)}function ND(){return V.ready()}function TD(){return V.backendName}function ED(e){V.removeBackend(e)}function qy(e){return V.findBackend(e)}function CD(e){return V.findBackendFactory(e)}function Ky(e,t,n=1){return V.registerBackend(e,t,n)}function MD(){return V.backend}function $D(e,t){ht().setPlatform(e,t)}function RD(e,t){let n=O(e,"a","add"),a=O(t,"b","add");[n,a]=Vt(n,a);let r={a:n,b:a};return V.runKernel(oy,r)}var De=U({add_:RD});function FD(e,t){let n=O(e,"a","floorDiv"),a=O(t,"b","floorDiv");[n,a]=Vt(n,a);let r={a:n,b:a};return V.runKernel(Zv,r)}var _k=U({floorDiv_:FD});function OD(e,t){let n=O(e,"a","div"),a=O(t,"b","div");if([n,a]=Vt(n,a),n.dtype==="int32"&&a.dtype==="int32")return _k(n,a);let r={a:n,b:a},s={};return V.runKernel(Pv,r,s)}var Qe=U({div_:OD});function DD(e,t){let n=O(e,"a","mul"),a=O(t,"b","mul");[n,a]=Vt(n,a);let r={a:n,b:a};return V.runKernel(Ew,r)}var fe=U({mul_:DD});function _D(e){let t=O(e,"x","abs");if(t.dtype==="complex64"){let n={x:t};return V.runKernel(bv,n)}else{let n={x:t};return V.runKernel(Q3,n)}}var Sa=U({abs_:_D});function zD(e){let t={x:O(e,"x","acos")};return V.runKernel(ev,t)}var PD=U({acos_:zD});function LD(e){let t={x:O(e,"x","acosh")};return V.runKernel(tv,t)}var WD=U({acosh_:LD});function BD(e){L(Array.isArray(e),()=>"The argument passed to tf.addN() must be a list of tensors"),L(e.length>=1,()=>`Mustpassatleastonetensortotf.addN(),butgot${e.length}`);let t=e.map((r,s)=>O(r,`tensors${s}`,"addN")),n=t[0];t.forEach(r=>{if(r.dtype!==n.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),t.forEach(r=>{if(!Kr(r.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});let a=t;return V.runKernel(nv,a)}var Xy=U({addN_:BD});function VD(e,t=null,n=!1){let a={x:O(e,"x","all","bool")},r={axis:t,keepDims:n};return V.runKernel(av,a,r)}var UD=U({all_:VD});function jD(e,t=null,n=!1){let a={x:O(e,"x","any","bool")},r={axis:t,keepDims:n};return V.runKernel(rv,a,r)}var HD=U({any_:jD});function GD(e,t=0){let n={x:O(e,"x","argMax")},a={axis:t};return V.runKernel(sv,n,a)}var Zy=U({argMax_:GD});function qD(e,t=0){let n={x:O(e,"x","argMin")},a={axis:t};return V.runKernel(iv,n,a)}var KD=U({argMin_:qD});function XD(e){let t={x:O(e,"x","asin")};return V.runKernel(ov,t)}var ZD=U({asin_:XD});function YD(e){let t={x:O(e,"x","asinh")};return V.runKernel(lv,t)}var JD=U({asinh_:YD});function QD(e){let t={x:O(e,"x","atan")};return V.runKernel(uv,t)}var e_=U({atan_:QD});function t_(e,t){let n=O(e,"a","atan2"),a=O(t,"b","atan2");[n,a]=Vt(n,a);let r={a:n,b:a};return V.runKernel(hv,r)}var n_=U({atan2_:t_});function a_(e){let
withdtype${s.dtype}.`)}),n.length===1)return Yr(n[0]);let a=n,r={axis:t};return V.runKernel(vv,a,r)}var sn=U({concat_:m_});function g_(e){let t={x:O(e,"x","sigmoid")};return V.runKernel(s7,t)}var Sr=U({sigmoid_:g_});function y_(e,t,n){let a=O(e,"x","slice","string_or_numeric");if(a.rank===0)throw new Error("Slicing scalar is not possible");let r={x:a},s={begin:t,size:n};return V.runKernel(t7,r,s)}var Ze=U({slice_:y_});function A_(e){let t={x:O(e,"x","tanh")};return V.runKernel(I7,t)}var Qy=U({tanh_:A_});function x_(e,t,n,a,r,s){let i=O(e,"forgetBias","basicLSTMCell"),o=O(t,"lstmKernel","basicLSTMCell"),l=O(n,"lstmBias","basicLSTMCell"),u=O(a,"data","basicLSTMCell"),d=O(r,"c","basicLSTMCell"),h=O(s,"h","basicLSTMCell"),p=sn([u,h],1),c=yt(p,o),m=De(c,l),f=m.shape[0],g=m.shape[1]/4,y=[f,g],A=Ze(m,[0,0],y),x=Ze(m,[0,g],y),v=Ze(m,[0,g*2],y),b=Ze(m,[0,g*3],y),w=De(fe(Sr(A),Qy(x)),fe(d,Sr(De(i,v)))),I=fe(Qy(w),Sr(b));return[w,I]}var b_=U({basicLSTMCell_:x_});function v_(e,t,n){let a=O(e,"x","batchToSpaceND"),r=t.reduce((o,l)=>o*l);L(a.rank>=1+t.length,()=>`inputrankis${a.rank}butshouldbe>thanblockShape.length${t.length}`),L(n.length===t.length,()=>`crops.lengthis${n.length}butshouldbeequaltoblockShape.length${t.length}`),L(a.shape[0]%r==0,()=>`inputtensorbatchis${a.shape[0]}butisnotdivisiblebytheproductoftheelementsofblockShape${t.join(" * ")}===${r}`);let s={x:a},i={blockShape:t,crops:n};return V.runKernel(mv,s,i)}var Bk=U({batchToSpaceND_:v_});function w_(e){let t;return e.rank===0||e.rank===1?t=le(e,[1,1,1,e.size]):e.rank===2?t=le(e,[1,1,e.shape[0],e.shape[1]]):e.rank===3?t=le(e,[1,e.shape[0],e.shape[1],e.shape[2]]):t=e,t}function k_(e,t,n,a,r,s){s==null&&(s=.001);let i=O(e,"x","batchNorm"),o=O(t,"mean","batchNorm"),l=O(n,"variance","batchNorm"),u;r!=null&&(u=O(r,"scale","batchNorm"));let d;a!=null&&(d=O(a,"offset","batchNorm")),L(o.rank===l.rank,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),L(d==null||o.rank===d.rank,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),L(u==null||o.rank===u.rank,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");let h={x:w_(i),scale:u,offset:d,mean:o,variance:l},p={varianceEpsilon:s},c=V.runKernel(Yv,h,p);return le(c,i.shape)}var Ac=U({batchNorm_:k_});function I_(e,t,n,a,r,s){let i=O(e,"x","batchNorm"),o=O(t,"mean","batchNorm"),l=O(n,"variance","batchNorm"),u;r!=null&&(u=O(r,"scale","batchNorm"));let d;return a!=null&&(d=O(a,"offset","batchNorm")),L(i.rank===2,()=>`ErrorinbatchNorm2D:xmustberank2butgotrank${i.rank}.`),L(o.rank===2||o.rank===1,()=>`ErrorinbatchNorm2D:meanmustberank2orrank1butgotrank${o.rank}.`),L(l.rank===2||l.rank===1,()=>`ErrorinbatchNorm2D:variancemustberank2orrank1butgotrank${l.rank}.`),u!=null&&L(u.rank===2||u.rank===1,()=>`ErrorinbatchNorm2D:scalemustberank2orrank1butgotrank${u.rank}.`),d!=null&&L(d.rank===2||d.rank===1,()=>`ErrorinbatchNorm2D:offsetmustberank2orrank1butgotrank${d.rank}.`),Ac(i,o,l,d,u,s)}var S_=U({batchNorm2d_:I_});function N_(e,t,n,a,r,s){let i=O(e,"x","batchNorm"),o=O(t,"mean","batchNorm"),l=O(n,"variance","batchNorm"),u;r!=null&&(u=O(r,"scale","batchNorm"));let d;return a!=null&&(d=O(a,"offset","batchNorm")),L(i.rank===3,()=>`ErrorinbatchNorm3D:xmustberank3butgotrank${i.rank}.`),L(o.rank===3||o.rank===1,()=>`ErrorinbatchNorm3D:meanmustberank3orrank1butgotrank${o.rank}.`),L(l.rank===3||l.rank===1,()=>`ErrorinbatchNorm3D:variancemustberank3orrank1butgotrank${l.rank}.`),u!=null&&L(u.rank===3||u.rank===1,()=>`ErrorinbatchNorm3D:scalemustberank3orrank1butgotrank${u.rank}.`),d!=null&&L(d.rank===3||d.rank===1,()=>`ErrorinbatchNorm3D:offsetmustberank3orrank1butgotrank${d.rank}.`),Ac(i,o,l,d,u,s)}var T_=U({batchNorm3d_:N_});function E_(e,t,n,a,r,s){let i=O(e,"x","batchNorm"),o=O(t,"mean","batchNorm"),l=O(n,"variance","batchNorm"),u;r!=null&&(u=O(r,"scale","batchNorm"));let d;ret
rank${s.rank}.`),L(Zn(t),()=>`ErrorinlocalResponseNormalization:depthRadiusmustbeanintegerbutgotdepthRadius${t}.`);let i=s,o=!1;s.rank===3&&(o=!0,i=le(s,[1,s.shape[0],s.shape[1],s.shape[2]]));let l={x:i},u={depthRadius:t,bias:n,alpha:a,beta:r},d=V.runKernel(gw,l,u);return o?le(d,[d.shape[1],d.shape[2],d.shape[3]]):d}var Jz=U({localResponseNormalization_:Yz});function Qz(e){let t={x:O(e,"x","log")};return V.runKernel(hw,t)}var ud=U({log_:Qz});function eP(e){let t={x:O(e,"x","log1p")};return V.runKernel(pw,t)}var Jk=U({log1p_:eP});function tP(e){return L(Ss(e),()=>"The f passed in grad(f) must be a function"),(t,n)=>{let a=O(t,"x","tf.grad","string_or_numeric"),r=n!=null?O(n,"dy","tf.grad"):null;return V.tidy(()=>{let{value:s,grads:i}=V.gradients(()=>e(a),[a],r);return r!=null&&On(s.shape,r.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),Ic(i),i[0]})}}function nP(e){return L(Ss(e),()=>"The f passed in grads(f) must be a function"),(t,n)=>{L(Array.isArray(t),()=>"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s");let a=rd(t,"args","tf.grads","string_or_numeric"),r=n!=null?O(n,"dy","tf.grads"):null;return V.tidy(()=>{let{value:s,grads:i}=V.gradients(()=>e(...a),a,r);return r!=null&&On(s.shape,r.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Ic(i),i})}}function aP(e){return L(Ss(e),()=>"The f passed in valueAndGrad(f) must be a function"),(t,n)=>{L(t instanceof St,()=>"The x passed in valueAndGrad(f)(x) must be a tensor"),L(n==null||n instanceof St,()=>"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");let{grads:a,value:r}=V.gradients(()=>e(t),[t],n);return Ic(a),{grad:a[0],value:r}}}function rP(e){return L(Ss(e),()=>"The f passed in valueAndGrads(f) must be a function"),(t,n)=>{L(Array.isArray(t)&&t.every(r=>r instanceof St),()=>"The args passed in valueAndGrads(f)(args) must be array of tensors"),L(n==null||n instanceof St,()=>"The dy passed in valueAndGrads(f)(args, dy) must be a tensor");let a=V.gradients(()=>e(...t),t,n);return n!=null&&On(a.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Ic(a.grads),a}}function Qk(e,t){L(Ss(e),()=>"The f passed in variableGrads(f) must be a function"),L(t==null||Array.isArray(t)&&t.every(u=>u instanceof ad),()=>"The varList passed in variableGrads(f, varList) must be an array of variables");let n=t!=null;if(!n){t=[];for(let u in V.registeredVariables)t.push(V.registeredVariables[u])}let a=n?t.filter(u=>!u.trainable):null,r=t.length;t=t.filter(u=>u.trainable),L(t.length>0,()=>`variableGrads()expectsatleastoneoftheinputvariablestobetrainable,butnoneofthe${r}variablesistrainable.`);let s=!0,{value:i,grads:o}=V.gradients(e,t,null,s);L(o.some(u=>u!=null),()=>"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."),L(i.rank===0,()=>`ThefpassedinvariableGrads(f)mustreturnascalar,butitreturnedarank-${i.rank}tensor`);let l={};return t.forEach((u,d)=>{o[d]!=null&&(l[u.name]=o[d])}),a!=null&&a.forEach(u=>l[u.name]=null),{value:i,grads:l}}function Nr(e){return V.customGrad(e)}function Ic(e){if(e.filter(t=>t==null).length>0)throw new Error(`Cannotcomputegradientofy=f(x)withrespecttox.Makesurethat
${r.shape}`);if(s.rank!==1)throw new Error(`ValuesshouldbeTensor1Dbutreceivedshape${s.shape}`);if(i.rank!==1)throw new Error(`DenseshapeshouldbeTensor1Dbutreceivedshape${i.shape}`);if(o.rank!==0)throw new Error(`Defaultvalueshouldbeascalarbutreceivedshape${o.shape}`);let l={indices:r,values:s,denseShape:i,defaultValue:o},u=V.runKernel(p7,l);return{outputIndices:u[0],outputValues:u[1],emptyRowIndicator:u[2],reverseIndexMap:u[3]}}var kV=U({sparseFillEmptyRows_:wV});function IV(e,t,n){let a=O(e,"inputIndices","sparseReshape"),r=O(t,"inputShape","sparseReshape"),s=O(n,"newShape","sparseReshape");if(a.rank!==2)throw new Error(`InputindicesshouldbeTensor2Dbutreceivedshape
${a.shape}`);if(r.rank!==1)throw new Error(`InputshapeshouldbeTensor1Dbutreceivedshape${r.shape}`);if(s.rank!==1)throw new Error(`NewshapeshouldbeTensor1Dbutreceivedshape${s.shape}`);let i={inputIndices:a,inputShape:r,newShape:s},o=V.runKernel(c7,i);return{outputIndices:o[0],outputShape:o[1]}}var SV=U({sparseReshape_:IV});function NV(e,t,n){let a=O(e,"data","sparseSegmentMean"),r=O(t,"indices","sparseSegmentMean"),s=O(n,"segmentIds","sparseSegmentMean");if(a.rank<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(r.rank!==1)throw new Error(`IndicesshouldbeTensor1Dbutreceivedshape
${r.shape}`);if(s.rank!==1)throw new Error(`SegmentidsshouldbeTensor1Dbutreceivedshape
${s.shape}`);let i={data:a,indices:r,segmentIds:s};return V.runKernel(f7,i)}var TV=U({sparseSegmentMean_:NV});function EV(e,t,n){let a=O(e,"data","sparseSegmentSum"),r=O(t,"indices","sparseSegmentSum"),s=O(n,"segmentIds","sparseSegmentSum");if(a.rank<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(r.rank!==1)throw new Error(`IndicesshouldbeTensor1Dbutreceivedshape
${r.shape}`);if(s.rank!==1)throw new Error(`SegmentidsshouldbeTensor1Dbutreceivedshape
${s.shape}`);let i={data:a,indices:r,segmentIds:s};return V.runKernel(m7,i)}var CV=U({sparseSegmentSum_:EV});function MV(e,t,n,a,r,s,i,o){let l=O(e,"data","stringNGrams","string");if(l.dtype!=="string")throw new Error("Data must be of datatype string");if(l.shape.length!==1)throw new Error(`Datamustbeavector,saw:${l.shape}`);let u=O(t,"dataSplits","stringNGrams");if(u.dtype!=="int32")throw new Error("Data splits must be of datatype int32");let d={separator:n,nGramWidths:a,leftPad:r,rightPad:s,padWidth:i,preserveShortSequences:o},h={data:l,dataSplits:u},p=V.runKernel(x7,h,d);return{nGrams:p[0],nGramsSplits:p[1]}}var $V=U({stringNGrams_:MV});function RV(e,t,n=!0){let a=O(e,"input","stringSplit","string"),r=O(t,"delimiter","stringSplit","string");if(a.rank!==1)throw new Error(`InputshouldbeTensor1Dbutreceivedshape${a.shape}`);if(r.rank!==0)throw new Error(`Delimitershouldbeascalarbutreceivedshape${r.shape}`);let s={skipEmpty:n},i={input:a,delimiter:r},o=V.runKernel(b7,i,s);return{indices:o[0],values:o[1],shape:o[2]}}var FV=U({stringSplit_:RV});function OV(e,t){let n=O(e,"input","stringToHashBucketFast","string"),a={numBuckets:t};if(t<=0)throw new Error("Number of buckets must be at least 1");let r={input:n};return V.runKernel(v7,r,a)}var DV=U({stringToHashBucketFast_:OV}),_V={fft:o1,ifft:Cc,rfft:l1,irfft:f6},zV={hammingWindow:cB,hannWindow:w6,frame:k6,stft:yB},Ye={flipLeftRight:vB,resizeNearestNeighbor:HB,resizeBilinear:UB,rotateWithOffset:kB,cropAndResize:xB,nonMaxSuppression:SB,nonMaxSuppressionAsync:FB,nonMaxSuppressionWithScore:DB,nonMaxSuppressionWithScoreAsync:zB,nonMaxSuppressionPadded:LB,nonMaxSuppressionPaddedAsync:BB,threshold:KB,transform:ZB},PV={bandPart:JB,gramSchmidt:eV,qr:nV},LV={absoluteDifference:sV,computeWeightedLoss:as,cosineDistance:oV,hingeLoss:uV,huberLoss:hV,logLoss:cV,meanSquaredError:mV,sigmoidCrossEntropy:AV,softmaxCrossEntropy:vV},WV={sparseFillEmptyRows:kV,sparseReshape:SV,sparseSegmentMean:TV,sparseSegmentSum:CV},BV={stringNGrams:$V,stringSplit:FV,stringToHashBucketFast:DV},Rs=class extends Mk{minimize(e,t=!1,n){let{value:a,grads:r}=this.computeGradients(e,n);if(n!=null){let s=n.map(i=>({name:i.name,tensor:r[i.name]}));this.applyGradients(s)}else this.applyGradients(r);return Ve(r),t?a:(a.dispose(),null)}get iterations(){return this.iterations_==null&&(this.iterations_=0),this.iterations_}incrementIterations(){this.iterations_=this.iterations+1}computeGradients(e,t){return Qk(e,t)}dispose(){this.iterations_!=null&&Ve(this.iterations_)}async saveIterations(){return this.iterations_==null&&(this.iterations_=0),{name:"iter",tensor:dt(this.iterations_,"int32")}}async getWeights(){throw new Error("getWeights() is not implemented for this optimizer yet.")}async setWeights(e){throw new Error(`setWeights()isnotimplementedforthisoptimizerclass${this.getClassName()}`)}async extractIterations(e){return this.iterations_=(await e[0].tensor.data())[0],e.slice(1)}};Object.defineProperty(Rs,Symbol.hasInstance,{value:e=>e.minimize!=null&&e.computeGradients!=null&&e.applyGradients!=null});var Oc=class extends Rs{constructor(e,t,n=null){super();this.learningRate=e,this.rho=t,this.epsilon=n,this.accumulatedGrads=[],this.accumulatedUpdates=[],n==null&&(this.epsilon=V.backend.epsilon())}applyGradients(e){(Array.isArray(e)?e.map(t=>t.name):Object.keys(e)).forEach((t,n)=>{let a=V.registeredVariables[t],r=!1;this.accumulatedGrads[n]==null&&(this.accumulatedGrads[n]={originalName:`${t}/accum_grad`,variable:Ue(()=>Na(a).variable(r))}),this.accumulatedUpdates[n]==null&&(this.accumulatedUpdates[n]={originalName:`${t}/accum_var`,variable:Ue(()=>Na(a).variable(r))});let s=Array.isArray(e)?e[n].tensor:e[t];if(s==null)return;let i=this.accumulatedGrads[n].variable,o=this.accumulatedUpdates[n].variable;Ue(()=>{let l=De(fe(i,this.rho),fe(tr(s),1-this.rho)),u=fe(Qe(ts(De(o,this.epsilon)),ts(De(i,this.epsilon))),s),d=De(fe(o,this.rho),fe(tr(u),1-this.rho));i.assign(l),o.assign(d);let h=De(fe(u,-this.learningRate),a);a.assign(h)})}),this.incrementIterations()}dispose(){this.accumulatedUpdates!
${s}).`);if(n<a)throw new Error(`batchDims(${a})mustbelessthanorequaltoaxis(${n}).`);for(let h=0;h<a;++h)if(e.shape[h]!==t.shape[h])throw new Error(`x.shape[${h}]:${e.shape[h]}shouldbeequaltoindices.shape[${h}]:${t.shape[h]}.`);let i=e.shape[n],o=[],l=1,u=1,d=1;for(let h=0;h<a;++h)o.push(e.shape[h]),l*=e.shape[h];for(let h=a;h<n;h++)o.push(e.shape[h]),u*=e.shape[h];for(let h=a;h<r;h++)o.push(t.shape[h]);for(let h=n+1;h<s;h++)o.push(e.shape[h]),d*=e.shape[h];return{batchSize:l,sliceSize:d,outerSize:u,dimSize:i,outputShape:o}}function CU(e){try{return e.map(t=>oc(t))}catch(t){throw new Error(`Failedtodecodeencodedstringbytesintoutf-8,error:${t}`)}}function MU(e){return e.map(t=>Qu(t))}var F6={};$e(F6,{nonMaxSuppressionV3Impl:()=>I6,nonMaxSuppressionV4Impl:()=>S6,nonMaxSuppressionV5Impl:()=>N6,whereImpl:()=>y6});var $U=1e-7,RU=1e-4,f1=class{constructor(e,t){this.backend=e,this.dataMover=t,this.data=new WeakMap,this.dataIdsCount=0}get(e){return this.data.has(e)||this.dataMover.moveData(this.backend,e),this.data.get(e)}set(e,t){this.dataIdsCount++,this.data.set(e,t)}has(e){return this.data.has(e)}delete(e){return this.dataIdsCount--,this.data.delete(e)}numDataIds(){return this.dataIdsCount}},Wc=class{refCount(e){return ja("refCount")}incRef(e){return ja("incRef")}timerAvailable(){return!0}time(e){return ja("time")}read(e){return ja("read")}readSync(e){return ja("readSync")}numDataIds(){return ja("numDataIds")}disposeData(e,t){return ja("disposeData")}write(e,t,n){return ja("write")}move(e,t,n,a,r){return ja("move")}memory(){return ja("memory")}floatPrecision(){return ja("floatPrecision")}epsilon(){return this.floatPrecision()===32?$U:RU}dispose(){return ja("dispose")}};function ja(e){throw new Error(`'${e}'notyetimplementedornotfoundintheregistry.Thiskernelmaynotbesupportedbythetfjsbackendyouhavechosen`)}function O6(e){let t=e.length,n=0,a=0;for(;t>0;)a=Math.random()*t|0,t--,n=e[t],e[t]=e[a],e[a]=n}function FU(e,t){if(e.length!==t.length)throw new Error(`ArraysizesmustmatchtobeshuffledtogetherFirstarraylengthwas${e.length}Secondarraylengthwas${t.length}`);let n=e.length,a,r,s=0;for(;n>0;)s=Math.random()*n|0,n--,a=e[n],r=t[n],e[n]=e[s],t[n]=t[s],e[s]=a,t[s]=r}function gd(e,t,n){return Math.max(e,Math.min(t,n))}function OU(e){return e%2==0?e:e+1}function DU(e){let t=0;for(let n=0;n<e.length;n++)t+=e[n];return t}function _U(e,t){let n=Math.random();return t*n+(1-n)*e}function zU(e,t){let n=0;for(let a=0;a<e.length;a++){let r=Number(e[a])-Number(t[a]);n+=r*r}return n}function P(e,t){if(!e)throw new Error(typeof t=="string"?t:t())}function nr(e,t,n=""){P(Fs(e,t),()=>n+`Shapes${e}and${t}mustmatch`)}function Bc(e){P(e!=null,()=>"The input to the tensor constructor must be a non-null value.")}function yd(e,t=[],n=!1){if(t==null&&(t=[]),Array.isArray(e)||ar(e)&&!n)for(let a=0;a<e.length;++a)yd(e[a],t,n);else t.push(e);return t}function on(e){if(e.length===0)return 1;let t=e[0];for(let n=1;n<e.length;n++)t*=e[n];return t}function PU(e){return e.length===0}function Fs(e,t){if(e===t)return!0;if(e==null||t==null||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function mn(e){return e%1==0}function LU(e){if(Math.tanh!=null)return Math.tanh(e);if(e===Infinity)return 1;if(e===-Infinity)return-1;{let t=Math.exp(2*e);return(t-1)/(t+1)}}function WU(e){let t=Math.ceil(Math.sqrt(e));return[t,Math.ceil(e/t)]}function BU(e){let t=new Uint32Array(e);for(let n=0;n<e;++n)t[n]=n;return O6(t),t}function Ad(e,t){return t<=e.length?e:e+" ".repeat(t-e.length)}function VU(e,t=a=>0,n){return new Promise((a,r)=>{let s=0,i=()=>{if(e()){a();return}s++;let o=t(s);if(n!=null&&s>=n){r();return}setTimeout(i,o)};i()})}function UU(e,t){let n=1,a=-1;for(let s=0;s<e.length;++s)if(e[s]>=0)n*=e[s];else if(e[s]===-1){if(a!==-1)throw Error(`Shapescanonlyhave1implicitsize.Found-1atdim${a}anddim${s}`);a=s}else if(e[s]<0)throw Error(`Shapescannotbe<0.Found${e[s]}atdim${s}`);if(a===-1){if(t>0&&t!==n)throw Error(`Size(${t})mustmatchthep
`;return p[p.length-1]=" "+p[p.length-1]+"]"+(s?"":m),p}function Ah(e){let t=[];for(let n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}var Qt=class{constructor(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=on(e),n!=null){let a=n.length;P(a===this.size,()=>`Lengthofvalues'${a}'doesnotmatchthesizeinferredbytheshape'${this.size}'.`)}if(t==="complex64")throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=n||_6(t,this.size),this.strides=Ko(e)}set(e,...t){t.length===0&&(t=[0]),P(t.length===this.rank,()=>`Thenumberofprovidedcoordinates(${t.length})mustmatchtherank(${this.rank})`);let n=this.locToIndex(t);this.values[n]=e}get(...e){e.length===0&&(e=[0]);let t=0;for(let a of e){if(a<0||a>=this.shape[t]){let r=`Requestedoutofrangeelementat${e}.Buffershape=${this.shape}`;throw new Error(r)}t++}let n=e[e.length-1];for(let a=0;a<e.length-1;++a)n+=this.strides[a]*e[a];return this.values[n]}locToIndex(e){if(this.rank===0)return 0;if(this.rank===1)return e[0];let t=e[e.length-1];for(let n=0;n<e.length-1;++n)t+=this.strides[n]*e[n];return t}indexToLoc(e){if(this.rank===0)return[];if(this.rank===1)return[e];let t=new Array(this.shape.length);for(let n=0;n<t.length-1;++n)t[n]=Math.floor(e/this.strides[n]),e-=t[n]*this.strides[n];return t[t.length-1]=e,t}get rank(){return this.shape.length}toTensor(){return Tr().makeTensor(this.values,this.shape,this.dtype)}},Tr=null,Vl=null,xj=null;function bj(e){Tr=e}function vj(e){Vl=e}function wj(e){xj=e}var Tt=class{constructor(e,t,n,a){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=on(e),this.strides=Ko(e),this.dataId=n,this.id=a,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){let e=await this.data();return Vl.buffer(this.shape,this.dtype,e)}bufferSync(){return Vl.buffer(this.shape,this.dtype,this.dataSync())}async array(){let e=await this.data();return Xo(this.shape,e,this.dtype==="complex64")}arraySync(){return Xo(this.shape,this.dataSync(),this.dtype==="complex64")}async data(){this.throwIfDisposed();let e=Tr().read(this.dataId);if(this.dtype==="string"){let t=await e;try{return t.map(n=>ff(n))}catch(n){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}}return e}dataSync(){this.throwIfDisposed();let e=Tr().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>ff(t))}catch(t){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return e}async bytes(){this.throwIfDisposed();let e=await Tr().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){this.isDisposed||(Tr().disposeTensor(this),this.isDisposedInternal=!0)}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return Vl.print(this,e)}clone(){return this.throwIfDisposed(),Vl.clone(this)}toString(e=!1){let t=this.dataSync();return yj(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),Vl.cast(this,e)}variable(e=!0,t,n){return this.throwIfDisposed(),Tr().makeVariable(this,e,t,n)}};Object.defineProperty(Tt,Symbol.hasInstance,{value:e=>!!e&&e.data!=null&&e.dataSync!=null&&e.throwIfDisposed!=null});function re(){return b1("Tensor",()=>Tt)}re();var gf=class extends Tt{constructor(e,t,n,a){super(e.shape,e.dtype,e.dataId,a);this.trainable=t,this.name=n}assign(e){if(e.dtype!==this.dtype)throw new Error(`dtypeofthenewvalue(${e.dtype})andpreviousvalue(${this.dtype})mustmatch`);if(!Fs(e.shape,this.shape))throw new Error(`shapeofthenewvalue(${e.shape})andpreviousvalue(${this.shape})mustmatch`);Tr().disposeTensor(this),this.dataId=e.dataId,Tr().incRef(this,null)}dispose(){Tr().disposeVariable(this),this.isDisposedInternal=!0}};Object.defineProperty(gf,Symbol.hasInstance,{value:e=>e instanceof Tt&&e.as
ManifestJSONhasweightswithnames:${o.join(", ")}.`)}let l=r.reduce((c,m,f)=>(m&&c.push(f),c),[]),u=[];l.forEach(c=>{t[c].paths.forEach(m=>{let f=n+(n.endsWith("/")?"":"/")+m;u.push(f)})});let d=await e(u),h={},p=0;return l.forEach(c=>{let m=t[c].paths.length,f=0;for(let x=0;x<m;x++)f+=d[p+x].byteLength;let g=new ArrayBuffer(f),y=new Uint8Array(g),A=0;for(let x=0;x<m;x++){let v=new Uint8Array(d[p+x]);y.set(v,A),A+=v.byteLength}s[c].forEach(x=>{let v=g.slice(x.groupOffset,x.groupOffset+x.sizeBytes),b=u4(v,[x.manifestEntry]);for(let w in b)h[w]=b[w]}),p+=m}),h}}var bH="application/octet-stream",vH="application/json",kA=class{constructor(e,t){if(this.DEFAULT_METHOD="POST",t==null&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.onProgress=t.onProgress,this.weightUrlConverter=t.weightUrlConverter,t.fetchFunc!=null?(P(typeof t.fetchFunc=="function",()=>"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"),this.fetch=t.fetchFunc):this.fetch=se().platform.fetch,P(e!=null&&e.length>0,()=>"URL path for http must not be null, undefined or empty."),Array.isArray(e)&&P(e.length===2,()=>`URLpathsforhttpmusthavealengthof2,(actuallengthis${e.length}).`),this.path=e,t.requestInit!=null&&t.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=t.requestInit||{}}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");let t=Object.assign({method:this.DEFAULT_METHOD},this.requestInit);t.body=new FormData;let n=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],a={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,weightsManifest:n};e.signature!=null&&(a.signature=e.signature),e.userDefinedMetadata!=null&&(a.userDefinedMetadata=e.userDefinedMetadata),e.modelInitializer!=null&&(a.modelInitializer=e.modelInitializer),t.body.append("model.json",new Blob([JSON.stringify(a)],{type:vH}),"model.json"),e.weightData!=null&&t.body.append("model.weights.bin",new Blob([e.weightData],{type:bH}),"model.weights.bin");let r=await this.fetch(this.path,t);if(r.ok)return{modelArtifactsInfo:wh(e),responses:[r]};throw new Error(`BrowserHTTPRequest.save()failedduetoHTTPresponsestatus${r.status}.`)}async load(){let e=await this.fetch(this.path,this.requestInit);if(!e.ok)throw new Error(`Requestto${this.path}failedwithstatuscode${e.status}.PleaseverifythisURLpointstothemodelJSONofthemodeltoload.`);let t;try{t=await e.json()}catch(c){let m=`FailedtoparsemodelJSONofresponsefrom${this.path}.`;throw this.path.endsWith(".pb")?m+=" Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository.":m+=" Please make sure the server is serving valid JSON for this request.",new Error(m)}let n=t.modelTopology,a=t.weightsManifest,r=t.generatedBy,s=t.convertedBy,i=t.format,o=t.signature,l=t.userDefinedMetadata;if(n==null&&a==null)throw new Error(`TheJSONfromHTTPpath${this.path}containsneithermodeltopologyormanifestforweights.`);let u,d;a!=null&&([u,d]=await this.loadWeights(a));let h={modelTopology:n,weightSpecs:u,weightData:d,generatedBy:r,convertedBy:s,format:i};o!=null&&(h.signature=o),l!=null&&(h.userDefinedMetadata=l);let p=t.modelInitializer;return p&&(h.modelInitializer=p),h}async loadWeights(e){let t=Array.isArray(this.path)?this.path[1]:this.path,[n,a]=wH(t),r=this.weightPathPrefix||n,s=[];for(let u of e)s.push(...u.weights);let i=[],o=[];for(let u of e)for(let d of u.paths)this.weightUrlConverter!=null?o.push(this.weightUrlConverter(d)):i.push(r+d+a);this.weightUrlConverter&&i.push(...await Promise.all(o));let l=await b4(i,{requestInit:thi
withdtype${s.dtype}.`)}),n.length===1)return Gi(n[0]);let a=n,r={axis:t};return j.runKernel(Cd,a,r)}var en=B({concat_:yG});function AG(e){let t={x:F(e,"x","sigmoid")};return j.runKernel(Rl,t)}var $r=B({sigmoid_:AG});function xG(e,t,n){let a=F(e,"x","slice","string_or_numeric");if(a.rank===0)throw new Error("Slicing scalar is not possible");let r={x:a},s={begin:t,size:n};return j.runKernel(ah,r,s)}var nt=B({slice_:xG});function bG(e){let t={x:F(e,"x","tanh")};return j.runKernel(zl,t)}var Kl=B({tanh_:bG});function vG(e,t,n,a,r,s){let i=F(e,"forgetBias","basicLSTMCell"),o=F(t,"lstmKernel","basicLSTMCell"),l=F(n,"lstmBias","basicLSTMCell"),u=F(a,"data","basicLSTMCell"),d=F(r,"c","basicLSTMCell"),h=F(s,"h","basicLSTMCell"),p=en([u,h],1),c=it(p,o),m=pe(c,l),f=m.shape[0],g=m.shape[1]/4,y=[f,g],A=nt(m,[0,0],y),x=nt(m,[0,g],y),v=nt(m,[0,g*2],y),b=nt(m,[0,g*3],y),w=pe(K($r(A),Kl(x)),K(d,$r(pe(i,v)))),I=K(Kl(w),$r(b));return[w,I]}var ywe=B({basicLSTMCell_:vG});function wG(e,t,n){let a=F(e,"x","batchToSpaceND"),r=t.reduce((o,l)=>o*l);P(a.rank>=1+t.length,()=>`inputrankis${a.rank}butshouldbe>thanblockShape.length${t.length}`),P(n.length===t.length,()=>`crops.lengthis${n.length}butshouldbeequaltoblockShape.length${t.length}`),P(a.shape[0]%r==0,()=>`inputtensorbatchis${a.shape[0]}butisnotdivisiblebytheproductoftheelementsofblockShape${t.join(" * ")}===${r}`);let s={x:a},i={blockShape:t,crops:n};return j.runKernel(Xc,s,i)}var Nf=B({batchToSpaceND_:wG});function kG(e){let t;return e.rank===0||e.rank===1?t=Y(e,[1,1,1,e.size]):e.rank===2?t=Y(e,[1,1,e.shape[0],e.shape[1]]):e.rank===3?t=Y(e,[1,e.shape[0],e.shape[1],e.shape[2]]):t=e,t}function IG(e,t,n,a,r,s){s==null&&(s=.001);let i=F(e,"x","batchNorm"),o=F(t,"mean","batchNorm"),l=F(n,"variance","batchNorm"),u;r!=null&&(u=F(r,"scale","batchNorm"));let d;a!=null&&(d=F(a,"offset","batchNorm")),P(o.rank===l.rank,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),P(d==null||o.rank===d.rank,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),P(u==null||o.rank===u.rank,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");let h={x:kG(i),scale:u,offset:d,mean:o,variance:l},p={varianceEpsilon:s},c=j.runKernel(dl,h,p);return Y(c,i.shape)}var Xl=B({batchNorm_:IG});function SG(e,t,n,a,r,s){let i=F(e,"x","batchNorm"),o=F(t,"mean","batchNorm"),l=F(n,"variance","batchNorm"),u;r!=null&&(u=F(r,"scale","batchNorm"));let d;return a!=null&&(d=F(a,"offset","batchNorm")),P(i.rank===2,()=>`ErrorinbatchNorm2D:xmustberank2butgotrank${i.rank}.`),P(o.rank===2||o.rank===1,()=>`ErrorinbatchNorm2D:meanmustberank2orrank1butgotrank${o.rank}.`),P(l.rank===2||l.rank===1,()=>`ErrorinbatchNorm2D:variancemustberank2orrank1butgotrank${l.rank}.`),u!=null&&P(u.rank===2||u.rank===1,()=>`ErrorinbatchNorm2D:scalemustberank2orrank1butgotrank${u.rank}.`),d!=null&&P(d.rank===2||d.rank===1,()=>`ErrorinbatchNorm2D:offsetmustberank2orrank1butgotrank${d.rank}.`),Xl(i,o,l,d,u,s)}var NG=B({batchNorm2d_:SG});function TG(e,t,n,a,r,s){let i=F(e,"x","batchNorm"),o=F(t,"mean","batchNorm"),l=F(n,"variance","batchNorm"),u;r!=null&&(u=F(r,"scale","batchNorm"));let d;return a!=null&&(d=F(a,"offset","batchNorm")),P(i.rank===3,()=>`ErrorinbatchNorm3D:xmustberank3butgotrank${i.rank}.`),P(o.rank===3||o.rank===1,()=>`ErrorinbatchNorm3D:meanmustberank3orrank1butgotrank${o.rank}.`),P(l.rank===3||l.rank===1,()=>`ErrorinbatchNorm3D:variancemustberank3orrank1butgotrank${l.rank}.`),u!=null&&P(u.rank===3||u.rank===1,()=>`ErrorinbatchNorm3D:scalemustberank3orrank1butgotrank${u.rank}.`),d!=null&&P(d.rank===3||d.rank===1,()=>`ErrorinbatchNorm3D:offsetmustberank3orrank1butgotrank${d.rank}.`),Xl(i,o,l,d,u,s)}var EG=B({batchNorm3d_:TG});function CG(e,t,n,a,r,s){let i=F(e,"x","batchNorm"),o=F(t,"mean","batchNorm"),l=F(n,"variance","batchNorm"),u;r!=null&&(u=F(r,"scale","batchNorm"));let d;return a!
rank${s.rank}.`),P(mn(t),()=>`ErrorinlocalResponseNormalization:depthRadiusmustbeanintegerbutgotdepthRadius${t}.`);let i=s,o=!1;s.rank===3&&(o=!0,i=Y(s,[1,s.shape[0],s.shape[1],s.shape[2]]));let l={x:i},u={depthRadius:t,bias:n,alpha:a,beta:r},d=j.runKernel(nf,l,u);return o?Y(d,[d.shape[1],d.shape[2],d.shape[3]]):d}var h8=B({localResponseNormalization_:_q});function zq(e){let t={x:F(e,"x","log")};return j.runKernel($i,t)}var Ma=B({log_:zq});function Pq(e){let t={x:F(e,"x","log1p")};return j.runKernel(Vd,t)}var VA=B({log1p_:Pq});function Lq(e,t){P(jc(e),()=>"The f passed in variableGrads(f) must be a function"),P(t==null||Array.isArray(t)&&t.every(u=>u instanceof gf),()=>"The varList passed in variableGrads(f, varList) must be an array of variables");let n=t!=null;if(!n){t=[];for(let u in j.registeredVariables)t.push(j.registeredVariables[u])}let a=n?t.filter(u=>!u.trainable):null,r=t.length;t=t.filter(u=>u.trainable),P(t.length>0,()=>`variableGrads()expectsatleastoneoftheinputvariablestobetrainable,butnoneofthe${r}variablesistrainable.`);let s=!0,{value:i,grads:o}=j.gradients(e,t,null,s);P(o.some(u=>u!=null),()=>"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."),P(i.rank===0,()=>`ThefpassedinvariableGrads(f)mustreturnascalar,butitreturnedarank-${i.rank}tensor`);let l={};return t.forEach((u,d)=>{o[d]!=null&&(l[u.name]=o[d])}),a!=null&&a.forEach(u=>l[u.name]=null),{value:i,grads:l}}function ss(e){return j.customGrad(e)}function Wq(e){let t={x:F(e,"x","neg")};return j.runKernel(Hd,t)}var Kt=B({neg_:Wq});function Bq(e){let t={x:F(e,"x","softplus")};return j.runKernel(ih,t)}var Zl=B({softplus_:Bq});function Vq(e){let t=F(e,"x","logSigmoid");return ss(n=>({value:Kt(Zl(Kt(n))),gradFunc:a=>K(a,$r(Kt(n)))}))(t)}var Uq=B({logSigmoid_:Vq});function jq(e,t=null,n=!1){let a={x:F(e,"x","max")},r={reductionIndices:t,keepDims:n};return j.runKernel(gl,a,r)}var sr=B({max_:jq});function Hq(e,t){let n=F(e,"a","sub"),a=F(t,"b","sub");[n,a]=Ut(n,a);let r={a:n,b:a};return j.runKernel(zi,r)}var Ne=B({sub_:Hq});function Gq(e,t=null,n=!1){let a=F(e,"x","sum");a.dtype==="bool"&&(a=we(a,"int32"));let r={x:a},s={axis:t,keepDims:n};return j.runKernel(Ol,r,s)}var Ce=B({sum_:Gq});function qq(e,t=-1){let n=F(e,"logits","logSoftmax");if(t===-1&&(t=n.rank-1),t!==n.rank-1)throw Error(`LogSoftmaxalonganon-lastdimensionisnotyetsupported.Logitswasrank${n.rank}andaxiswas${t}`);return ss((a,r)=>{let s=!0,i=sr(a,t,!0),o=Ne(a,i),l=Ne(we(o,"float32"),Ma(Ce(qa(o),t,s)));return r([l]),{value:l,gradFunc:(u,d)=>{let[h]=d,p=!0,c=qa(h);return Ne(u,K(Ce(u,t,p),c))}}})(n)}var UA=B({logSoftmax_:qq});function jA(e,t){for(let n=0;n<e.length;++n)if(e[e.length-n-1]!==t-1-n)return!1;return!0}function p8(e,t,n){let a=e.length+t.length,r=[],s=0,i=0;for(let o=0;o<a;o++)n.indexOf(o)===-1?r.push(e[s++]):r.push(t[i++]);return r}function c8(e,t){let n=[],a=e.length;for(let s=0;s<a;s++)t.indexOf(s)===-1&&n.push(e[s]);let r=t.map(s=>e[s]);return[n,r]}function Qi(e,t){let n=t.map(a=>1);return p8(e,n,t)}function Kq(e,t,n){P(jA(t,n),()=>`${e}supportsonlyinner-mostaxesfornow.Gotaxes${t}andrank-${n}input.`)}function f8(e,t){if(jA(e,t))return null;let n=[];for(let a=0;a<t;++a)e.indexOf(a)===-1&&n.push(a);return e.forEach(a=>n.push(a)),n}function HA(e){return e.map((t,n)=>[n,t]).sort((t,n)=>t[1]-n[1]).map(t=>t[0])}function Xq(e,t){let n=[];for(let a=t-e;a<t;++a)n.push(a);return n}function Zq(e,t=null,n=!1){let a=F(e,"x","logSumExp"),r=Ha(t,a.shape),s=sr(a,r,!0),i=Ne(a,s),o=qa(i),l=Ce(o,r),u=Ma(l),d=pe(Y(s,u.shape),u);if(n){let h=Qi(d.shape,r);return Y(d,h)}return d}var m8=B({logSumExp_:Zq});function Yq(e,t){let n=F(e,"a","logicalAnd","bool"),a=F(t,"b","logicalAnd","bool");Rt(n.shape,a.shape);let r={a:n,b:a};return j.runKernel(Ud,r)}var ir=B({logicalAnd_:Yq});function Jq(e){let t={x:F(e,"x","logicalNot","bool")};return j.runKernel(ef,t)}var Cf=B({logicalNot_:Jq});funct
${r.shape}`);if(s.rank!==1)throw new Error(`ValuesshouldbeTensor1Dbutreceivedshape${s.shape}`);if(i.rank!==1)throw new Error(`DenseshapeshouldbeTensor1Dbutreceivedshape${i.shape}`);if(o.rank!==0)throw new Error(`Defaultvalueshouldbeascalarbutreceivedshape${o.shape}`);let l={indices:r,values:s,denseShape:i,defaultValue:o},u=j.runKernel(K1,l);return{outputIndices:u[0],outputValues:u[1],emptyRowIndicator:u[2],reverseIndexMap:u[3]}}var YZ=B({sparseFillEmptyRows_:ZZ});function JZ(e,t,n){let a=F(e,"inputIndices","sparseReshape"),r=F(t,"inputShape","sparseReshape"),s=F(n,"newShape","sparseReshape");if(a.rank!==2)throw new Error(`InputindicesshouldbeTensor2Dbutreceivedshape
${a.shape}`);if(r.rank!==1)throw new Error(`InputshapeshouldbeTensor1Dbutreceivedshape${r.shape}`);if(s.rank!==1)throw new Error(`NewshapeshouldbeTensor1Dbutreceivedshape${s.shape}`);let i={inputIndices:a,inputShape:r,newShape:s},o=j.runKernel(X1,i);return{outputIndices:o[0],outputShape:o[1]}}var QZ=B({sparseReshape_:JZ});function eY(e,t,n){let a=F(e,"data","sparseSegmentMean"),r=F(t,"indices","sparseSegmentMean"),s=F(n,"segmentIds","sparseSegmentMean");if(a.rank<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(r.rank!==1)throw new Error(`IndicesshouldbeTensor1Dbutreceivedshape
${r.shape}`);if(s.rank!==1)throw new Error(`SegmentidsshouldbeTensor1Dbutreceivedshape
${s.shape}`);let i={data:a,indices:r,segmentIds:s};return j.runKernel(Z1,i)}var tY=B({sparseSegmentMean_:eY});function nY(e,t,n){let a=F(e,"data","sparseSegmentSum"),r=F(t,"indices","sparseSegmentSum"),s=F(n,"segmentIds","sparseSegmentSum");if(a.rank<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(r.rank!==1)throw new Error(`IndicesshouldbeTensor1Dbutreceivedshape
${r.shape}`);if(s.rank!==1)throw new Error(`SegmentidsshouldbeTensor1Dbutreceivedshape
${s.shape}`);let i={data:a,indices:r,segmentIds:s};return j.runKernel(Y1,i)}var aY=B({sparseSegmentSum_:nY});function rY(e,t,n,a,r,s,i,o){let l=F(e,"data","stringNGrams","string");if(l.dtype!=="string")throw new Error("Data must be of datatype string");if(l.shape.length!==1)throw new Error(`Datamustbeavector,saw:${l.shape}`);let u=F(t,"dataSplits","stringNGrams");if(u.dtype!=="int32")throw new Error("Data splits must be of datatype int32");let d={separator:n,nGramWidths:a,leftPad:r,rightPad:s,padWidth:i,preserveShortSequences:o},h={data:l,dataSplits:u},p=j.runKernel(Q1,h,d);return{nGrams:p[0],nGramsSplits:p[1]}}var sY=B({stringNGrams_:rY});function iY(e,t,n=!0){let a=F(e,"input","stringSplit","string"),r=F(t,"delimiter","stringSplit","string");if(a.rank!==1)throw new Error(`InputshouldbeTensor1Dbutreceivedshape${a.shape}`);if(r.rank!==0)throw new Error(`Delimitershouldbeascalarbutreceivedshape${r.shape}`);let s={skipEmpty:n},i={input:a,delimiter:r},o=j.runKernel(eA,i,s);return{indices:o[0],values:o[1],shape:o[2]}}var oY=B({stringSplit_:iY});function lY(e,t){let n=F(e,"input","stringToHashBucketFast","string"),a={numBuckets:t};if(t<=0)throw new Error("Number of buckets must be at least 1");let r={input:n};return j.runKernel(tA,r,a)}var uY=B({stringToHashBucketFast_:lY}),to={flipLeftRight:sZ,resizeNearestNeighbor:L8,resizeBilinear:P8,rotateWithOffset:oZ,cropAndResize:aZ,nonMaxSuppression:uZ,nonMaxSuppressionAsync:yZ,nonMaxSuppressionWithScore:xZ,nonMaxSuppressionWithScoreAsync:vZ,nonMaxSuppressionPadded:kZ,nonMaxSuppressionPaddedAsync:SZ,threshold:MZ,transform:RZ},dY={bandPart:OZ,gramSchmidt:_Z,qr:PZ},Vf={sparseFillEmptyRows:YZ,sparseReshape:QZ,sparseSegmentMean:tY,sparseSegmentSum:aY},c2={stringNGrams:sY,stringSplit:oY,stringToHashBucketFast:uY},js=class extends W4{minimize(e,t=!1,n){let{value:a,grads:r}=this.computeGradients(e,n);if(n!=null){let s=n.map(i=>({name:i.name,tensor:r[i.name]}));this.applyGradients(s)}else this.applyGradients(r);return Ge(r),t?a:(a.dispose(),null)}get iterations(){return this.iterations_==null&&(this.iterations_=0),this.iterations_}incrementIterations(){this.iterations_=this.iterations+1}computeGradients(e,t){return Lq(e,t)}dispose(){this.iterations_!=null&&Ge(this.iterations_)}async saveIterations(){return this.iterations_==null&&(this.iterations_=0),{name:"iter",tensor:Re(this.iterations_,"int32")}}async getWeights(){throw new Error("getWeights() is not implemented for this optimizer yet.")}async setWeights(e){throw new Error(`setWeights()isnotimplementedforthisoptimizerclass${this.getClassName()}`)}async extractIterations(e){return this.iterations_=(await e[0].tensor.data())[0],e.slice(1)}};Object.defineProperty(js,Symbol.hasInstance,{value:e=>e.minimize!=null&&e.computeGradients!=null&&e.applyGradients!=null});var f2=class extends js{constructor(e,t,n=null){super();this.learningRate=e,this.rho=t,this.epsilon=n,this.accumulatedGrads=[],this.accumulatedUpdates=[],n==null&&(this.epsilon=j.backend.epsilon())}applyGradients(e){(Array.isArray(e)?e.map(t=>t.name):Object.keys(e)).forEach((t,n)=>{let a=j.registeredVariables[t],r=!1;this.accumulatedGrads[n]==null&&(this.accumulatedGrads[n]={originalName:`${t}/accum_grad`,variable:Z(()=>at(a).variable(r))}),this.accumulatedUpdates[n]==null&&(this.accumulatedUpdates[n]={originalName:`${t}/accum_var`,variable:Z(()=>at(a).variable(r))});let s=Array.isArray(e)?e[n].tensor:e[t];if(s==null)return;let i=this.accumulatedGrads[n].variable,o=this.accumulatedUpdates[n].variable;Z(()=>{let l=pe(K(i,this.rho),K(vt(s),1-this.rho)),u=K(Me(Mn(pe(o,this.epsilon)),Mn(pe(i,this.epsilon))),s),d=pe(K(o,this.rho),K(vt(u),1-this.rho));i.assign(l),o.assign(d);let h=pe(K(u,-this.learningRate),a);a.assign(h)})}),this.incrementIterations()}dispose(){this.accumulatedUpdates!=null&&(Ge(this.accumulatedGrads.map(e=>e.variable)),Ge(this.accumulatedUpdates.map(e=>e.variable)))}async getWeights(){let e=[...this.accumulatedGrads,...this.accumulatedUpdates];return[await this.saveIterations()].concat(e.map(t=>({name:t.originalName,tensor:t.variabl
2.Thecustom${a}isdefinedinJavaScript,butisnotregisteredproperlywithtf.serialization.registerClass().`);return i}else{let s=e;if(s.className==null||s.config==null)throw new G(`${a}:Improperconfigformat:${JSON.stringify(s)}.
'className'and'config'mustset.`);let i=s.className,o,l;if(i in n?[o,l]=n[i]:i in Ka?[o,l]=Ka.className:i in t&&([o,l]=t[i]),o==null)throw new G(`Unknown${a}:${i}.Thismaybeduetooneofthefollowingreasons:
2.Thecustom${a}isdefinedinJavaScript,butisnotregisteredproperlywithtf.serialization.registerClass().`);if(l!=null){let u={};for(let c of Object.keys(Ka))u[c]=Ka[c];for(let c of Object.keys(n))u[c]=n[c];let d=s.config;d.customObjects=u;let h={...Ka};for(let c of Object.keys(n))Ka[c]=n[c];S2(s.config);let p=l(o,s.config,n,r);return Ka={...h},p}else{let u={...Ka};for(let h of Object.keys(n))Ka[h]=n[h];let d=new o(s.config);return Ka={...u},d}}}function YQ(e,t){return e<t?-1:e>t?1:0}function jf(e,t){return-1*YQ(e,t)}function Hs(e){if(e==null)return e;let t=[];for(let n of e)t.indexOf(n)===-1&&t.push(n);return t}function JQ(e){if(e==null)throw new G(`Invalidvalueinobj:${JSON.stringify(e)}`);for(let t in e)if(e.hasOwnProperty(t))return!1;return!0}function so(e,t,n){if(n!=null&&e.indexOf(n)<0)throw new G(`${n}isnotavalid${t}.Validvaluesare${e}ornull/undefined.`)}function N2(e,t,n=0,a=Infinity){return Rr(n>=0),Rr(a>=n),Array.isArray(e)&&e.length>=n&&e.length<=a&&e.every(r=>typeof r===t)}function An(e,t){Array.isArray(e)?(k.assert(e.length>0,()=>`${t}isunexpectedlyanemptyarray.`),e.forEach((n,a)=>An(n,`element${a+1}of${t}`))):k.assert(Number.isInteger(e)&&e>0,()=>`Expected${t}tobeapositiveinteger,butgot${aI(e)}.`)}function aI(e){return e===null?"null":Array.isArray(e)?"["+e.map(t=>aI(t)).join(",")+"]":typeof e=="string"?`"${e}"`:`${e}`}function QQ(e,t){let n=k.now(),a;return(...r)=>{let s=k.now();return s-n<t||(n=s,a=e(...r)),a}}function rI(e){return e==="relu"?"relu":e==="linear"?"linear":e==="elu"?"elu":null}function T2(e,t){return Z(()=>Mn(Ce(K(e,e),t,!0)))}var _h=class extends ue.Serializable{getConfig(){return{}}},E2=class extends _h{constructor(e){super();this.defaultMaxValue=2,this.defaultAxis=0,this.maxValue=e.maxValue!=null?e.maxValue:this.defaultMaxValue,this.axis=e.axis!=null?e.axis:this.defaultAxis}apply(e){return Z(()=>{let t=T2(e,this.axis),n=ua(t,0,this.maxValue);return K(e,Me(n,pe(dn(),t)))})}getConfig(){return{maxValue:this.maxValue,axis:this.axis}}};E2.className="MaxNorm";ue.registerClass(E2);var C2=class extends _h{constructor(e){super();this.defaultAxis=0,this.axis=e.axis!=null?e.axis:this.defaultAxis}apply(e){return Z(()=>Me(e,pe(dn(),T2(e,this.axis))))}getConfig(){return{axis:this.axis}}};C2.className="UnitNorm";ue.registerClass(C2);var M2=class extends _h{apply(e){return ls(e)}};M2.className="NonNeg";ue.registerClass(M2);var $2=class extends _h{constructor(e){super();this.defaultMinValue=0,this.defaultMaxValue=1,this.defaultRate=1,this.defaultAxis=0,this.minValue=e.minValue!=null?e.minValue:this.defaultMinValue,this.maxValue=e.maxValue!=null?e.maxValue:this.defaultMaxValue,this.rate=e.rate!=null?e.rate:this.defaultRate,this.axis=e.axis!=null?e.axis:this.defaultAxis}apply(e){return Z(()=>{let t=T2(e,this.axis),n=pe(K(this.rate,ua(t,this.minValue,this.maxValue)),K(1-this.rate,t));return K(e,Me(n,pe(dn(),t)))})}getConfig(){return{minValue:this.minValue,maxValue:this.maxValue,rate:this.rate,axis:this.axis}}};$2.className="MinMaxNorm";ue.registerClass($2);var sI={maxNorm:"MaxNorm",minMaxNorm:"MinMaxNorm",nonNeg:"NonNeg",unitNorm:"UnitNorm"};function hn(e){return I2(e)}function iI(e,t={}){return Dh(e,ue.SerializationMap.getMap().classNameMap,t,"constraint")}function pn(e){if(e==null)return null;if(typeof e=="string"){let t={className:e in sI?sI[e]:e,config:{}};return iI(t)}else return e instanceof _h?e:iI(e)}function eee(e){return new E2(e)}function tee(e){return new C2(e)}function nee(){return new M2}function aee(e){return new $2(e)}var oI={};$e(oI,{constant:()=>Nee,glorotNormal:()=>Fee,glorotUniform:()=>Ree,heNormal:()=>Oee,heUniform:()=>Dee,identity:()=>Mee,leCunNormal:()=>_ee,leCunUniform:()=>zee,ones:()=>See,orthogonal:()=>Pee,randomNormal:()=>Eee,randomUniform:()=>Tee,truncatedNormal:()=>Cee,varianceScaling:()=>$ee,zeros:()=>Iee});var ree=["channelsFirst","channelsLast"],see=["nearest","bilinear"],iee=["valid","same","causal"],oee=["max","avg"],lee=["sum","mul","concat","ave"],nu=new Map;function Yt(e){so(ree,"DataFormat",e)}function uee(e){so(see,"Interpolati
becausethevaluedtypeis${t.dtype},butTensorArraydtypeis${this.dtype}.`);if(this.size()===0&&(this.elementShape==null||this.elementShape.length===0)&&(this.elementShape=t.shape),Za(this.elementShape,t.shape,`TensorArray${this.name}:CouldnotwritetoTensorArrayindex${e}.`),n.read)throw new Error(`TensorArray${this.name}:CouldnotwritetoTensorArrayindex${e},becauseithasalreadybeenread.`);if(n.written)throw new Error(`TensorArray${this.name}:CouldnotwritetoTensorArrayindex${e},becauseithasalreadybeenwritten.`);n.tensor=t,Sn(t),n.written=!0,this.tensors[e]=n}writeMany(e,t){if(e.length!==t.length)throw new Error(`TensorArray${this.name}:couldnotwritemultipletensors,becausetheindexsize:${e.length}isnotthesameastensorssize:${t.length}.`);e.forEach((n,a)=>this.write(n,t[a]))}gather(e,t){if(!!t&&t!==this.dtype)throw new Error(`TensorArraydtypeis${this.dtype}butgatherrequesteddtype${t}`);if(e)e=e.slice(0,this.size());else{e=[];for(let a=0;a<this.size();a++)e.push(a)}if(e.length===0)return Cr([],[0].concat(this.elementShape));let n=this.readMany(e);return Za(this.elementShape,n[0].shape,"TensorArray shape mismatch: "),Fa(n,0)}concat(e){if(!!e&&e!==this.dtype)throw new Error(`TensorArraydtypeis${this.dtype}butconcatrequesteddtype${e}`);if(this.size()===0)return Cr([],[0].concat(this.elementShape));let t=[];for(let a=0;a<this.size();a++)t.push(a);let n=this.readMany(t);return Za(this.elementShape,n[0].shape,`TensorArrayshapemismatch:tensorarrayshape(${this.elementShape})vsfirsttensorshape(${n[0].shape})`),en(n,0)}scatter(e,t){if(t.dtype!==this.dtype)throw new Error(`TensorArraydtypeis${this.dtype}buttensorhasdtype${t.dtype}`);if(e.length!==t.shape[0])throw new Error(`Expectedlen(indices)==tensor.shape[0],butsaw:${e.length}vs.${t.shape[0]}`);let n=Math.max(...e);if(!this.dynamicSize&&n>=this.maxSize)throw new Error(`Maxindexmustbe<arraysize(${n}vs.${this.maxSize})`);this.writeMany(e,or(t,0))}split(e,t){if(t.dtype!==this.dtype)throw new Error(`TensorArraydtypeis${this.dtype}buttensorhasdtype${t.dtype}`);let n=0,a=e.map(o=>(n+=o,n));if(n!==t.shape[0])throw new Error(`Expectedsumoflengthstobeequalto
tensor.shape[0],butsumoflengthsis
${n},andtensor's shape is: ${t.shape}`);if(!this.dynamicSize&&e.length!==this.maxSize)throw new Error(`TensorArray'ssizeisnotequaltothesizeoflengths(${this.maxSize}vs.${e.length}),andtheTensorArrayisnotmarkedasdynamicallyresizeable`);let r=n===0?0:t.size/n,s=[];Z(()=>{t=Y(t,[1,n,r]);for(let o=0;o<e.length;++o){let l=o===0?0:a[o-1],u=[0,l,0],d=[1,e[o],r];s[o]=Y(nt(t,u,d),this.elementShape)}return s});let i=[];for(let o=0;o<e.length;o++)i[o]=o;this.writeMany(i,s)}},Qh=class{constructor(e,t,n,a=-1){this.tensors=e,this.elementShape=t,this.elementDtype=n,e!=null&&e.forEach(r=>{if(n!==r.dtype)throw new Error(`Invaliddatatypes;opelements${n},butlistelements${r.dtype}`);Za(t,r.shape,"TensorList shape mismatch: "),Sn(r)}),this.idTensor=Re(0),this.maxNumElements=a,Sn(this.idTensor)}get id(){return this.idTensor.id}copy(){return new Qh([...this.tensors],this.elementShape,this.elementDtype)}clearAndClose(e){this.tensors.forEach(t=>{(e==null||!e.has(t.id))&&t.dispose()}),this.tensors.length=0,this.idTensor.dispose()}size(){return this.tensors.length}stack(e,t,n=-1){if(t!==this.elementDtype)throw new Error(`Invaliddatatypes;opelements${t},butlistelements${this.elementDtype}`);if(n!==-1&&this.tensors.length!==n)throw new Error(`Operationexpectedalistwith${n}elementsbutgotalistwith${this.tensors.length}elements.`);Za(e,this.elementShape,"TensorList shape mismatch: ");let a=Jh(this.elementShape,this.tensors,e);return Z(()=>{let r=this.tensors.map(s=>Y(s,a));return Fa(r,0)})}popBack(e,t){if(t!==this.elementDtype)throw new Error(`Invaliddatatypes;opelements${t},butlistelements${this.elementDtype}`);if(this.size()===0)throw new Error("Trying to pop from an empty list.");let n=Jh(this.elementShape,this.tensors,e),a=this.tensors.pop();return Za(a.shape,e,"TensorList shape mismatch: "),Y(a,n)}pushBack(e){if(e.dtype!==this.elementDtype)throw new Error(`Invaliddatatypes;opelements${e.dtype},butlistelements${this.elementDtype}`);if(Za(e.shape,this.elementShape,"TensorList shape mismatch: "),this.maxNumElements===this.size())throw new Error("Trying to push element into a full list.");Sn(e),this.tensors.push(e)}resize(e){if(e<0)throw new Error(`TensorListResizeexpectssizetobenon-negative.Got:${e}`);if(this.maxNumElements!==-1&&e>this.maxNumElements)throw new Error(`TensorListResizeinputsize${e}isgreatermaxNumElement${this.maxNumElements}.`);this.tensors.length=e}getItem(e,t,n){if(n!==this.elementDtype)throw new Error(`Invaliddatatypes;opelements${n},butlistelements${this.elementDtype}`);if(e<0||e>this.tensors.length)throw new Error(`Tryingtoaccesselement${e}inalistwith${this.tensors.length}elements.`);if(this.tensors[e]==null)throw new Error(`elementatindex${e}isnull.`);Za(this.tensors[e].shape,t,"TensorList shape mismatch: ");let a=Jh(this.elementShape,this.tensors,t);return Y(this.tensors[e],a)}setItem(e,t){if(t.dtype!==this.elementDtype)throw new Error(`Invaliddatatypes;opelements${t.dtype},butlistelements${this.elementDtype}`);if(e<0||this.maxNumElements!==-1&&e>=this.maxNumElements)throw new Error(`Tryingtosetelement${e}inalistwithmax${this.maxNumElements}elements.`);Za(this.elementShape,t.shape,"TensorList shape mismatch: "),Sn(t),this.tensors[e]=t}gather(e,t,n){if(t!==this.elementDtype)throw new Error(`Invaliddatatypes;opelements${t},butlistelements${this.elementDtype}`);Za(this.elementShape,n,"TensorList shape mismatch: "),e=e.slice(0,this.size());let a=Jh(this.elementShape,this.tensors,n);return e.length===0?Cr([],[0].concat(a)):Z(()=>{let r=e.map(s=>Y(this.tensors[s],a));return Fa(r,0)})}concat(e,t){if(!!e&&e!==this.elementDtype)throw new Error(`TensorListdtypeis${this.elementDtype}butconcatrequesteddtype${e}`);Za(this.elementShape,t,"TensorList shape mismatch: ");let n=Jh(this.elementShape,this.tensors,t);return this.size()===0?Cr([],[0].concat(n)):Z(()=>{let a=this.tensors.map(r=>Y(r,n));return en(a,0)})}};function ire(e,t,n){let a=e.dtype;if(e.shape.length<1)throw new Error(`Tensor
${e}`);let a;return this.size===Infinity||this.size==null?a=this.size:t?a=Math.ceil(this.size/e):a=Math.floor(this.size/e),pa(async()=>(await n.iterator()).columnMajorBatch(e,t,lse),a)}concatenate(e){let t=this,n;return this.size===Infinity||e.size===Infinity?n=Infinity:this.size!=null&&e.size!=null?n=this.size+e.size:n=null,pa(async()=>(await t.iterator()).concatenate(await e.iterator()),n)}filter(e){let t=this,n;return this.size===Infinity?n=Infinity:n=null,pa(async()=>(await t.iterator()).filter(a=>Z(()=>e(a))),n)}async forEachAsync(e){return(await this.iterator()).forEachAsync(e)}map(e){let t=this;return pa(async()=>(await t.iterator()).map(n=>Z(()=>e(n))),this.size)}mapAsync(e){let t=this;return pa(async()=>(await t.iterator()).mapAsync(e),this.size)}prefetch(e){if(e==null)throw new RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");let t=this;return pa(async()=>(await t.iterator()).prefetch(e),this.size)}repeat(e){let t=this,n;return this.size!=null&&e>0?n=this.size*e:e===0?n=0:this.size!=null&&(e===void 0||e<0)?n=Infinity:n=null,pa(async()=>{let a=T5(async()=>({value:await t.iterator(),done:!1}));return Gre(a.take(e))},n)}skip(e){let t=this,n;return this.size!=null&&e>=0&&this.size>=e?n=this.size-e:this.size!=null&&(this.size<e||e===void 0||e<0)?n=0:n=null,pa(async()=>(await t.iterator()).skip(e),n)}shuffle(e,t,n=!0){if(e==null||e<0)throw this.size==null?new RangeError("`Dataset.shuffle()` requires bufferSize to be specified."):new RangeError(`\`Dataset.shuffle()\` requires bufferSize to be specified. If your data fits in main memory (for regular JS objects), and/or GPU memory (for \`tf.Tensor\`s), consider setting bufferSize to the dataset size (${this.size} elements)`);leta=this,r=Pre.alea(t||k.now().toString());returnpa(async()=>{lets=r.int32();returnn&&(s+=r.int32()),(awaita.iterator()).shuffle(e,s.toString())},this.size)}take(e){lett=this,n;returnthis.size!=null&&this.size>e?n=e:this.size!=null&&this.size<=e?n=this.size:n=null,pa(async()=>(awaitt.iterator()).take(e),n)}asynctoArray(){if(this.size===Infinity)thrownewError("Can not convert infinite data stream to array.");return(awaitthis.iterator()).toArray()}asynctoArrayForTest(){if(this.size===Infinity)thrownewError("Can not convert infinite data stream to array.");return(awaitthis.iterator()).toArrayForTest()}};uu.MAX_BUFFER_SIZE=1e4;functionpa(e,t=null){returnnewclassextendsuu{constructor(){super(...arguments);this.size=t}asynciterator(){returne()}}}functionise(e){returnpa(async()=>N9(e),e.length)}functionose(e){if(!lu(e))thrownewError("The argument to zip() must be an object or array.");lett;if(Array.isArray(e))for(letn=0;n<e.length;n++)t=t==null?e[n].size:Math.min(t,e[n].size);elseif(einstanceofObject)for(letnine)t=t==null?e[n].size:Math.min(t,e[n].size);returnpa(async()=>{letn=awaitw9(e,a=>{if(ainstanceofuu)return{value:a.iterator(),recurse:!1};if(lu(a))return{value:null,recurse:!0};thrownewError("Leaves of the structure passed to zip() must be Datasets, not primitives.")});returnqre(n,N0.SHORTEST)},t)}functionlse(e){if(e===null)returnnull;lett=e[0];returnVre(t)?{value:use(e),recurse:!1}:{value:null,recurse:!0}}functionuse(e){if(e.length===0)thrownewError("Can't make a batch of zero elements.");returne[0]instanceofTt?Fa(e):Cr(e)}varM9=classextendsuu{constructor(e){super();this.input=e}asynciterator(){return(awaitthis.input.iterator()).decodeUTF8().split(`
`).map(e=>(e.endsWith("\r")&&(e=e.slice(0,-1)),e))}},T0='"',ep=Symbol("out"),$9=Symbol("field"),E0=Symbol("quote"),C5=Symbol("quoteafterquote"),R9=Symbol("quoteinquote"),F9=class extends uu{constructor(e,t){super();this.input=e,this.hasHeader=!0,this.fullColumnNames=null,this.columnNamesValidated=!1,this.columnConfigs=null,this.configuredColumnsOnly=!1,this.delimiter=",",this.delimWhitespace=!1,this.base=new M9(e),t||(t={}),this.hasHeader=t.hasHeader!==!1,this.fullColumnNames=t.columnNames,this.columnConfigs=t.columnConfigs,this.configuredColumnsOnly=t.configuredColumnsOnly,t.delimWhitespace?(k.assert(t.delimiter==null,()=>"Delimiter should not be provided when delimWhitespace is true."),this.delimWhitespace=!0,this.delimiter=" "):this.delimiter=t.delimiter?t.delimiter:","}async columnNames(){return this.columnNamesValidated||await this.setColumnNames(),this.configuredColumnsOnly?Object.keys(this.columnConfigs):this.fullColumnNames}async setColumnNames(){let e=await this.maybeReadHeaderLine();if(!this.fullColumnNames&&!e)throw new Error("Column names must be provided if there is no header line.");this.fullColumnNames&&e&&k.assert(e.length===this.fullColumnNames.length,()=>"The length of provided columnNames ("+this.fullColumnNames.length.toString()+") does not match the length of the header line read from file ("+e.length.toString()+")."),this.fullColumnNames||(this.fullColumnNames=e);let t=this.fullColumnNames.reduce((a,r)=>(a[r]=a[r]+1||1,a),{}),n=Object.keys(t).filter(a=>t[a]>1);if(k.assert(n.length===0,()=>"Duplicate column names found: "+n.toString()),this.columnConfigs){for(let a of Object.keys(this.columnConfigs))if(this.fullColumnNames.indexOf(a)===-1)throw new Error('The key "'+a+'" provided in columnConfigs does not match any of the column names ('+this.fullColumnNames.toString()+").")}this.columnNamesValidated=!0}async maybeReadHeaderLine(){if(this.hasHeader){let e=await(await this.base.iterator()).next();if(e.done)throw new Error("No data was found for CSV parsing.");let t=e.value;return this.parseRow(t,!1)}else return null}async iterator(){this.columnNamesValidated||await this.setColumnNames();let e=await this.base.iterator();return this.hasHeader&&(e=e.skip(1)),e.map(t=>this.makeDataElement(t))}makeDataElement(e){let t=this.parseRow(e),n={},a={};for(let r=0;r<this.fullColumnNames.length;r++){let s=this.fullColumnNames[r],i=this.columnConfigs?this.columnConfigs[s]:null;if(!(this.configuredColumnsOnly&&!i)){let o=t[r],l=null;if(o==="")if(i&&i.default!==void 0)l=i.default;else{if(i&&(i.required||i.isLabel))throw new Error(`Requiredcolumn${s}isemptyinthisline:${e}`);l=void 0}else{let u=Number(o);if(isNaN(u))i&&i.dtype==="bool"?l=this.getBoolean(o):l=o;else if(!i||!i.dtype)l=u;else switch(i.dtype){case"float32":l=u;break;case"int32":l=Math.floor(u);break;case"bool":l=this.getBoolean(o);break;default:l=u}}i&&i.isLabel?a[s]=l:n[s]=l}}return Object.keys(a).length===0?n:{xs:n,ys:a}}getBoolean(e){return e==="1"||e.toLowerCase()==="true"?1:0}parseRow(e,t=!0){let n=[],a=0,r=e.length,s=ep;for(let i=0;i<r;i++)switch(s){case ep:switch(e.charAt(i)){case T0:a=i+1,s=E0;break;case this.delimiter:if(a=i+1,this.delimiter===" "&&this.delimWhitespace)break;n.push(""),s=ep;break;default:s=$9,a=i;break}break;case $9:switch(e.charAt(i)){case this.delimiter:n.push(e.substring(a,i)),s=ep,a=i+1;break;default:}break;case E0:switch(e.charAt(i)){case T0:s=C5;break;default:}break;case C5:switch(e.charAt(i)){case this.delimiter:n.push(e.substring(a,i-1)),s=ep,a=i+1;break;case T0:s=E0;break;default:s=R9;break}break;case R9:switch(e.charAt(i)){case T0:s=E0;break;default:}break;default:}if(s===C5?n.push(e.substring(a,r-1)):n.push(e.substring(a)),t&&n.length!==this.fullColumnNames.length)throw new Error(`Invalidrowincsvfile.Shouldhave${this.fullColumnNames.length}elementsinarow,butgot${n}`);return n}},O9=class extends xn{constructor(e){super();this.microphoneConfig=e,this.isClosed=!1,this.fftSize=e.fftSize||1024;let t=Math.log2(this.fftSize);if(this.fftSize<0||t<4||t>14||!Number.isInteger(t))throw new Error(`InvalidfftSi
============================
Hithere\u{1F44B}.LookslikeyouarerunningTensorFlow.jsinNode.js.Tospeedthingsupdramatically,installournodebackend,whichbindstoTensorFlowC++,byrunningnpmi@tensorflow/tfjs-node,ornpmi@tensorflow/tfjs-node-gpuifyouhaveCUDA.Thencallrequire('@tensorflow/tfjs-node');(-gpusuffixforCUDA)atthestartofyourprogram.Visithttps://github.com/tensorflow/tfjs-node for more details.
============================`));let a={id:this.nextDataId()};return this.data.set(a,{values:e,dtype:n,refCount:1}),a}makeTensorInfo(e,t,n){let a;if(t==="string"&&n!=null&&n.length>0&&k.isString(n[0])){let r=n.map(s=>k.encodeString(s));a=this.write(r,e,t)}else a=this.write(n,e,t);return{dataId:a,shape:e,dtype:t}}refCount(e){return this.data.has(e)?this.data.get(e).refCount:0}incRef(e){let t=this.data.get(e);t.refCount++}decRef(e){if(this.data.has(e)){let t=this.data.get(e);t.refCount--}}move(e,t,n,a,r){this.data.set(e,{values:t,dtype:a,refCount:r})}numDataIds(){return this.data.numDataIds()}async read(e){return this.readSync(e)}readSync(e){let{dtype:t,complexTensorInfos:n}=this.data.get(e);if(t==="complex64"){let a=this.readSync(n.real.dataId),r=this.readSync(n.imag.dataId);return M.mergeRealAndImagArrays(a,r)}return this.data.get(e).values}bufferSync(e){let t=this.readSync(e.dataId),n=t;if(e.dtype==="string")try{n=t.map(a=>k.decodeString(a))}catch(a){throw new Error("Failed to decode encoded string bytes into utf-8")}return Pe(e.shape,e.dtype,n)}makeOutput(e,t,n){let a=this.write(e,t,n);return Ps().makeTensorFromDataId(a,t,n,this)}disposeData(e,t=!1){if(this.data.has(e)){if(this.data.get(e).refCount--,!t&&this.data.get(e).refCount>0)return!1;let{complexTensorInfos:n}=this.data.get(e);n!=null&&(this.disposeData(n.real.dataId,!0),this.disposeData(n.imag.dataId,!0)),this.data.delete(e)}return!0}disposeIntermediateTensorInfo(e){this.disposeData(e.dataId)}async time(e){let t=k.now();return e(),{kernelMs:k.now()-t}}memory(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}}where(e){Se([e],"where");let t=this.readSync(e.dataId);return kse(e.shape,t)}dispose(){}floatPrecision(){return 32}epsilon(){return super.epsilon()}},M5=V9;M5.nextDataId=0;var U9={};$e(U9,{addImpl:()=>H9,bincountImpl:()=>R5,bincountReduceImpl:()=>G9,ceilImpl:()=>q9,concatImpl:()=>K9,equalImpl:()=>X9,expImpl:()=>Y9,expm1Impl:()=>Q9,floorImpl:()=>eN,gatherNdImpl:()=>tN,gatherV2Impl:()=>nN,greaterEqualImpl:()=>rN,greaterImpl:()=>aN,lessEqualImpl:()=>iN,lessImpl:()=>sN,linSpaceImpl:()=>oN,logImpl:()=>lN,maxImpl:()=>uN,maximumImpl:()=>dN,minimumImpl:()=>hN,multiplyImpl:()=>F5,negImpl:()=>pN,notEqualImpl:()=>cN,prodImpl:()=>fN,rangeImpl:()=>mN,rsqrtImpl:()=>gN,simpleAbsImpl:()=>j9,sliceImpl:()=>yN,sparseFillEmptyRowsImpl:()=>AN,sparseReshapeImpl:()=>xN,sparseSegmentReductionImpl:()=>D5,squaredDifferenceImpl:()=>bN,stridedSliceImpl:()=>vN,stringNGramsImpl:()=>wN,stringSplitImpl:()=>kN,stringToHashBucketFastImpl:()=>IN,subImpl:()=>SN,tileImpl:()=>NN,topKImpl:()=>TN,transposeImpl:()=>O5,uniqueImpl:()=>EN});function j9(e){let t=new Float32Array(e.length);for(let n=0;n<e.length;++n)t[n]=Math.abs(e[n]);return t}var Ise=e=>{let{x:t}=e.inputs,n=e.backend;Se(t,"abs");let a=new Float32Array(k.sizeFromShape(t.shape)),r=n.data.get(t.dataId).values;return a=j9(r),n.makeOutput(a,t.shape,"float32")},Sse={kernelName:xd,backendName:"cpu",kernelFunc:Ise};function nn(e){return(t,n,a,r,s)=>{let i=M.assertAndGetBroadcastShape(t,n),o=i.length,l=k.computeStrides(i),u=k.sizeFromShape(i),d=k.getTypedArrayFromDType(s,u),h=t.length,p=n.length,c=k.computeStrides(t),m=k.computeStrides(n),f=M.getBroadcastDims(t,i),g=M.getBroadcastDims(n,i);if(f.length+g.length===0)for(let y=0;y<d.length;++y)d[y]=e(a[y%a.length],r[y%r.length]);else for(let y=0;y<d.length;++y){let A=k.indexToLoc(y,o,l),x=A.slice(-h);f.forEach(I=>x[I]=0);let v=k.locToIndex(x,h,c),b=A.slice(-p);g.forEach(I=>b[I]=0);let w=k.locToIndex(b,p,m);d[y]=e(a[v],r[w])}return[d,i]}}function ca(e){let{inputs:t,backend:n}=e,{real:a,imag:r}=t,s=n.data.get(a.dataId).values,i=n.data.get(r.dataId).values,o=n.makeTensorInfo(a.shape,"complex64"),l=n.data.get(o.dataId);return l.complexTensorInfos={real:n.makeTensorInfo(a.shape,"float32",s),imag:n.makeTensorInfo(r.shape,"float32",i)},o}var Nse={kernelName:I1,backendName:"cpu",kernelFunc:ca};function C0(e,t,n="float32"){if(n==="complex64"){let r=C0(e,t,"float32"),s=C0(e,t,"float32");return ca({inputs:{re
indices.shape[0]=${o}`);let g=k.getArrayFromDType(n,0),y=k.getArrayFromDType(r,0);return[g,[0,h],y,u,d]}let p=!0,c=0,m=new Array(l).fill(0);for(let g=0;g<o;++g){let y=e[g*h];if(y<0)throw new Error(`indices(${g},0)isinvalid:${y}<0`);if(y>=l)throw new Error(`indices(${g},0)isinvalid:${y}>=${l}`);++m[y],p=p&&y>=c,c=y}let f=!0;for(let g=0;g<l;++g){let y=m[g]===0;u[g]=y,f=f&&!y,m[g]=Math.max(m[g],1),g>0&&(m[g]+=m[g-1])}if(f&&p){let g=e,y=a;for(let A=0;A<o;++A)d[A]=A;return[g,[o,h],y,u,d]}else{let g=m[l-1],y=k.getArrayFromDType(n,g*h),A=k.getArrayFromDType(r,g),x=new Array(l).fill(0);for(let v=0;v<o;++v){let b=e[v*h],w=x[b],I=(b===0?0:m[b-1])+w;x[b]++;for(let T=0;T<h;++T)y[I*h+T]=e[v*h+T];A[I]=a[v],d[v]=I}for(let v=0;v<l;++v)if(x[v]===0){let b=v===0?0:m[v-1];y[b*h+0]=v;for(let w=1;w<h;++w)y[b*h+w]=0;A[b]=i}return[y,[g,h],A,u,d]}}function xN(e,t,n,a,r){let s=k.sizeFromShape(a),i=t[0],o=r.length,l=[],u=1,d=-1;for(let g=0;g<o;++g){let y=r[g];if(y===-1){if(d!==-1)throw new Error(`onlyoneoutputdimensionmaybe-1,notboth${d}and${g}`);d=g,l.push(1)}else{if(y<0)throw new Error(`size${g}mustbenon-negative,not${y}`);u*=y,l.push(y)}}if(d!==-1){if(u<=0)throw new Error("reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero");let g=Math.trunc(s/u);if(u*g!==s)throw new Error(`InputtoreshapeisaSparseTensorwith${s}
densevalues,buttherequestedshaperequiresamultipleof${u}.inputShape=${a}outputShape=${l}`);l[d]=g}let h=k.sizeFromShape(l);if(h!==s)throw new Error(`Inputtoreshapeisatensorwith${s}densevalues,buttherequestedshapehas${h}.inputShape=${a}outputShape=${l}`);let p=a.length,c=[];if(p>0){c[p-1]=1;for(let g=p-2;g>=0;--g)c[g]=c[g+1]*a[g+1]}let m=[];if(o>0){m[o-1]=1;for(let g=o-2;g>=0;--g)m[g]=m[g+1]*l[g+1]}let f=k.getArrayFromDType(n,i*o);for(let g=0;g<i;++g){let y=0;for(let A=0;A<p;++A)y+=e[g*p+A]*c[A];for(let A=0;A<o;++A)f[g*o+A]=Math.trunc(y/m[A]),y%=m[A]}return[f,[i,o],l]}function D5(e,t,n,a,r,s=!1,i=0){let o=a.length;if(o!==r.length)throw new Error("segmentIds and indices should have same size.");let l=[t[0],e.length/t[0]],u=l[1],d=o>0?r[o-1]+1:0;if(d<0)throw new Error("segment ids must be >= 0");let h=t.slice();h[0]=d;let p=h.reduce((A,x)=>A*x,1),c=k.getArrayFromDType(n,p);if(o===0)return d>0&&c.fill(i),[c,h];if(d<=0)throw new Error("segment ids must be >= 0");let m=0,f=1,g=0,y=r[m];for(;;){let A=0;if(f<o){if(A=r[f],y===A){++f;continue}if(y>=A)throw new Error("segment ids are not increasing")}if(y<0||y>=d)throw new Error(`Segmentid${y}outofrange[0,${d}),possiblybecausesegmentIdsinputisnotsorted.`);y>g&&c.fill(i,g*u,y*u);for(let x=m;x<f;++x){let v=a[x];if(v<0||v>=l[0])throw new Error(`Bad:indices[${x}]==${a[x]}outofrange[0,${l[0]})`);for(let b=0;b<u;b++)c[y*u+b]+=e[v*u+b]}if(s)for(let x=0;x<u;x++)c[y*u+x]/=f-m;if(m=f,++f,g=y+1,y=A,f>o)break}return g<d&&c.fill(i,g*u,d*u),[c,h]}var bN=nn((e,t)=>{let n=e-t;return n*n}),pie=bn(_i,bN),cie={kernelName:_i,backendName:"cpu",kernelFunc:pie};function vN(e,t,n,a){let r=Pe(e,t.dtype);for(let s=0;s<r.size;s++){let i=r.indexToLoc(s),o=new Array(i.length);for(let l=0;l<o.length;l++)o[l]=i[l]*n[l]+a[l];r.set(t.get(...o),...i)}return r}var fie=class{constructor(e,t,n,a,r,s){this.separator=k.encodeString(e),this.nGramWidths=t,this.leftPad=k.encodeString(n),this.rightPad=k.encodeString(a),this.padWidth=r,this.preserveShort=s}getPadWidth(e){return Math.min(this.padWidth<0?e-1:this.padWidth,e-1)}getNumNGrams(e,t){let n=this.getPadWidth(t);return Math.max(0,e+2*n-t+1)}createNGrams(e,t,n,a,r,s){for(let i=0;i<r;++i){let o=this.getPadWidth(s),l=Math.max(0,o-i),u=Math.max(0,o-(r-(i+1))),d=s-(l+u),h=t+(l>0?0:i-o),p=0;p+=l*this.leftPad.length;for(let g=0;g<d;++g)p+=e[h+g].length;p+=u*this.rightPad.length,p+=(l+u+d-1)*this.separator.length,n[a+i]=new Uint8Array(p);let c=n[a+i],m=0,f=g=>g.forEach(y=>c[m++]=y);for(let g=0;g<l;++g)f(this.leftPad),f(this.separator);for(let g=0;g<d-1;++g)f(e[h+g]),f(this.separator);if(d>0){f(e[h+d-1]);for(let g=0;g<u;++g)f(this.separator),f(this.rightPad)}else{for(let g=0;g<u-1;++g)f(this.rightPad),f(this.separator);f(this.rightPad)}}}compute(e,t){let n=e.length,a=t.length;if(a>0){let o=t[0];if(o!==0)throw new Error(`Firstsplitvaluemustbe0,got${o}`);for(let l=1;l<a;++l){let u=t[l]>=o;if(u=u&&t[l]<=n,!u)throw new Error(`Invalidsplitvalue${t[l]},mustbein[${o},${n}]`);o=t[l]}if(o!==n)throw new Error(`Lastsplitvaluemustbedatasize.Expected${n},got${o}`)}let r=a-1,s=k.getArrayFromDType("int32",a);if(n===0||a===0){let o=new Array(n);for(let l=0;l<=r;++l)s[l]=0;return[o,s]}s[0]=0;for(let o=1;o<=r;++o){let l=t[o]-t[o-1],u=0;this.nGramWidths.forEach(d=>{u+=this.getNumNGrams(l,d)}),this.preserveShort&&l>0&&u===0&&(u=1),s[o]=s[o-1]+u}let i=new Array(s[r]);for(let o=0;o<r;++o){let l=t[o],u=s[o];if(this.nGramWidths.forEach(d=>{let h=t[o+1]-t[o],p=this.getNumNGrams(h,d);this.createNGrams(e,l,i,u,p,d),u+=p}),this.preserveShort&&u===s[o]){let d=t[o+1]-t[o];if(d===0)continue;let h=d+2*this.padWidth,p=1;this.createNGrams(e,l,i,u,p,h)}}return[i,s]}};function wN(e,t,n,a,r,s,i,o){return new fie(n,a,r,s,i,o).compute(e,t)}function mie(e,t,n){if(!e.length)return[];if(t.length===0){let s=new Array(e.length);for(let i=0;i<e.length;++i)s[i]=e.subarray(i,i+1);return s}if(t.length===1){let s=t[0],i=[],o=e.indexOf(s);for(;o!==-1;){let l=e.subarray(0,o);(!n||l.length!==0)&&i.push(l),e=e.subarray(o+1),o=e.indexOf(s)}retur
${s.shape}`);if(a.shape.length!==2)throw new Error(`Indicesmustbeamatrix,saw:
${a.shape}`);if(r.shape.length!==1)throw new Error(`Valuesmustbeavector,saw:
${r.shape}`);if(i.shape.length!==0)throw new Error(`Defaultvaluemustbeascalar,saw:
${i.shape}`);let o=n.data.get(a.dataId).values,l=n.data.get(r.dataId).values,u=n.data.get(s.dataId).values,d=n.data.get(i.dataId).values[0],[h,p,c,m,f]=AN(o,a.shape,a.dtype,l,r.dtype,u,d);return[n.makeTensorInfo(p,a.dtype,h),n.makeTensorInfo([p[0]],r.dtype,c),n.makeTensorInfo([m.length],"bool",new Uint8Array(m.map(g=>Number(g)))),n.makeTensorInfo([f.length],a.dtype,new Int32Array(f))]}var Mde={kernelName:K1,backendName:"cpu",kernelFunc:Cde};function $de(e){let{inputs:t,backend:n}=e,{inputIndices:a,inputShape:r,newShape:s}=t;if(a.shape.length!==2)throw new Error(`Inputindicesshouldbeamatrixbutreceivedshape
${a.shape}`);if(r.shape.length!==1)throw new Error(`Inputshapeshouldbeavectorbutreceivedshape
${r.shape}`);if(s.shape.length!==1)throw new Error(`Targetshapeshouldbeavectorbutreceivedshape${s.shape}`);let i=Array.from(n.data.get(r.dataId).values),o=n.data.get(a.dataId).values,l=Array.from(n.data.get(s.dataId).values),[u,d,h]=xN(o,a.shape,a.dtype,i,l);return[n.makeTensorInfo(d,a.dtype,u),n.makeTensorInfo([h.length],s.dtype,new Int32Array(h))]}var Rde={kernelName:X1,backendName:"cpu",kernelFunc:$de};function Fde(e){let{inputs:t,backend:n}=e,{data:a,indices:r,segmentIds:s}=t;if(a.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(r.shape.length!==1)throw new Error(`Indicesshouldbeavectorbutreceivedshape
${r.shape}`);if(s.shape.length!==1)throw new Error(`Segmentidsshouldbeavectorbutreceivedshape
${s.shape}`);let i=n.data.get(a.dataId).values,o=n.data.get(r.dataId).values,l=n.data.get(s.dataId).values,[u,d]=D5(i,a.shape,a.dtype,o,l,!0);return n.makeTensorInfo(d,a.dtype,u)}var Ode={kernelName:Z1,backendName:"cpu",kernelFunc:Fde};function Dde(e){let{inputs:t,backend:n}=e,{data:a,indices:r,segmentIds:s}=t;if(a.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(r.shape.length!==1)throw new Error(`Indicesshouldbeavectorbutreceivedshape
${r.shape}`);if(s.shape.length!==1)throw new Error(`Segmentidsshouldbeavectorbutreceivedshape
${s.shape}`);let i=n.data.get(a.dataId).values,o=n.data.get(r.dataId).values,l=n.data.get(s.dataId).values,[u,d]=D5(i,a.shape,a.dtype,o,l);return n.makeTensorInfo(d,a.dtype,u)}var _de={kernelName:Y1,backendName:"cpu",kernelFunc:Dde};function zde(e){let{inputs:t,backend:n,attrs:a}=e,{sparseIndices:r,sparseValues:s,defaultValue:i}=t,{outputShape:o}=a,{sliceRank:l,numUpdates:u,sliceSize:d,strides:h,outputSize:p}=M.calculateShapes(s,r,o),c=!1,m=n.bufferSync(r),f=n.bufferSync(s),g=n.data.get(i.dataId).values[0],y=GN(m,f,o,p,d,u,l,h,g,c);return n.makeTensorInfo(o,y.dtype,y.values)}var Pde={kernelName:J1,backendName:"cpu",kernelFunc:zde};function Lde(e){let{inputs:t,backend:n,attrs:a}=e,{x:r}=t,{numOrSizeSplits:s,axis:i}=a,o=k.parseAxisParam(i,r.shape)[0],l=M.prepareSplitSize(r,s,o),u=new Array(r.shape.length).fill(0),d=r.shape.slice();return l.map(h=>{let p=[...d];p[o]=h;let c=fo({inputs:{x:r},backend:n,attrs:{begin:u,size:p}});return u[o]+=h,c})}var Wde={kernelName:oh,backendName:"cpu",kernelFunc:Lde},Bde=xt(Fl,e=>Math.sqrt(e)),Vde={kernelName:Fl,backendName:"cpu",kernelFunc:Bde},Ude={kernelName:lf,backendName:"cpu",kernelFunc:({inputs:e,backend:t})=>{let{x:n}=e,a=t;Se(n,"square");let r=a.data.get(n.dataId).values,s=new Float32Array(r.length);for(let i=0;i<r.length;++i){let o=r[i];s[i]=o*o}return{dataId:a.write(s,n.shape,n.dtype),shape:n.shape,dtype:n.dtype}}},jde=xt(Li,(e,t)=>{let n=t;return isNaN(e)?NaN:e>0?1:n.alpha}),Hde={kernelName:Li,backendName:"cpu",kernelFunc:jde};function Gde(e){let{inputs:t,backend:n,attrs:a}=e,{x:r}=t,{begin:s,end:i,strides:o,beginMask:l,endMask:u,ellipsisMask:d,newAxisMask:h,shrinkAxisMask:p}=a;Se(r,"stridedSlice");let{nonStrided:c,$begin:m,$strides:f,size:g,newShape:y,outShape:A}=Cn.sliceInfo(r.shape,s,i,o,l,u,d,h,p),x=Ot({inputs:{x:r},backend:n,attrs:{shape:y}}),v;if(c){let w=fo({inputs:{x},backend:n,attrs:{begin:m,size:g}});v=Ot({inputs:{x:w},backend:n,attrs:{shape:A}}),n.disposeIntermediateTensorInfo(w)}else if(A.some(w=>w===0))v=n.makeTensorInfo(A,r.dtype,[]);else{let w=n.bufferSync(x),I=vN(A,w,f,m);v=n.makeTensorInfo(I.shape,I.dtype,I.values)}let b=Ot({inputs:{x:v},backend:n,attrs:{shape:A}});return n.disposeIntermediateTensorInfo(x),n.disposeIntermediateTensorInfo(v),b}var qde={kernelName:lh,backendName:"cpu",kernelFunc:Gde};function Kde(e){let{inputs:t,backend:n,attrs:a}=e,{separator:r,nGramWidths:s,leftPad:i,rightPad:o,padWidth:l,preserveShortSequences:u}=a,{data:d,dataSplits:h}=t,p=n.data.get(d.dataId).values,c=n.data.get(h.dataId).values,[m,f]=wN(p,c,r,s,i,o,l,u);return[n.makeTensorInfo([m.length],"string",m),n.makeTensorInfo(h.shape,"int32",f)]}var Xde={kernelName:Q1,backendName:"cpu",kernelFunc:Kde};function Zde(e){let{inputs:t,backend:n,attrs:a}=e,{skipEmpty:r}=a,{input:s,delimiter:i}=t;if(s.dtype!=="string")throw new Error("Input must be of datatype string");if(s.shape.length!==1)throw new Error(`Inputmustbeavector,gotshape:${s.shape}`);if(i.shape.length!==0)throw new Error(`Delimitermustbeascalar,gotshape:${i.shape}`);let o=n.data.get(s.dataId).values,l=n.data.get(i.dataId).values[0],[u,d,h]=kN(o,l,r),p=d.length;return[n.makeTensorInfo([p,2],"int32",u),n.makeTensorInfo([p],"string",d),n.makeTensorInfo([2],"int32",new Int32Array(h))]}var Yde={kernelName:eA,backendName:"cpu",kernelFunc:Zde};function Jde(e){let{inputs:t,backend:n,attrs:a}=e,{numBuckets:r}=a,{input:s}=t;if(s.dtype!=="string")throw new Error("Input must be of datatype string");if(r<=0)throw new Error("Number of buckets must be at least 1");let i=n.data.get(s.dataId).values,o=IN(i,r);return n.makeTensorInfo(s.shape,"int32",o)}var Qde={kernelName:tA,backendName:"cpu",kernelFunc:Jde},ehe=xt(_l,e=>Math.tan(e)),the={kernelName:_l,backendName:"cpu",kernelFunc:ehe},nhe=xt(zl,e=>Math.tanh(e)),ahe={kernelName:zl,backendName:"cpu",kernelFunc:nhe};function rhe(e){let{inputs:t,backend:n,attrs:a}=e,{x:r}=t,{reps:s}=a;Se(r,"tile");let i=NN(n.bufferSync(r),s);return n.makeTensorInfo(i.shape,i.dtype,i.values)}var she={kernelName:Pi,backendName:"cpu",kernelFunc:rhe};function ihe(e){let{inputs:t,backend:n,attrs:a
// Explicitly use integer operations as dot() only works on floats.
intindex=row*${r}+col*${s}+depth+${c};
vec2uv=uvFromFlat(${d},${h},index);
returnsampleTexture(${n},uv);
}
`}function vpe(e){let t=e.shapeInfo.logicalShape,n=t.length,a=e.name,r="get"+a.charAt(0).toUpperCase()+a.slice(1),s=e.shapeInfo.texShape,i=[Math.ceil(s[0]/2),Math.ceil(s[1]/2)],o=i[0],l=i[1],u=Math.ceil(t[n-1]/2),d=u*Math.ceil(t[n-2]/2),h="int b, int row, int col",p=`b*${d}+(row/2)*${u}+(col/2)`;for(let m=2;m<n-1;m++)h=`intb${m},`+h,d*=t[n-m-1],p=`b${m}*${d}+`+p;let c=Wn();return`
indices.shape[0]=${o}`);let g=k.getArrayFromDType(n,0),y=k.getArrayFromDType(r,0);return[g,[0,h],y,u,d]}let p=!0,c=0,m=new Array(l).fill(0);for(let g=0;g<o;++g){let y=e[g*h];if(y<0)throw new Error(`indices(${g},0)isinvalid:${y}<0`);if(y>=l)throw new Error(`indices(${g},0)isinvalid:${y}>=${l}`);++m[y],p=p&&y>=c,c=y}let f=!0;for(let g=0;g<l;++g){let y=m[g]===0;u[g]=y,f=f&&!y,m[g]=Math.max(m[g],1),g>0&&(m[g]+=m[g-1])}if(f&&p){let g=e,y=a;for(let A=0;A<o;++A)d[A]=A;return[g,[o,h],y,u,d]}else{let g=m[l-1],y=k.getArrayFromDType(n,g*h),A=k.getArrayFromDType(r,g),x=new Array(l).fill(0);for(let v=0;v<o;++v){let b=e[v*h],w=x[b],I=(b===0?0:m[b-1])+w;x[b]++;for(let T=0;T<h;++T)y[I*h+T]=e[v*h+T];A[I]=a[v],d[v]=I}for(let v=0;v<l;++v)if(x[v]===0){let b=v===0?0:m[v-1];y[b*h+0]=v;for(let w=1;w<h;++w)y[b*h+w]=0;A[b]=i}return[y,[g,h],A,u,d]}}function jpe(e,t,n,a,r){let s=k.sizeFromShape(a),i=t[0],o=r.length,l=[],u=1,d=-1;for(let g=0;g<o;++g){let y=r[g];if(y===-1){if(d!==-1)throw new Error(`onlyoneoutputdimensionmaybe-1,notboth${d}and${g}`);d=g,l.push(1)}else{if(y<0)throw new Error(`size${g}mustbenon-negative,not${y}`);u*=y,l.push(y)}}if(d!==-1){if(u<=0)throw new Error("reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero");let g=Math.trunc(s/u);if(u*g!==s)throw new Error(`InputtoreshapeisaSparseTensorwith${s}
densevalues,buttherequestedshaperequiresamultipleof${u}.inputShape=${a}outputShape=${l}`);l[d]=g}let h=k.sizeFromShape(l);if(h!==s)throw new Error(`Inputtoreshapeisatensorwith${s}densevalues,buttherequestedshapehas${h}.inputShape=${a}outputShape=${l}`);let p=a.length,c=[];if(p>0){c[p-1]=1;for(let g=p-2;g>=0;--g)c[g]=c[g+1]*a[g+1]}let m=[];if(o>0){m[o-1]=1;for(let g=o-2;g>=0;--g)m[g]=m[g+1]*l[g+1]}let f=k.getArrayFromDType(n,i*o);for(let g=0;g<i;++g){let y=0;for(let A=0;A<p;++A)y+=e[g*p+A]*c[A];for(let A=0;A<o;++A)f[g*o+A]=Math.trunc(y/m[A]),y%=m[A]}return[f,[i,o],l]}function Hpe(e,t,n,a,r,s=!1,i=0){let o=a.length;if(o!==r.length)throw new Error("segmentIds and indices should have same size.");let l=[t[0],e.length/t[0]],u=l[1],d=o>0?r[o-1]+1:0;if(d<0)throw new Error("segment ids must be >= 0");let h=t.slice();h[0]=d;let p=h.reduce((A,x)=>A*x,1),c=k.getArrayFromDType(n,p);if(o===0)return d>0&&c.fill(i),[c,h];if(d<=0)throw new Error("segment ids must be >= 0");let m=0,f=1,g=0,y=r[m];for(;;){let A=0;if(f<o){if(A=r[f],y===A){++f;continue}if(y>=A)throw new Error("segment ids are not increasing")}if(y<0||y>=d)throw new Error(`Segmentid${y}outofrange[0,${d}),possiblybecausesegmentIdsinputisnotsorted.`);y>g&&c.fill(i,g*u,y*u);for(let x=m;x<f;++x){let v=a[x];if(v<0||v>=l[0])throw new Error(`Bad:indices[${x}]==${a[x]}outofrange[0,${l[0]})`);for(let b=0;b<u;b++)c[y*u+b]+=e[v*u+b]}if(s)for(let x=0;x<u;x++)c[y*u+x]/=f-m;if(m=f,++f,g=y+1,y=A,f>o)break}return g<d&&c.fill(i,g*u,d*u),[c,h]}var lE=Pa((e,t)=>{let n=e-t;return n*n}),r7e=Ya(_i,lE);function Gpe(e,t,n,a){let r=Pe(e,t.dtype);for(let s=0;s<r.size;s++){let i=r.indexToLoc(s),o=new Array(i.length);for(let l=0;l<o.length;l++)o[l]=i[l]*n[l]+a[l];r.set(t.get(...o),...i)}return r}var qpe=class{constructor(e,t,n,a,r,s){this.separator=k.encodeString(e),this.nGramWidths=t,this.leftPad=k.encodeString(n),this.rightPad=k.encodeString(a),this.padWidth=r,this.preserveShort=s}getPadWidth(e){return Math.min(this.padWidth<0?e-1:this.padWidth,e-1)}getNumNGrams(e,t){let n=this.getPadWidth(t);return Math.max(0,e+2*n-t+1)}createNGrams(e,t,n,a,r,s){for(let i=0;i<r;++i){let o=this.getPadWidth(s),l=Math.max(0,o-i),u=Math.max(0,o-(r-(i+1))),d=s-(l+u),h=t+(l>0?0:i-o),p=0;p+=l*this.leftPad.length;for(let g=0;g<d;++g)p+=e[h+g].length;p+=u*this.rightPad.length,p+=(l+u+d-1)*this.separator.length,n[a+i]=new Uint8Array(p);let c=n[a+i],m=0,f=g=>g.forEach(y=>c[m++]=y);for(let g=0;g<l;++g)f(this.leftPad),f(this.separator);for(let g=0;g<d-1;++g)f(e[h+g]),f(this.separator);if(d>0){f(e[h+d-1]);for(let g=0;g<u;++g)f(this.separator),f(this.rightPad)}else{for(let g=0;g<u-1;++g)f(this.rightPad),f(this.separator);f(this.rightPad)}}}compute(e,t){let n=e.length,a=t.length;if(a>0){let o=t[0];if(o!==0)throw new Error(`Firstsplitvaluemustbe0,got${o}`);for(let l=1;l<a;++l){let u=t[l]>=o;if(u=u&&t[l]<=n,!u)throw new Error(`Invalidsplitvalue${t[l]},mustbein[${o},${n}]`);o=t[l]}if(o!==n)throw new Error(`Lastsplitvaluemustbedatasize.Expected${n},got${o}`)}let r=a-1,s=k.getArrayFromDType("int32",a);if(n===0||a===0){let o=new Array(n);for(let l=0;l<=r;++l)s[l]=0;return[o,s]}s[0]=0;for(let o=1;o<=r;++o){let l=t[o]-t[o-1],u=0;this.nGramWidths.forEach(d=>{u+=this.getNumNGrams(l,d)}),this.preserveShort&&l>0&&u===0&&(u=1),s[o]=s[o-1]+u}let i=new Array(s[r]);for(let o=0;o<r;++o){let l=t[o],u=s[o];if(this.nGramWidths.forEach(d=>{let h=t[o+1]-t[o],p=this.getNumNGrams(h,d);this.createNGrams(e,l,i,u,p,d),u+=p}),this.preserveShort&&u===s[o]){let d=t[o+1]-t[o];if(d===0)continue;let h=d+2*this.padWidth,p=1;this.createNGrams(e,l,i,u,p,h)}}return[i,s]}};function Kpe(e,t,n,a,r,s,i,o){return new qpe(n,a,r,s,i,o).compute(e,t)}function Xpe(e,t,n){if(!e.length)return[];if(t.length===0){let s=new Array(e.length);for(let i=0;i<e.length;++i)s[i]=e.subarray(i,i+1);return s}if(t.length===1){let s=t[0],i=[],o=e.indexOf(s);for(;o!==-1;){let l=e.subarray(0,o);(!n||l.length!==0)&&i.push(l),e=e.subarray(o+1),o=e.indexOf(s)}return(!n||e.length!==0)&&i.push(e),i}let a=[],r=0;for(
`}var Hce=class{constructor(e){this.gpgpu=e,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}acquireTexture(e,t,n){let a=gE(t,n),r=yE(e,a,n);r in this.freeTextures||(this.freeTextures[r]=[]),r in this.usedTextures||(this.usedTextures[r]=[]);let s=mE(e,a,this.gpgpu.gl,this.gpgpu.textureConfig,n);if(this.freeTextures[r].length>0){this.numFreeTextures--,this.numUsedTextures++,this._numBytesFree-=s,this.log();let o=this.freeTextures[r].shift();return this.usedTextures[r].push(o),o}let i;return a===Nn.PACKED_2X2_FLOAT32?i=this.gpgpu.createPackedMatrixTexture(e[0],e[1]):a===Nn.PACKED_2X2_FLOAT16?i=this.gpgpu.createFloat16PackedMatrixTexture(e[0],e[1]):a===Nn.UNPACKED_FLOAT32?i=this.gpgpu.createFloat32MatrixTexture(e[0],e[1]):a===Nn.UNPACKED_FLOAT16?i=this.gpgpu.createFloat16MatrixTexture(e[0],e[1]):a===Nn.PACKED_4X1_UNSIGNED_BYTE&&(i=this.gpgpu.createUnsignedBytesMatrixTexture(e[0],e[1])),this.usedTextures[r].push(i),this.numUsedTextures++,this._numBytesAllocated+=s,this.log(),i}releaseTexture(e,t,n,a){if(this.freeTextures==null)return;let r=gE(n,a),s=yE(t,r,a);s in this.freeTextures||(this.freeTextures[s]=[]);let i=mE(t,r,this.gpgpu.gl,this.gpgpu.textureConfig,a),o=se().get("WEBGL_DELETE_TEXTURE_THRESHOLD");o!==-1&&this._numBytesAllocated>o?(this.gpgpu.deleteMatrixTexture(e),this._numBytesAllocated-=i):(this.freeTextures[s].push(e),this.numFreeTextures++,this._numBytesFree+=i),this.numUsedTextures--;let l=this.usedTextures[s],u=l.indexOf(e);if(u<0)throw new Error("Cannot release a texture that was never provided by this texture manager");l.splice(u,1),this.log()}log(){if(!this.logEnabled)return;let e=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",`${this.numFreeTextures}/${this.numUsedTextures}`,`(${e})`);let t=this._numBytesFree/this._numBytesAllocated;console.log(`Bytesallocated:${this._numBytesAllocated}`),console.log(`Bytesunused:${this._numBytesFree}(${Math.round(100*t)}%)`)}get numBytesAllocated(){return this._numBytesAllocated}get numBytesFree(){return this._numBytesFree}getNumUsedTextures(){return this.numUsedTextures}getNumFreeTextures(){return this.numFreeTextures}dispose(){if(this.freeTextures!=null){for(let e in this.freeTextures)this.freeTextures[e].forEach(t=>{this.gpgpu.deleteMatrixTexture(t)});for(let e in this.usedTextures)this.usedTextures[e].forEach(t=>{this.gpgpu.deleteMatrixTexture(t)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0}}};function Gce(e,t){let n=e;if(t===n.R32F)return 4;if(t===n.R16F)return 2;if(t===n.RGBA32F||t===e.RGBA)return 16;if(t===n.RGBA16F)return 8;throw new Error(`Unknowninternalformat${t}`)}function mE(e,t,n,a,r){let s=qce(t,a),i;if(r){let[l,u]=fu(e[0],e[1]);i=l*u}else{let[l,u]=sp(e[0],e[1]);i=l*u}let o=Gce(n,s);return i*o}function qce(e,t){switch(e){case Nn.PACKED_2X2_FLOAT32:return Q5(t);case Nn.PACKED_2X2_FLOAT16:return eb(t);case Nn.UNPACKED_FLOAT32:return Z5(t);case Nn.UNPACKED_FLOAT16:return Y5(t);case Nn.PACKED_4X1_UNSIGNED_BYTE:return J5(t);default:throw new Error(`Unknownphysicaltexturetype${e}`)}}function Kce(e){return se().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?e?Nn.PACKED_2X2_FLOAT32:Nn.UNPACKED_FLOAT32:e?Nn.PACKED_2X2_FLOAT16:Nn.UNPACKED_FLOAT16}function gE(e,t){if(e===_a.UPLOAD)return Nn.PACKED_2X2_FLOAT32;if(e===_a.RENDER||e==null)return Kce(t);if(e===_a.DOWNLOAD||e===_a.PIXELS)return Nn.PACKED_4X1_UNSIGNED_BYTE;throw new Error(`Unknownlogicaltexturetype${e}`)}function yE(e,t,n){return`${e[0]}_${e[1]}_${t}_${n}`}var Qs=class{constructor(e,t){this.variableNames=["A"],this.outputShape=e,this.userCode=`
`}},ife=us.whereImpl,ofe=1e-7,lfe=1e-4,ob={};function ufe(e){return e in ob||(ob[e]={}),ob[e]}var dfe=()=>se().getNumber("CPU_HANDOFF_SIZE_THRESHOLD"),hfe=600;function pfe(){return se().global.screen==null?1024:se().global.screen.height*se().global.screen.width*window.devicePixelRatio*hfe/1024/1024}var xE=class extends Wc{constructor(e){super();if(this.pendingRead=new WeakMap,this.pendingDisposal=new WeakSet,this.dataRefCount=new WeakMap,this.numBytesInGPU=0,this.uploadWaitMs=0,this.downloadWaitMs=0,this.lastGlFlushTime=0,this.warnedAboutMemory=!1,this.pendingDeletes=0,this.disposed=!1,!se().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(e==null){let t=Pr(se().getNumber("WEBGL_VERSION"));this.binaryCache=ufe(se().getNumber("WEBGL_VERSION")),this.gpgpu=new W0(t),this.canvas=t.canvas,this.gpgpuCreatedLocally=!0}else this.gpgpu=e,this.binaryCache={},this.gpgpuCreatedLocally=!1,this.canvas=e.gl.canvas;this.textureManager=new Hce(this.gpgpu),this.numMBBeforeWarning=pfe(),this.texData=new f1(this,Ps())}nextDataId(){return xE.nextDataId++}numDataIds(){return this.texData.numDataIds()-this.pendingDeletes}write(e,t,n){if((se().getBool("WEBGL_CHECK_NUMERICAL_PROBLEMS")||se().getBool("DEBUG"))&&this.checkNumericalProblems(e),n==="complex64"&&e!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");let a={id:this.nextDataId()};return this.texData.set(a,{shape:t,dtype:n,values:e,usage:_a.UPLOAD,refCount:1}),a}refCount(e){return this.texData.has(e)?this.texData.get(e).refCount:0}incRef(e){let t=this.texData.get(e);t.refCount++}decRef(e){if(this.texData.has(e)){let t=this.texData.get(e);t.refCount--}}move(e,t,n,a,r){if(se().getBool("DEBUG")&&this.checkNumericalProblems(t),a==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(e,{shape:n,dtype:a,values:t,usage:_a.UPLOAD,refCount:r})}disposeIntermediateTensorInfo(e){this.disposeData(e.dataId)}readSync(e){let t=this.texData.get(e),{values:n,dtype:a,complexTensorInfos:r,slice:s,shape:i,isPacked:o}=t;if(s!=null){let h;o?h=new wu(i,V0):h=new Qs(i,V0);let p=this.runWebGLProgram(h,[{dataId:e,shape:i,dtype:a}],a),c=this.readSync(p.dataId);return this.disposeIntermediateTensorInfo(p),c}if(n!=null)return this.convertAndCacheOnCPU(e);if(a==="string")return n;let l=this.activeTimers!=null,u;l&&(u=k.now());let d;if(a==="complex64"){let h=this.readSync(r.real.dataId),p=this.readSync(r.imag.dataId);d=M.mergeRealAndImagArrays(h,p)}else d=this.getValuesFromTexture(e);return l&&(this.downloadWaitMs+=k.now()-u),this.convertAndCacheOnCPU(e,d)}async read(e){if(this.pendingRead.has(e)){let c=this.pendingRead.get(e);return new Promise(m=>c.push(m))}let t=this.texData.get(e),{values:n,shape:a,slice:r,dtype:s,complexTensorInfos:i,isPacked:o}=t;if(r!=null){let c;o?c=new wu(a,V0):c=new Qs(a,V0);let m=this.runWebGLProgram(c,[{dataId:e,shape:a,dtype:s}],s),f=this.read(m.dataId);return this.disposeIntermediateTensorInfo(m),f}if(n!=null)return this.convertAndCacheOnCPU(e);if(!se().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&se().getNumber("WEBGL_VERSION")===2)throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");let l=null,u;if(s!=="complex64"&&se().get("WEBGL_BUFFER_SUPPORTED")){u=this.decode(e);let c=this.texData.get(u.dataId);l=this.gpgpu.createBufferFromTexture(c.texture,...ip(a))}this.pendingRead.set(e,[]),s!=="complex64"&&await this.gpgpu.createAndWaitForFence();let d;if(s==="complex64"){let c=await Promise.all([this.read(i.real.dataId),this.read(i.imag.dataId)]),m=c[0],f=c[1];d=M.mergeRealAndImagArrays(m,f)}else if(l==null)d=this.getValuesFromTexture(e);else{let c=k.sizeFromShape(a);d=this.gpgpu.downloadFloat32MatrixFromBuffer(l,c)}u!=null&&this.disposeIntermediateTensorInfo(u);let h=this.convertAndCacheOnCPU(e,d),p=this.pendingRead.get(e);return this.pendingRead.delete(e),p.forEach(c=>c(h)),this.pendingDisposal.has(e)&&(this.pendingDisposal.delete(e),this.disposeData(e)&&Ps().removeDataId(e,this),this.pendingDel
`;function Afe(e){let{inputs:t,backend:n,attrs:a}=e,{x:r}=t,{alpha:s}=a,i=n.makeTensorInfo([],"float32",k.createScalarValue(s,"float32")),o=se().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new pp(kE,r.shape,i.shape):new ku(wE,r.shape,i.shape),l=n.runWebGLProgram(o,[r,i],r.dtype);return n.disposeIntermediateTensorInfo(i),l}var xfe={kernelName:cl,backendName:"webgl",kernelFunc:Afe},IE="return (a < 0.) ? b * a : a;",SE=`
return(log(1.0+x)-log(1.0-x))/2.0;`,b0e=ot({opSnippet:x0e}),v0e={kernelName:Td,backendName:"webgl",kernelFunc:b0e},cp=class{constructor(e,t,n,a=!1,r=!1){if(this.variableNames=["x"],t==="avg"&&n)throw new Error("Cannot compute positions for average pool.");let s=e.filterWidth,i=e.strideHeight,o=e.strideWidth,l=e.dilationHeight,u=e.dilationWidth,d=e.effectiveFilterHeight,h=e.effectiveFilterWidth,p=e.padInfo.top,c=e.padInfo.left;this.outputShape=e.outShape;let m=t==="avg",f=`((batch*${e.inHeight}+xR)*${e.inWidth}+xC)*${e.inChannels}+d`,g=`(xR*${e.inWidth}+xC)*${e.inChannels}+d`,y="0.0";if(m||(y="-1.0 / 1e-20"),n){let I=">=";this.userCode=`
constivec2strides=ivec2(${i},${o});
constivec2pads=ivec2(${p},${c});
voidmain(){
ivec4coords=getOutputCoords();
intbatch=coords[0];
intd=coords[3];
ivec2xRCCorner=coords.yz*strides-pads;
intxRCorner=xRCCorner.x;
intxCCorner=xRCCorner.y;
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
floatminMaxValue=0.0;
floatminMaxValueFound=0.0;
intminMaxPosition=0;
floatavgValue=0.0;
for(intwR=0;wR<${d};
wR+=${l}){
intxR=xRCorner+wR;
if(xR<0||xR>=${e.inHeight}){
continue;
}
for(intwC=0;wC<${h};
wC+=${u}){
intxC=xCCorner+wC;
if(xC<0||xC>=${e.inWidth}){
continue;
}
floatvalue=getX(batch,xR,xC,d);
// If a min / max value has already been found, use it. If not,
`}},ub=class{constructor(e,t,n,a=!1,r=!1){if(this.variableNames=["x"],t==="avg"&&n)throw new Error("Cannot compute positions for average pool.");let s=e.filterWidth,i=e.strideDepth,o=e.strideHeight,l=e.strideWidth,u=e.dilationDepth,d=e.dilationHeight,h=e.dilationWidth,p=e.effectiveFilterDepth,c=e.effectiveFilterHeight,m=e.effectiveFilterWidth,f=e.padInfo.front,g=e.padInfo.top,y=e.padInfo.left;this.outputShape=e.outShape;let A=t==="avg",x="0.0";if(A||(x="-1.0 / 1e-20"),n){let C=">=";this.userCode=`
`}},_0e=({inputs:e,backend:t,attrs:n})=>{let{x:a,mean:r,variance:s,offset:i,scale:o}=e;k.assert(r.shape.length===s.shape.length,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),k.assert(i==null||r.shape.length===i.shape.length,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),k.assert(o==null||r.shape.length===o.shape.length,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");let{varianceEpsilon:l}=n;l==null&&(l=.001);let u=[a,r,s],d=null;i!=null&&(d=i.shape,u.push(i));let h=null;o!=null&&(h=o.shape,u.push(o));let p=se().getBool("WEBGL_PACK_NORMALIZATION")?new D0e(a.shape,r.shape,s.shape,d,h,l):new O0e(a.shape,r.shape,s.shape,d,h,l);return t.runWebGLProgram(p,u,u[0].dtype)},z0e={kernelName:dl,backendName:"webgl",kernelFunc:_0e},P0e=class{constructor(e){this.variableNames=["source"],this.outputShape=e,this.rank=e.length;let t=kt(this.rank),n=`uniformintstart[${this.rank}];`,a=L0e(this.rank),r,s=e.map((i,o)=>`sourceLoc.${db[o]}=start[${o}]+coords.${db[o]};`);r=`
`}};function UE({x:e,filter:t,convInfo:n,backend:a,bias:r=null,preluActivationWeights:s=null,leakyreluAlpha:i=0,activation:o=null}){let l=e.shape,u=a.texData.get(e.dataId),d=n.inChannels,h=l[0]*l[1]*l[2],p=n.outChannels,c=n.dataFormat==="channelsLast",m=!1,f=!1,g,y=[],A=(h===1||p===1)&&d>RE,x=l[2]%2!=0&&!!u.isPacked;if(A||!se().getBool("WEBGL_LAZILY_UNPACK")||!se().getBool("WEBGL_PACK_BINARY_OPERATIONS")||!x){let v=c?l[0]*l[1]*l[2]:l[0]*l[2]*l[3],b=be({inputs:{x:e},backend:a,attrs:{shape:[1,v,n.inChannels]}}),w=be({inputs:{x:t},backend:a,attrs:{shape:[1,n.inChannels,n.outChannels]}}),I=q0({a:b,b:w,transposeA:m,transposeB:f,backend:a,bias:r,activation:o,preluActivationWeights:s,leakyreluAlpha:i});g=be({inputs:{x:I},backend:a,attrs:{shape:n.outShape}}),y.push(b),y.push(w),y.push(I)}else{let v=c?l[0]*l[1]*(l[2]+1):l[0]*l[2]*(l[3]+1),b={dataId:e.dataId,shape:[1,v,n.inChannels],dtype:e.dtype},w=u.shape;u.shape=u.shape.slice(),u.shape[u.shape.length-2]++,k.assert(up(u.shape,b.shape),()=>`packedreshape${u.shape}to${b.shape}isn'tfree`);let I=be({inputs:{x:t},backend:a,attrs:{shape:[1,n.inChannels,n.outChannels]}});y.push(I);let T=q0({a:b,b:I,backend:a,transposeA:m,transposeB:f,bias:r,activation:o,preluActivationWeights:s,leakyreluAlpha:i}),C=a.texData.get(T.dataId);k.assert(C.isPacked,()=>"batchMatMul result is expected to be packed"),u.shape=w,C.shape=n.outShape,g=fa({inputs:{x:T},backend:a}),g.shape=n.outShape,y.push(T)}for(let v of y)a.disposeIntermediateTensorInfo(v);return g}function jE({x:e,filter:t,convInfo:n,backend:a,bias:r=null,preluActivationWeights:s=null,leakyreluAlpha:i=0,activation:o=null}){let{filterWidth:l,filterHeight:u,inChannels:d,outWidth:h,outHeight:p,dataFormat:c}=n,m=c==="channelsLast",f=l*u*d,g=p*h,y=[f,g],A=!0,x=!1,v=[],b=be({inputs:{x:e},backend:a,attrs:{shape:e.shape.slice(1)}}),w=be({inputs:{x:t},backend:a,attrs:{shape:[1,f,k.sizeFromShape(t.shape)/f]}});v.push(b),v.push(w);let I=new fme(y,b.shape,n),T=a.runWebGLProgram(I,[b],"float32"),C=be({inputs:{x:T},backend:a,attrs:{shape:[1,y[0],y[1]]}});v.push(T),v.push(C);let z=r!=null,$=s!=null,S=o==="leakyrelu",D=o?j0(o,!0):null,_=new TE(C.shape,w.shape,[1,g,n.outChannels],A,x,z,D,$,S),W=[C,w];if(r&&W.push(r),$&&W.push(s),S){let ee=a.makeTensorInfo([],"float32",k.createScalarValue(i,"float32"));W.push(ee),v.push(ee)}let X=a.runWebGLProgram(_,W,"float32"),q=m?[1,p,h,n.outChannels]:[1,n.outChannels,p,h],Q=be({inputs:{x:X},backend:a,attrs:{shape:q}});v.push(X);for(let ee of v)a.disposeIntermediateTensorInfo(ee);return Q}function mme(e){let{inputs:t,backend:n,attrs:a}=e,{x:r,filter:s}=t,{strides:i,pad:o,dataFormat:l,dilations:u,dimRoundingMode:d}=a,h=M.convertConv2DDataFormat(l),p=M.computeConv2DInfo(r.shape,s.shape,i,u,o,d,!1,h),c;if(p.filterHeight===1&&p.filterWidth===1&&p.dilationHeight===1&&p.dilationWidth===1&&p.strideHeight===1&&p.strideWidth===1&&(p.padInfo.type==="SAME"||p.padInfo.type==="VALID"))c=UE({x:r,filter:s,convInfo:p,backend:n});else if(se().getBool("WEBGL_CONV_IM2COL")&&r.shape[0]===1)c=jE({x:r,filter:s,convInfo:p,backend:n});else{let f=new VE(p);c=n.runWebGLProgram(f,[r,s],"float32")}let m=be({inputs:{x:c},backend:n,attrs:{shape:p.outShape}});return n.disposeIntermediateTensorInfo(c),m}var gme={kernelName:tl,backendName:"webgl",kernelFunc:mme},yme=class{constructor(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;let t=e.strideHeight,n=e.strideWidth,a=e.padInfo.top,r=e.padInfo.left,s=e.dataFormat==="channelsLast";this.userCode=`
`}},tAe=e=>{let{inputs:t,backend:n,attrs:a}=e,{indices:r}=t,{depth:s,onValue:i,offValue:o}=a,l=k.sizeFromShape(r.shape),u=new eAe(l,s,i,o),d=be({inputs:{x:r},backend:n,attrs:{shape:[l]}}),h=n.runWebGLProgram(u,[d],r.dtype);n.disposeIntermediateTensorInfo(d);let p=[...r.shape,s],c=be({inputs:{x:h},backend:n,attrs:{shape:p}});return n.disposeIntermediateTensorInfo(h),c},nAe={kernelName:wl,backendName:"webgl",kernelFunc:tAe};function Y0(e){let{inputs:t,backend:n}=e,{x:a}=t;if(a.dtype==="complex64"){let r=mp({inputs:{input:a},backend:n}),s=Y0({inputs:{x:r},backend:n}),i=Z0({inputs:{input:a},backend:n}),o=Y0({inputs:{x:i},backend:n}),l=ei({inputs:{real:s,imag:o},backend:n});return n.disposeIntermediateTensorInfo(r),n.disposeIntermediateTensorInfo(s),n.disposeIntermediateTensorInfo(i),n.disposeIntermediateTensorInfo(o),l}else return cb({attrs:{shape:a.shape,dtype:a.dtype,value:a.dtype==="string"?"":0},backend:n})}var aAe={kernelName:ph,backendName:"webgl",kernelFunc:Y0};function lC(e){let{inputs:t,backend:n}=e,{x:a}=t;if(a.dtype==="string")throw new Error("onesLike is not supported under string dtype");if(a.dtype==="complex64"){let r=mp({inputs:{input:a},backend:n}),s=lC({inputs:{x:r},backend:n}),i=Z0({inputs:{input:a},backend:n}),o=Y0({inputs:{x:i},backend:n}),l=ei({inputs:{real:s,imag:o},backend:n});return n.disposeIntermediateTensorInfo(r),n.disposeIntermediateTensorInfo(s),n.disposeIntermediateTensorInfo(i),n.disposeIntermediateTensorInfo(o),l}else return cb({attrs:{shape:a.shape,dtype:a.dtype,value:1},backend:n})}var rAe={kernelName:Xd,backendName:"webgl",kernelFunc:lC};function sAe(e){let{inputs:t,backend:n,attrs:a}=e,{axis:r}=a;if(t.length===1)return pb({inputs:{input:t[0]},backend:n,attrs:{dim:r}});let s=t[0].shape,i=t[0].dtype;t.forEach(d=>{k.assertShapesMatch(s,d.shape,"All tensors passed to stack must have matching shapes"),k.assert(i===d.dtype,()=>"All tensors passed to stack must have matching dtypes")});let o=[],l=t.map(d=>{let h=pb({inputs:{input:d},backend:n,attrs:{dim:r}});return o.push(h),h}),u=BE({inputs:l,backend:n,attrs:{axis:r}});return o.forEach(d=>n.disposeIntermediateTensorInfo(d)),u}var iAe={kernelName:Zd,backendName:"webgl",kernelFunc:sAe},oAe=class{constructor(e,t,n){this.variableNames=["x"],this.outputShape=t.map((l,u)=>l[0]+e[u]+l[1]);let a=e.length,r=kt(a),s=t.map(l=>l[0]).join(","),i=t.map((l,u)=>l[0]+e[u]).join(","),o=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,a);if(a===1){this.userCode=`
`}},UAe=class{constructor(e,t){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;let n=e.length;if(n>4)throw new Error(`WebGLbackend:Reverseofrank-${n}tensorisnotyetsupported`);this.outputShape=e;let a=Bn("rc",n),r=`${a[n-1]}+1<${this.outputShape[n-1]}`,s=`${a[n-2]}+1<${this.outputShape[n-2]}`,i=kt(n);n===1?this.userCode=`
`,v2e=ot({opSnippet:b2e}),w2e={kernelName:ih,backendName:"webgl",kernelFunc:v2e},k2e=e=>{let{inputs:t,backend:n,attrs:a}=e,{x:r}=t,{blockShape:s,paddings:i}=a;k.assert(r.shape.length<=4,()=>"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet");let o=s.reduce((y,A)=>y*A),l=[[0,0]];l.push(...i);for(let y=1+s.length;y<r.shape.length;++y)l.push([0,0]);let u=[],d=uC({inputs:{x:r},backend:n,attrs:{paddings:l,constantValue:0}}),h=M.getReshaped(d.shape,s,o,!1),p=M.getPermuted(h.length,s.length,!1),c=M.getReshapedPermuted(d.shape,s,o,!1),m=be({inputs:{x:d},backend:n,attrs:{shape:h}}),f=Vn({inputs:{x:m},backend:n,attrs:{perm:p}}),g=be({inputs:{x:f},backend:n,attrs:{shape:c}});return u.push(d),u.push(m),u.push(f),u.forEach(y=>n.disposeIntermediateTensorInfo(y)),g},I2e={kernelName:of,backendName:"webgl",kernelFunc:k2e};function S2e(e){let{inputs:t,backend:n}=e,{indices:a,values:r,denseShape:s,defaultValue:i}=t;if(s.shape.length!==1)throw new Error(`Denseshapemustbeavector,saw:
${s.shape}`);if(a.shape.length!==2)throw new Error(`Indicesmustbeamatrix,saw:
${a.shape}`);if(r.shape.length!==1)throw new Error(`Valuesmustbeavector,saw:
${r.shape}`);if(i.shape.length!==0)throw new Error(`Defaultvaluemustbeascalar,saw:
${i.shape}`);let o=n.readSync(a.dataId),l=n.readSync(r.dataId),u=n.readSync(s.dataId),d=n.readSync(i.dataId)[0],[h,p,c,m,f]=Ece(o,a.shape,a.dtype,l,r.dtype,u,d);return[n.makeTensorInfo(p,a.dtype,h),n.makeTensorInfo([p[0]],r.dtype,c),n.makeTensorInfo([m.length],"bool",new Uint8Array(m.map(g=>Number(g)))),n.makeTensorInfo([f.length],a.dtype,new Int32Array(f))]}var N2e={kernelName:K1,backendName:"webgl",kernelFunc:S2e};function T2e(e){let{inputs:t,backend:n}=e,{inputIndices:a,inputShape:r,newShape:s}=t;if(a.shape.length!==2)throw new Error(`Inputindicesshouldbeamatrixbutreceivedshape${a.shape}`);if(r.shape.length!==1)throw new Error(`Inputshapeshouldbeavectorbutreceivedshape${r.shape}`);if(s.shape.length!==1)throw new Error(`Targetshapeshouldbeavectorbutreceivedshape${s.shape}`);let i=Array.from(n.readSync(r.dataId)),o=n.readSync(a.dataId),l=Array.from(n.readSync(s.dataId)),[u,d,h]=Cce(o,a.shape,a.dtype,i,l);return[n.makeTensorInfo(d,a.dtype,u),n.makeTensorInfo([h.length],s.dtype,new Int32Array(h))]}var E2e={kernelName:X1,backendName:"webgl",kernelFunc:T2e};function C2e(e){let{inputs:t,backend:n}=e,{data:a,indices:r,segmentIds:s}=t;if(a.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(r.shape.length!==1)throw new Error(`Indicesshouldbeavectorbutreceivedshape
${r.shape}`);if(s.shape.length!==1)throw new Error(`Segmentidsshouldbeavectorbutreceivedshape
${s.shape}`);let i=n.readSync(a.dataId),o=n.readSync(r.dataId),l=n.readSync(s.dataId),[u,d]=pE(i,a.shape,a.dtype,o,l,!0);return n.makeTensorInfo(d,a.dtype,u)}var M2e={kernelName:Z1,backendName:"webgl",kernelFunc:C2e};function $2e(e){let{inputs:t,backend:n}=e,{data:a,indices:r,segmentIds:s}=t;if(a.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(r.shape.length!==1)throw new Error(`Indicesshouldbeavectorbutreceivedshape
${r.shape}`);if(s.shape.length!==1)throw new Error(`Segmentidsshouldbeavectorbutreceivedshape
${s.shape}`);let i=n.readSync(a.dataId),o=n.readSync(r.dataId),l=n.readSync(s.dataId),[u,d]=pE(i,a.shape,a.dtype,o,l);return n.makeTensorInfo(d,a.dtype,u)}var R2e={kernelName:Y1,backendName:"webgl",kernelFunc:$2e};function F2e(e){let{inputs:t,backend:n,attrs:a}=e,{sparseIndices:r,sparseValues:s,defaultValue:i}=t,{outputShape:o}=a,{sliceRank:l,numUpdates:u,strides:d,outputSize:h}=M.calculateShapes(s,r,o),p=!1,c=new hC(u,l,r.shape.length,s.shape.length,d,[h,1],p),m=n.runWebGLProgram(c,[s,r,i],s.dtype),f=be({inputs:{x:m},backend:n,attrs:{shape:o}});return n.disposeIntermediateTensorInfo(m),f}var O2e={kernelName:J1,backendName:"webgl",kernelFunc:F2e};function D2e(e){let{inputs:t,backend:n,attrs:a}=e,{x:r}=t,{numOrSizeSplits:s,axis:i}=a,o=k.parseAxisParam(i,r.shape)[0],l=M.prepareSplitSize(r,s,o),u=r.shape.length,d=new Array(u).fill(0),h=r.shape.slice();return l.map(p=>{let c=[...h];c[o]=p;let m=fp({inputs:{x:r},backend:n,attrs:{begin:d,size:c}});return d[o]+=p,m})}var _2e={kernelName:oh,backendName:"webgl",kernelFunc:D2e},z2e="return sqrt(x);",P2e=ot({opSnippet:z2e}),L2e={kernelName:Fl,backendName:"webgl",kernelFunc:P2e},W2e="return x * x;",B2e=ot({opSnippet:W2e}),V2e={kernelName:lf,backendName:"webgl",kernelFunc:B2e},pC="return (a - b) * (a - b);",U2e=Tn({opSnippet:pC,packedOpSnippet:pC}),j2e={kernelName:_i,backendName:"webgl",kernelFunc:U2e};function H2e({inputs:e,attrs:t,backend:n}){let{x:a}=e,r=gr+`
`}};function K2e(e){let{inputs:t,backend:n,attrs:a}=e,{x:r}=t,{begin:s,end:i,strides:o,beginMask:l,endMask:u,ellipsisMask:d,newAxisMask:h,shrinkAxisMask:p}=a,{nonStrided:c,$begin:m,$strides:f,size:g,newShape:y,outShape:A}=Cn.sliceInfo(r.shape,s,i,o,l,u,d,h,p),x=be({inputs:{x:r},backend:n,attrs:{shape:y}}),v;if(c){let w=fp({inputs:{x},backend:n,attrs:{begin:m,size:g}});v=be({inputs:{x:w},backend:n,attrs:{shape:A}}),n.disposeIntermediateTensorInfo(w)}else if(A.some(w=>w===0))v=n.makeTensorInfo(A,r.dtype,[]);else if(n.shouldExecuteOnCPU([x])){let w=n.texData.get(x.dataId).values,I=Pe(x.shape,x.dtype,w),T=Mce(A,I,f,m);v=n.makeTensorInfo(A,x.dtype,T.values)}else{let w=new q2e(m,f,A);v=n.runWebGLProgram(w,[x],x.dtype)}let b=be({inputs:{x:v},backend:n,attrs:{shape:A}});return n.disposeIntermediateTensorInfo(x),n.disposeIntermediateTensorInfo(v),b}var X2e={kernelName:lh,backendName:"webgl",kernelFunc:K2e};function Z2e(e){let{inputs:t,backend:n,attrs:a}=e,{separator:r,nGramWidths:s,leftPad:i,rightPad:o,padWidth:l,preserveShortSequences:u}=a,{data:d,dataSplits:h}=t,p=n.readSync(d.dataId),c=n.readSync(h.dataId),[m,f]=$ce(p,c,r,s,i,o,l,u);return[n.makeTensorInfo([m.length],"string",m),n.makeTensorInfo(h.shape,"int32",f)]}var Y2e={kernelName:Q1,backendName:"webgl",kernelFunc:Z2e};function J2e(e){let{inputs:t,backend:n,attrs:a}=e,{skipEmpty:r}=a,{input:s,delimiter:i}=t;if(s.dtype!=="string")throw new Error("Input must be of datatype string");if(s.shape.length!==1)throw new Error(`Inputmustbeavector,gotshape:${s.shape}`);if(i.shape.length!==0)throw new Error(`Delimitermustbeascalar,gotshape:${i.shape}`);let o=n.readSync(s.dataId),l=n.readSync(i.dataId)[0],[u,d,h]=Rce(o,l,r),p=d.length;return[n.makeTensorInfo([p,2],"int32",u),n.makeTensorInfo([p],"string",d),n.makeTensorInfo([2],"int32",new Int32Array(h))]}var Q2e={kernelName:eA,backendName:"webgl",kernelFunc:J2e};function exe(e){let{inputs:t,backend:n,attrs:a}=e,{numBuckets:r}=a,{input:s}=t;if(s.dtype!=="string")throw new Error("Input must be of datatype string");if(r<=0)throw new Error("Number of buckets must be at least 1");let i=n.readSync(s.dataId),o=Fce(i,r);return n.makeTensorInfo(s.shape,"int32",o)}var txe={kernelName:tA,backendName:"webgl",kernelFunc:exe},nxe="return tan(x);",axe=ot({opSnippet:nxe}),rxe={kernelName:_l,backendName:"webgl",kernelFunc:axe},sxe=`