varff=Object.defineProperty,tg=N=>ff(N,"__esModule",{value:!0}),Or=(N,i)=>()=>(i||(i={exports:{}},N(i.exports,i)),i.exports),Zh=(N,i)=>{tg(N);for(varweini)ff(N,we,{get:i[we],enumerable:!0})},rg=Or(()=>{}),ng=Or(()=>{}),Bp=Or(()=>{}),ml=Or(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});vari=function(t,e){returni=Object.setPrototypeOf||{__proto__:[]}instanceofArray&&function(n,a){n.__proto__=a}||function(n,a){for(varcina)a.hasOwnProperty(c)&&(n[c]=a[c])},i(t,e)};functionwe(t,e){i(t,e);functionn(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,newn)}functionM(t,e,n,a){returnnew(n||(n=Promise))(function(c,d){functiony(C){try{_(a.next(C))}catch(F){d(F)}}functionv(C){try{_(a.throw(C))}catch(F){d(F)}}function_(C){C.done?c(C.value):newn(function(F){F(C.value)}).then(y,v)}_((a=a.apply(t,e||[])).next())})}functionV(t,e){varn={label:0,sent:function(){if(d[0]&1)throwd[1];returnd[1]},trys:[],ops:[]},a,c,d,y;returny={next:v(0),throw:v(1),return:v(2)},typeofSymbol=="function"&&(y[Symbol.iterator]=function(){returnthis}),y;functionv(C){returnfunction(F){return_([C,F])}}function_(C){if(a)thrownewTypeError("Generator is already executing.");for(;n;)try{if(a=1,c&&(d=C[0]&2?c.return:C[0]?c.throw||((d=c.return)&&d.call(c),0):c.next)&&!(d=d.call(c,C[1])).done)returnd;(c=0,d)&&(C=[C[0]&2,d.value]);switch(C[0]){case0:case1:d=C;break;case4:returnn.label++,{value:C[1],done:!1};case5:n.label++,c=C[1],C=[0];continue;case7:C=n.ops.pop(),n.trys.pop();continue;default:if(!(d=n.trys,d=d.length>0&&d[d.length-1])&&(C[0]===6||C[0]===2)){n=0;continue}if(C[0]===3&&(!d||C[1]>d[0]&&C[1]<d[3])){n.label=C[1];break}if(C[0]===6&&n.label<d[1]){n.label=d[1],d=C;break}if(d&&n.label<d[2]){n.label=d[2],n.ops.push(C);break}d[2]&&n.ops.pop(),n.trys.pop();continue}C=e.call(t,n)}catch(F){C=[6,F],c=0}finally{a=d=0}if(C[0]&5)throwC[1];return{value:C[0]?C[1]:void0,done:!0}}}varoe=1e-7,de=1e-4,X=function(){functiont(e,n){this.backend=e,this.dataMover=n,this.data=newWeakMap,this.dataIdsCount=0}returnt.prototype.get=function(e){returnthis.data.has(e)||this.dataMover.moveData(this.backend,e),this.data.get(e)},t.prototype.set=function(e,n){this.dataIdsCount++,this.data.set(e,n)},t.prototype.has=function(e){returnthis.data.has(e)},t.prototype.delete=function(e){returnthis.dataIdsCount--,this.data.delete(e)},t.prototype.numDataIds=function(){returnthis.dataIdsCount},t}(),Te=function(){functiont(){}returnt.prototype.time=function(e){returnz("time")},t.prototype.read=function(e){returnz("read")},t.prototype.readSync=function(e){returnz("readSync")},t.prototype.numDataIds=function(){returnz("numDataIds")},t.prototype.disposeData=function(e){returnz("disposeData")},t.prototype.write=function(e,n,a){returnz("write")},t.prototype.move=function(e,n,a,c){returnz("move")},t.prototype.memory=function(){returnz("memory")},t.prototype.floatPrecision=function(){returnz("floatPrecision")},t.prototype.epsilon=function(){returnthis.floatPrecision()===32?oe:de},t.prototype.batchMatMul=function(e,n,a,c){returnz("batchMatMul")},t.prototype.fusedBatchMatMul=function(e){varn=e.a,a=e.b,c=e.transposeA,d=e.transposeB,y=e.bias,v=e.activation,_=e.preluActivationWeights;returnz("fusedBatchMatMul")},t.prototype.slice=function(e,n,a){returnz("slice")},t.prototype.stridedSlice=function(e,n,a,c){returnz("stridedSlice")},t.prototype.unstack=function(e,n){returnz("unstack")},t.prototype.reverse=function(e,n){returnz("reverse")},t.prototype.concat=function(e,n){returnz("concat")},t.prototype.neg=function(e){returnz("neg")},t.prototype.add=function(e,n){returnz("add")},t.prototype.addN=function(e){returnz("addN")},t.prototype.subtract=function(e,n){returnz("subtract")},t.prototype.multiply=function(e,n){returnz("multiply")},t.prototype.realDivide=function(e,n){returnz("realDivide")},t.prototype.floorDiv=function(e,n){returnz("floorDiv")},t.prototype.sum=function(e,n){returnz("sum")},t.prototype.prod=function(e,n){returnz("prod")},t.prototype.unsortedSegmentSum=function(e,n,a){returnz(
`;return He[He.length-1]=" "+He[He.length-1]+"]"+(d?"":ur),He}function Oe(t){for(var e=[],n=0;n<t.length;n+=2)e.push([t[n],t[n+1]]);return e}var De=function(){function t(e,n,a){var c=this;if(this.dtype=n,this.shape=e.slice(),this.size=It(e),a!=null){var d=a.length;W(d===this.size,function(){return"Length of values '"+d+"' does not match the size "+("inferred by the shape '"+c.size+"'.")})}if(n==="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=a||_r(n,this.size),this.strides=za(e)}return t.prototype.set=function(e){for(var n=this,a=[],c=1;c<arguments.length;c++)a[c-1]=arguments[c];a.length===0&&(a=[0]),W(a.length===this.rank,function(){return"The number of provided coordinates ("+a.length+") must "+("match the rank ("+n.rank+")")});var d=this.locToIndex(a);this.values[d]=e},t.prototype.get=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];e.length===0&&(e=[0]);for(var a=0,c=0,d=e;c<d.length;c++){var y=d[c];if(y<0||y>=this.shape[a]){var v="Requested out of range element at "+e+". "+(" Buffer shape="+this.shape);throw new Error(v)}a++}for(var _=e[e.length-1],C=0;C<e.length-1;++C)_+=this.strides[C]*e[C];return this.values[_]},t.prototype.locToIndex=function(e){if(this.rank===0)return 0;if(this.rank===1)return e[0];for(var n=e[e.length-1],a=0;a<e.length-1;++a)n+=this.strides[a]*e[a];return n},t.prototype.indexToLoc=function(e){if(this.rank===0)return[];if(this.rank===1)return[e];for(var n=new Array(this.shape.length),a=0;a<n.length-1;++a)n[a]=Math.floor(e/this.strides[a]),e-=n[a]*this.strides[a];return n[n.length-1]=e,n},Object.defineProperty(t.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),t.prototype.toTensor=function(){return Ve().makeTensor(this.values,this.shape,this.dtype)},t}(),Ve=null,Xe=null;function at(t){Ve=t}function it(t){Xe=t}var $=function(){function t(e,n,a,c){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=n||"float32",this.size=It(e),this.strides=za(e),this.dataId=a,this.id=c,this.rankType=this.rank<5?this.rank.toString():"higher"}return Object.defineProperty(t.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),t.prototype.buffer=function(){return M(this,void 0,void 0,function(){var e;return V(this,function(n){switch(n.label){case 0:return[4,this.data()];case 1:return e=n.sent(),[2,Xe.buffer(this.shape,this.dtype,e)]}})})},t.prototype.bufferSync=function(){return Xe.buffer(this.shape,this.dtype,this.dataSync())},t.prototype.array=function(){return M(this,void 0,void 0,function(){var e;return V(this,function(n){switch(n.label){case 0:return[4,this.data()];case 1:return e=n.sent(),[2,Gn(this.shape,e)]}})})},t.prototype.arraySync=function(){return Gn(this.shape,this.dataSync())},t.prototype.data=function(){return M(this,void 0,void 0,function(){var e,n;return V(this,function(a){switch(a.label){case 0:return this.throwIfDisposed(),e=Ve().read(this.dataId),this.dtype==="string"?[4,e]:[3,2];case 1:n=a.sent();try{return[2,n.map(function(c){return ns(c)})]}catch(c){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}a.label=2;case 2:return[2,e]}})})},t.prototype.dataSync=function(){this.throwIfDisposed();var e=Ve().readSync(this.dataId);if(this.dtype==="string")try{return e.map(function(n){return ns(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},t.prototype.bytes=function(){return M(this,void 0,void 0,function(){var e;return V(this,function(n){switch(n.label){case 0:return this.throwIfDisposed(),[4,Ve().read(this.dataId)];case 1:return e=n.sent(),this.dtype==="string"?[2,e]:[2,new Uint8Array(e.buffer)]}})})},t.prototype.dispose=function(){if(this.isDisposed)return;Ve().disposeTensor(this),this.isDisposedInternal=!0},Object.defineProperty(t.prototype,"isDisposed",{get:function(){return this.isDi
`)+"Manifest JSON has weights with names: "+(_.join(", ")+"."));return F=d.reduce(function(Me,He,ct){return He&&Me.push(ct),Me},[]),B=[],F.forEach(function(Me){n[Me].paths.forEach(function(He){var ct=a+(a.endsWith("/")?"":"/")+He;B.push(ct)})}),[4,t(B)];case 1:return U=Le.sent(),J={},me=0,F.forEach(function(Me){for(var He=n[Me].paths.length,ct=0,Nt=0;Nt<He;Nt++)ct+=U[me+Nt].byteLength;for(var Ct=new ArrayBuffer(ct),Bt=new Uint8Array(Ct),ur=0,nr=0;nr<He;nr++){var yr=new Uint8Array(U[me+nr]);Bt.set(yr,ur),ur+=yr.byteLength}var Gr=y[Me];Gr.forEach(function(en){var Zr=Ct.slice(en.groupOffset,en.groupOffset+en.sizeBytes),Qr=xa(Zr,[en.manifestEntry]);for(var Kr in Qr)J[Kr]=Qr[Kr]}),me+=He}),[2,J]}})})}}var Hs="application/octet-stream",fo="application/json",Mu=function(){function t(e,n){if(this.DEFAULT_METHOD="POST",n==null&&(n={}),this.weightPathPrefix=n.weightPathPrefix,this.onProgress=n.onProgress,this.weightUrlConverter=n.weightUrlConverter,n.fetchFunc!=null?(W(typeof n.fetchFunc=="function",function(){return"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"}),this.fetch=n.fetchFunc):this.fetch=Rr().platform.fetch,W(e!=null&&e.length>0,function(){return"URL path for http must not be null, undefined or empty."}),Array.isArray(e)&&W(e.length===2,function(){return"URL paths for http must have a length of 2, "+("(actual length is "+e.length+").")}),this.path=e,n.requestInit!=null&&n.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=n.requestInit||{}}return t.prototype.save=function(e){return M(this,void 0,void 0,function(){var n,a,c,d;return V(this,function(y){switch(y.label){case 0:if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");return n=Object.assign({method:this.DEFAULT_METHOD},this.requestInit),n.body=new FormData,a=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],c={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,userDefinedMetadata:e.userDefinedMetadata,weightsManifest:a},n.body.append("model.json",new Blob([JSON.stringify(c)],{type:fo}),"model.json"),e.weightData!=null&&n.body.append("model.weights.bin",new Blob([e.weightData],{type:Hs}),"model.weights.bin"),[4,this.fetch(this.path,n)];case 1:if(d=y.sent(),d.ok)return[2,{modelArtifactsInfo:dn(e),responses:[d]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+(d.status+"."))}})})},t.prototype.load=function(){return M(this,void 0,void 0,function(){var e,n,a,c,d,y,v,_,C,F,B,U,J,me,Le;return V(this,function(Me){switch(Me.label){case 0:return[4,this.fetch(this.path,this.requestInit)];case 1:if(e=Me.sent(),!e.ok)throw new Error("Request to "+this.path+" failed with status code "+(e.status+". Please verify this URL points to ")+"the model JSON of the model to load.");Me.label=2;case 2:return Me.trys.push([2,4,,5]),[4,e.json()];case 3:return n=Me.sent(),[3,5];case 4:throw a=Me.sent(),c="Failed to parse model JSON of response from "+this.path+".",this.path.endsWith(".pb")?c+=" 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.":c+=" Please make sure the server is serving valid JSON for this request.",new Error(c);case 5:if(d=n.modelTopology,y=n.weightsManifest,v=n.generatedBy,_=n.convertedBy,C=n.format,F=n.userDefinedMetadata,d==null&&y==null)throw new Error("The JSON from HTTP path "+this.path+" contains neither model topology or manifest for weights.");return y!=null?[4,this.loadWeights(y)]:[3,7];case 6:J=Me.sent(),B=J[0],U=J[1],Me.label=7;case 7:return me={modelTopology:d,weightSpecs:B,weightData:U,userDefinedMetadata:F,generatedBy:v,convertedBy:_,format:C},Le=n.mo
`)+("Expected: "+C+"."))}}function El(t,e){t().then(function(){return e.fail()},function(){return e()})}function Rl(t,e){var n=typeof e=="string"||typeof e=="number"||typeof e=="boolean"?[e]:e;return ta(t)||ta(t[0])||ta(e)||ta(e[0])?Gu(t,n,function(a,c){return a==c}):Gu(t,e,function(a,c){return js(a,c,0)})}function Al(t,e,n){if(n==null&&(n=vu()),!js(t,e,n))throw new Error("Numbers differ: actual === "+t+", expected === "+e)}function js(t,e,n){return!isFinite(t)&&!isFinite(e)?!0:!(isNaN(t)||isNaN(e)||Math.abs(t-e)>n)}function ju(t,e,n){for(var a=0;a<t.length;a++)if(t[a]<e||t[a]>n)throw new Error("Value out of range:"+t[a]+" low: "+e+", high: "+n)}function Fl(t,e){expect(new Float32Array(t)).toEqual(new Float32Array(e))}var Dl={__proto__:null,TEST_EPSILON_FLOAT16:Hu,expectArraysClose:Tl,testEpsilon:vu,expectPromiseToFail:El,expectArraysEqual:Rl,expectNumbersClose:Al,expectValuesInRange:ju,expectArrayBuffersEqual:Fl},qu="2.7.0";function Ol(){Rr().set("PROD",!0)}function Ml(){Rr().set("DEBUG",!0)}function Ku(){Rr().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")}function Ea(t){Rr().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(t+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}function zl(){Ie.disposeVariables()}function Ll(){return Ie}function Pl(){return Ie.memory()}function Zc(t){return Ie.profile(t)}function la(t,e){return Ie.tidy(t,e)}function Ua(t){var e=Ot(t);e.forEach(function(n){return n.dispose()})}function gu(t){return Ie.keep(t)}function Qc(t){return Ie.time(t)}function Bl(t){return Ie.setBackend(t)}function Wl(){return Ie.ready()}function Ul(){return Ie.backendName}function Vl(t){Ie.removeBackend(t)}function Hl(t){return Ie.findBackend(t)}function Gl(t){return Ie.findBackendFactory(t)}function jl(t,e,n){return n===void 0&&(n=1),Ie.registerBackend(t,e,n)}function ql(){return Ie.backend}function Kl(t,e){Rr().setPlatform(t,e)}function Xl(t,e){var n,a=ie(t,"a","add"),c=ie(e,"b","add");n=Tt(a,c),a=n[0],c=n[1];var d=function(v,_){var C=v.add(a,c);return _([a,c]),C},y={a,b:c};return Ie.runKernelFunc(d,y,null,ma)}var Cr=Re({add_:Xl});function Yl(t,e){var n,a=ie(t,"a","floorDiv"),c=ie(e,"b","floorDiv");n=Tt(a,c),a=n[0],c=n[1];var d=function(v,_){var C=v.floorDiv(a,c);return _([a,c]),C},y={a,b:c};return Ie.runKernelFunc(d,y,null,k)}var Xu=Re({floorDiv_:Yl});function Zl(t,e){var n,a=ie(t,"a","div"),c=ie(e,"b","div");if(n=Tt(a,c),a=n[0],c=n[1],a.dtype==="int32"&&c.dtype==="int32")return Xu(a,c);var d=function(_,C){var F=_.realDivide(a,c);return C([a,c]),F},y={a,b:c},v={};return Ie.runKernelFunc(d,y,null,Vr,v)}var Wr=Re({div_:Zl});function Jc(t,e){var n,a=ie(t,"a","mul"),c=ie(e,"b","mul");n=Tt(a,c),a=n[0],c=n[1];var d=function(v,_){var C=v.multiply(a,c);return _([a,c]),C},y={a,b:c};return Ie.runKernelFunc(d,y,null,qr)}var bt=Re({mul_:Jc});function Ql(t){var e=ie(t,"x","abs"),n={x:e};return Ie.runKernelFunc(function(a,c){return c([e]),e.dtype==="complex64"?a.complexAbs(e):a.abs(e)},n,null,jn)}var ci=Re({abs_:Ql});function Jl(t){var e=ie(t,"x","acos"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.acos(e);return c([e]),d},n,null,ni)}var $c=Re({acos_:Jl});function $l(t){var e=ie(t,"x","acosh"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.acosh(e);return c([e]),d},n,null,pi)}var el=Re({acosh_:$l});function eh(t){W(Array.isArray(t),function(){return"The argument passed to tf.addN() must be a list of tensors"}),W(t.length>=1,function(){return"Must pass at least one tensor to tf.addN(), but got "+(""+t.length)});var e=t.map(function(d,y){return ie(d,"tensors"+y,"addN")}),n=e[0];e.forEach(function(d){if(d.dtype!==n.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),e.forEach(function(d){if(!mt(d.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});var a=function(d,y){var v=d.addN(e);return y(e),v},c=e;return Ie.runKernelFunc(a,c,null,di)}var th=Re({addN_:eh});function Yu(t,e){for(var n=0;n<t.length;++n)if(t[t.length-n-1]!==e-1-n)return!1;return!0
withdtype`+y.dtype+". ")});var a=function(y,v){var _=jt(e,n[0].shape)[0],C=Ir(n.map(function(U){return U.shape}),_);if(It(C)===0)return An([],C);if(n=n.filter(function(U){return U.size>0}),n.length===1)return n[0];var F=n.map(function(U){return U.shape});hr(F,_);var B=y.concat(n,_);return v(n),B},c=n,d={axis:e};return Ie.runKernelFunc(a,c,null,Ue,d)}var kr=Re({concat_:zr});function Sr(t){var e=ie(t,"x","sigmoid"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.sigmoid(e);return c([d]),d},n,null,As)}var mn=Re({sigmoid_:Sr});function Xr(t,e,n){var a=ie(t,"x","slice");if(a.rank===0)throw new Error("Slicing scalar is not possible");var c=function(v,_){var C=Vu(a,e,n),F=C[0],B=C[1];return Bc(a,F,B),_([a]),v.slice(a,F,B)},d={x:a},y={begin:e,size:n};return Ie.runKernelFunc(c,d,null,To,y)}var er=Re({slice_:Xr});function Dn(t){var e=ie(t,"x","tanh"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.tanh(e);return c([d]),d},n,null,Os)}var Cn=Re({tanh_:Dn});function bn(t,e,n,a,c,d){var y=ie(t,"forgetBias","basicLSTMCell"),v=ie(e,"lstmKernel","basicLSTMCell"),_=ie(n,"lstmBias","basicLSTMCell"),C=ie(a,"data","basicLSTMCell"),F=ie(c,"c","basicLSTMCell"),B=ie(d,"h","basicLSTMCell"),U=kr([C,B],1),J=sn(U,v),me=Cr(J,_),Le=me.shape[0],Me=me.shape[1]/4,He=[Le,Me],ct=er(me,[0,0],He),Nt=er(me,[0,Me],He),Ct=er(me,[0,Me*2],He),Bt=er(me,[0,Me*3],He),ur=Cr(bt(mn(ct),Cn(Nt)),bt(F,mn(Cr(y,Ct)))),nr=bt(Cn(ur),mn(Bt));return[ur,nr]}var un=Re({basicLSTMCell_:bn});function On(t,e,n){var a=ie(t,"x","batchToSpaceND"),c=e.reduce(function(_,C){return _*C});W(a.rank>=1+e.length,function(){return"input rank is "+a.rank+" but should be > than blockShape.length "+e.length}),W(n.length===e.length,function(){return"crops.length is "+n.length+" but should be equal to blockShape.length "+e.length}),W(a.shape[0]%c===0,function(){return"input tensor batch is "+a.shape[0]+" but is not divisible by the product of "+("the elements of blockShape "+e.join(" * ")+" === "+c)});var d=function(_){return _.batchToSpaceND(a,e,n)},y={x:a},v={blockShape:e,crops:n};return Ie.runKernelFunc(d,y,null,Oi,v)}var Hr=Re({batchToSpaceND_:On});function ha(t){var e;return t.rank===0||t.rank===1?e=Ke(t,[1,1,1,t.size]):t.rank===2?e=Ke(t,[1,1,t.shape[0],t.shape[1]]):t.rank===3?e=Ke(t,[1,t.shape[0],t.shape[1],t.shape[2]]):e=t,e}function Ni(t,e,n,a,c,d){d==null&&(d=.001);var y=ie(t,"x","batchNorm"),v=ie(e,"mean","batchNorm"),_=ie(n,"variance","batchNorm"),C;c!=null&&(C=ie(c,"scale","batchNorm"));var F;a!=null&&(F=ie(a,"offset","batchNorm")),W(v.rank===_.rank,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),W(F==null||v.rank===F.rank,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),W(C==null||v.rank===C.rank,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."});var B=ha(y),U=function(Me,He){return He([B,v,_,C]),Me.batchNorm(B,Wi(v),Wi(_),Wi(F),Wi(C),d)},J={x:B,scale:C,offset:F,mean:v,variance:_},me={varianceEpsilon:d},Le=Ie.runKernelFunc(U,J,null,K,me);return Ke(Le,y.shape)}function Wi(t){return t==null?null:t.rank===0?Ke(t,[t.size]):t.rank===1?t:t.rank===2?Ke(t,[1,1,t.shape[0],t.shape[1]]):t.rank===3?Ke(t,[1,t.shape[0],t.shape[1],t.shape[2]]):t}var Kn=Re({batchNorm_:Ni});function eo(t,e,n,a,c,d){var y=ie(t,"x","batchNorm"),v=ie(e,"mean","batchNorm"),_=ie(n,"variance","batchNorm"),C;c!=null&&(C=ie(c,"scale","batchNorm"));var F;return a!=null&&(F=ie(a,"offset","batchNorm")),W(y.rank===2,function(){return"Error in batchNorm2D: x must be rank 2 but got rank "+(y.rank+".")}),W(v.rank===2||v.rank===1,function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but "+("got rank "+v.rank+".")}),W(_.rank===2||_.rank===1,function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 "+("but got rank "+_.rank+".")}),C!=null&&W(C.rank===2||C.rank===1,function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 "+("but got rank "+C.rank+".")}),F!=null&&W(F.rank===2||F.rank===1,function(){return"Error in batchNorm2D: off
`+a.shape}),W(y%(e*e)===0,function(){return"Dimension size must be evenly divisible by "+e*e+" but is "+y+" for depthToSpace with input shape "+a.shape});var v=function(F){return F.depthToSpace(a,e,n)},_={x:a},C={blockSize:e,dataFormat:n};return Ie.runKernelFunc(v,_,null,va,C)}var Yp=Re({depthToSpace_:Tf});function Ef(t,e,n,a,c,d,y){c===void 0&&(c="NHWC"),d===void 0&&(d=[1,1]);var v=ie(t,"x","depthwiseConv2d"),_=ie(e,"filter","depthwiseConv2d"),C=v,F=!1;v.rank===3&&(F=!0,C=Ke(v,[1,v.shape[0],v.shape[1],v.shape[2]])),W(C.rank===4,function(){return"Error in depthwiseConv2d: input must be rank 4, but got "+("rank "+C.rank+".")}),W(_.rank===4,function(){return"Error in depthwiseConv2d: filter must be rank 4, but got rank "+(_.rank+".")}),W(C.shape[3]===_.shape[2],function(){return"Error in depthwiseConv2d: number of input channels "+("("+C.shape[3]+") must match the inChannels dimension in ")+("filter "+_.shape[2]+".")}),y!=null&&W(yt(a),function(){return"Error in depthwiseConv2d: pad must be an integer when using, "+("dimRoundingMode "+y+" but got pad "+a+".")});var B=function(Le,Me){d==null&&(d=[1,1]),W(dt(n,d),function(){return"Error in depthwiseConv2d: Either strides or dilations must be "+("1. Got strides "+n+" and dilations '"+d+"'")});var He=T(C.shape,_.shape,n,d,a,y,!0),ct=Le.depthwiseConv2D(C,_,He);return Me([C,_]),ct},U={x:C,filter:_},J={strides:n,pad:a,dataFormat:c,dilations:d,dimRoundingMode:y},me=Ie.runKernelFunc(B,U,null,ia,J);return F?Ke(me,[me.shape[1],me.shape[2],me.shape[3]]):me}var lh=Re({depthwiseConv2d_:Ef});function Rf(t){var e=ie(t,"x","diag"),n=function(c){var d=Ke(e,[e.size]),y=c.diag(d),v=t.shape.concat(t.shape);return Ke(y,v)},a={x:e};return Ie.runKernelFunc(n,a,null,rn)}var Af=Re({diag_:Rf});function Ff(t,e,n,a,c,d){c===void 0&&(c=[1,1]),d===void 0&&(d="NHWC");var y=ie(t,"x","dilation2d"),v=ie(e,"filter","dilation2d");W(y.rank===3||y.rank===4,function(){return"Error in dilation2d: input must be rank 3 or 4, but got rank "+(y.rank+".")}),W(v.rank===3,function(){return"Error in dilation2d: filter must be rank 3, but got rank "+(v.rank+".")}),W(d==="NHWC",function(){return"Error in dilation2d: Only NHWC is currently supported, "+("but got dataFormat of "+d)});var _=y,C=!1;y.rank===3&&(_=Ke(y,[1,y.shape[0],y.shape[1],y.shape[2]]),C=!0);var F={x:_,filter:v},B={strides:n,pad:a,dilations:c},U=Ie.runKernel(hn,F,B);return C?Ke(U,[U.shape[1],U.shape[2],U.shape[3]]):U}var Zp=Re({dilation2d_:Ff});function Df(t,e){for(var n=t.length,a=[],c=0;c<n;c++){var d=n-1-c,y=t[d]||1,v=e[e.length-1-c]||1;v>1&&y===1&&a.unshift(d)}return a}function ti(t,e){for(var n=[],a=0;a<e.length;a++){var c=t[t.length-a-1],d=e.length-a-1,y=e[d];(c==null||c===1&&y>1)&&n.unshift(d)}return n}function pa(t,e){for(var n=[],a=Math.max(t.length,e.length),c=0;c<a;c++){var d=t[t.length-c-1];d==null&&(d=1);var y=e[e.length-c-1];if(y==null&&(y=1),d===1)n.unshift(y);else if(y===1)n.unshift(d);else if(d!==y){var v="Operands could not be broadcast together with shapes "+(t+" and "+e+".");throw Error(v)}else n.unshift(d)}return n}function Of(t,e){var n,a=ie(t,"a","equal"),c=ie(e,"b","equal");n=Tt(a,c),a=n[0],c=n[1],pa(a.shape,c.shape);var d=function(v){return v.equal(a,c)},y={a,b:c};return Ie.runKernelFunc(d,y,null,qn)}var hh=Re({equal_:Of});function Mf(t,e,n){var a=ie(e,"a","where"),c=ie(n,"b","where"),d=ie(t,"condition","where","bool"),y=pa(a.shape,c.shape),v=Qu(a,y),_=Qu(c,y);d.rank===1&&W(d.shape[0]===a.shape[0],function(){return"The first dimension of `a` must match the size of `condition`."}),d.rank!==1&&st(d.shape,_.shape,"Error in where: ");var C=function(B,U){var J=B.select(d,v,_);return U([d]),J},F={condition:d,t:v,e:_};return Ie.runKernelFunc(C,F,null,Da)}var ls=Re({where_:Mf});function zf(t){var e=ie(t,"x","zerosLike"),n={x:e};return Ie.runKernelFunc(function(a){return a.zerosLike(e)},n,null,zs)}var gn=Re({zerosLike_:zf});function Lf(t,e){var n,a=ie(t,"a","div"),c=ie(e,"b","div");n=Tt(a,c),a=n[0],c=n[1];var d=Wr(a,c),y=gn(d),v=hh(c,y);return ls(v,y,d)}var Qp=Re({divNoNan_:Lf});function Pf(t,e){var n=ie(t,"t1","dot"),a=ie(e,"t2","d
rank`+d.rank+"."}),W(yt(e),function(){return"Error in localResponseNormalization: depthRadius must be an "+("integer but got depthRadius "+e+".")});var y=d,v=!1;d.rank===3&&(v=!0,y=Ke(d,[1,d.shape[0],d.shape[1],d.shape[2]]));var _=function(U,J){var me=U.localResponseNormalization4D(y,e,n,a,c);return J([y,me]),me},C={x:y},F={depthRadius:e,bias:n,alpha:a,beta:c},B=Ie.runKernelFunc(_,C,null,Sn,F);return v?Ke(B,[B.shape[1],B.shape[2],B.shape[3]]):B}var sd=Re({localResponseNormalization_:c1});function l1(t){var e=ie(t,"x","log"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.log(e);return c([e]),d},n,null,xr)}var ec=Re({log_:l1});function h1(t){var e=ie(t,"x","log1p"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.log1p(e);return c([e]),d},n,null,kn)}var hp=Re({log1p_:h1});function p1(t){return W(ra(t),function(){return"The f passed in grad(f) must be a function"}),function(e,n){var a=ie(e,"x","tf.grad",null),c=n!=null?ie(n,"dy","tf.grad"):null;return Ie.tidy(function(){var d=Ie.gradients(function(){return t(a)},[a],c),y=d.value,v=d.grads;return c!=null&&st(y.shape,c.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),Dh(v),v[0]})}}function d1(t){return W(ra(t),function(){return"The f passed in grads(f) must be a function"}),function(e,n){W(Array.isArray(e),function(){return"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s"});var a=In(e,"args","tf.grads",null),c=n!=null?ie(n,"dy","tf.grads"):null;return Ie.tidy(function(){var d=Ie.gradients(function(){return t.apply(void 0,a)},a,c),y=d.value,v=d.grads;return c!=null&&st(y.shape,c.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Dh(v),v})}}function f1(t){return W(ra(t),function(){return"The f passed in valueAndGrad(f) must be a function"}),function(e,n){W(e instanceof $,function(){return"The x passed in valueAndGrad(f)(x) must be a tensor"}),W(n==null||n instanceof $,function(){return"The dy passed in valueAndGrad(f)(x, dy) must be a tensor"});var a=Ie.gradients(function(){return t(e)},[e],n),c=a.grads,d=a.value;return Dh(c),{grad:c[0],value:d}}}function m1(t){return W(ra(t),function(){return"The f passed in valueAndGrads(f) must be a function"}),function(e,n){W(Array.isArray(e)&&e.every(function(c){return c instanceof $}),function(){return"The args passed in valueAndGrads(f)(args) must be array of tensors"}),W(n==null||n instanceof $,function(){return"The dy passed in valueAndGrads(f)(args, dy) must be a tensor"});var a=Ie.gradients(function(){return t.apply(void 0,e)},e,n);return n!=null&&st(a.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Dh(a.grads),a}}function ud(t,e){W(ra(t),function(){return"The f passed in variableGrads(f) must be a function"}),W(e==null||Array.isArray(e)&&e.every(function(B){return B instanceof rt}),function(){return"The varList passed in variableGrads(f, varList) must be an array of variables"});var n=e!=null;if(!n){e=[];for(var a in Ie.registeredVariables)e.push(Ie.registeredVariables[a])}var c=n?e.filter(function(B){return!B.trainable}):null,d=e.length;e=e.filter(function(B){return B.trainable}),W(e.length>0,function(){return"variableGrads() expects at least one of the input variables to "+("be trainable, but none of the "+d+" variables is ")+"trainable."});var y=!0,v=Ie.gradients(t,e,null,y),_=v.value,C=v.grads;W(C.some(function(B){return B!=null}),function(){return"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()."}),W(_.rank===0,function(){return"The f passed in variableGrads(f) must return a scalar, but it "+("returned a rank-"+_.rank+" tensor")});var F={};return e.forEach(function(B,U){C[U]!=null&&(F[B.name]=C[U])}),c!=null&&c.forEach(function(B){return F[B.name]=null}),{value:_,grads:F}}function Ts(t){return Ie.customGrad(t)}function Dh(t){var e=t.filter(function(n){return n==nul
thefyoupassedenclosesalloperationsthatleadfromxtoy.`)}function y1(t){var e=ie(t,"x","neg"),n={x:e};return Ie.runKernelFunc(function(a){return a.neg(e)},n,null,Io)}var ri=Re({neg_:y1});function v1(t){var e=ie(t,"x","softplus"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.softplus(e);return c([e]),d},n,null,Zo)}var pp=Re({softplus_:v1});function g1(t){var e=ie(t,"x","logSigmoid"),n=Ts(function(a){var c=ri(pp(ri(a))),d=function(y){var v=bt(y,mn(ri(a)));return v};return{value:c,gradFunc:d}});return n(e)}var cd=Re({logSigmoid_:g1});function x1(t,e,n){e===void 0&&(e=null),n===void 0&&(n=!1);var a=ie(t,"x","max"),c=function(v,_){var C=jt(e,a.shape),F=C,B=$i(F,a.rank),U=a;B!=null&&(U=$n(a,B),F=p(F.length,U.rank));var J=v.max(U,F);B!=null&&U.dispose();var me=J;if(n){var Le=li(me.shape,jt(e,a.shape));me=Ke(me,Le),J.dispose()}return _([a,me]),me},d={x:a},y={reductionIndices:e,keepDims:n};return Ie.runKernelFunc(c,d,null,$r,y)}var tc=Re({max_:x1});function _1(t,e){var n,a=ie(t,"a","sub"),c=ie(e,"b","sub");n=Tt(a,c),a=n[0],c=n[1];var d=function(v,_){var C=v.subtract(a,c);return _([a,c]),C},y={a,b:c};return Ie.runKernelFunc(d,y,null,ds)}var Lr=Re({sub_:_1});function w1(t,e,n){e===void 0&&(e=null),n===void 0&&(n=!1);var a=ie(t,"x","sum");a.dtype==="bool"&&(a=dr(a,"int32"));var c=function(v,_){_([a]);var C=jt(e,a.shape),F=$i(C,a.rank),B=C,U=a;F!=null&&(U=$n(a,F),B=p(B.length,a.rank));var J=v.sum(U,B);if(n){var me=li(J.shape,C);J=Ke(J,me)}return J},d={x:a},y={axis:e,keepDims:n};return Ie.runKernelFunc(c,d,null,Qo,y)}var Yr=Re({sum_:w1});function b1(t,e){e===void 0&&(e=-1);var n=ie(t,"logits","logSoftmax");if(e===-1&&(e=n.rank-1),e!==n.rank-1)throw Error("Log Softmax along a non-last dimension is not yet supported. "+("Logits was rank "+n.rank+" and axis was "+e));var a=function(y,v){var _=!0,C=tc(t,e,!0),F=Lr(t,C),B=Lr(dr(F,"float32"),ec(Yr(hs(F),e,_)));return v([B]),B},c={logits:n},d={axis:e};return Ie.runKernelFunc(a,c,null,Na,d)}var ld=Re({logSoftmax_:b1});function k1(t,e,n){e===void 0&&(e=null),n===void 0&&(n=!1);var a=ie(t,"x","logSumExp"),c=jt(e,a.shape),d=tc(a,c,!0),y=Lr(a,d),v=hs(y),_=Yr(v,c),C=ec(_),F=Cr(Ke(d,C.shape),C);if(n){var B=li(F.shape,c);return Ke(F,B)}return F}var dp=Re({logSumExp_:k1});function S1(t,e){var n=ie(t,"a","logicalAnd","bool"),a=ie(e,"b","logicalAnd","bool");pa(n.shape,a.shape);var c={a:n,b:a};return Ie.runKernelFunc(function(d){return d.logicalAnd(n,a)},c,null,pn)}var rc=Re({logicalAnd_:S1});function I1(t){var e=ie(t,"x","logicalNot","bool"),n={x:e};return Ie.runKernelFunc(function(a){return a.logicalNot(e)},n,null,zn)}var Oh=Re({logicalNot_:I1});function N1(t,e){var n=ie(t,"a","logicalOr","bool"),a=ie(e,"b","logicalOr","bool");pa(n.shape,a.shape);var c={a:n,b:a};return Ie.runKernelFunc(function(d){return d.logicalOr(n,a)},c,null,Dr)}var fp=Re({logicalOr_:N1});function C1(t,e){var n=ie(t,"a","logicalXor","bool"),a=ie(e,"b","logicalXor","bool");return pa(n.shape,a.shape),rc(fp(t,e),Oh(rc(t,e)))}var hd=Re({logicalXor_:C1});function T1(t,e,n,a,c){var d=ie(t,"x","maxPool"),y=1,v=d,_=!1;d.rank===3&&(_=!0,v=Ke(d,[1,d.shape[0],d.shape[1],d.shape[2]])),W(v.rank===4,function(){return"Error in maxPool: input must be rank 4 but got rank "+v.rank+"."}),W(dt(n,y),function(){return"Error in maxPool: Either strides or dilations must be 1. "+("Got strides "+n+" and dilations '"+y+"'")}),c!=null&&W(yt(a),function(){return"Error in maxPool: pad must be an integer when using, "+("dimRoundingMode "+c+" but got pad "+a+".")});var C=function(J,me){var Le=h(v.shape,e,n,1,a,c),Me;return Le.filterWidth===1&&Le.filterHeight===1&&mt(Le.inShape,Le.outShape)?Me=v.clone():Me=J.maxPool(v,Le),me([v,Me]),Me},F={x:v},B={filterSize:e,strides:n,pad:a,dimRoundingMode:c},U=Ie.runKernelFunc(C,F,null,mi,B);return _?Ke(U,[U.shape[1],U.shape[2],U.shape[3]]):U}var mp=Re({maxPool_:T1});function E1(t,e,n,a,c,d,y){e===void 0&&(e=[1,1,1]),d===void 0&&(d="NDHWC"),y==null?y=[1,1,1]:Ea("dilations is deprecated, this field will be gone in v3.0.0.");var v=ie(t,"x","maxPool3d"),_=v,C=!1;v.rank===4&&(C=!0,_=Ke(v,[1,v.shape[0],v.shape
`+("1. The "+o+" is defined in Python, in which ")+`caseitneedstobeportedtoTensorFlow.jsoryourJavaScriptcode.
`+("2. The custom "+o+" is defined in JavaScript, ")+"but is not registered properly with tf.serialization.registerClass().");return Z}else{var le=s;if(le.className==null||le.config==null)throw new w(o+": Improper config format: "+(JSON.stringify(le)+`.
`)+"'className' and 'config' must set.");var Ne=le.className,Be=void 0,je=void 0;if(Ne in r?(b=r[Ne],Be=b[0],je=b[1]):Ne in $e?(T=$e.className,Be=T[0],je=T[1]):Ne in u&&(O=u[Ne],Be=O[0],je=O[1]),Be==null)throw new w("Unknown "+o+": "+Ne+`.Thismaybeduetooneofthefollowingreasons:
`+("1. The "+o+" is defined in Python, in which ")+`caseitneedstobeportedtoTensorFlow.jsoryourJavaScriptcode.
`+("2. The custom "+o+" is defined in JavaScript, ")+"but is not registered properly with tf.serialization.registerClass().");if(je!=null){for(var qe={},vt=0,pt=Object.keys($e);vt<pt.length;vt++){var ut=pt[vt];qe[ut]=$e[ut]}for(var dt=0,Ft=Object.keys(r);dt<Ft.length;dt++){var ut=Ft[dt];qe[ut]=r[ut]}var sr=le.config;sr.customObjects=qe;for(var Yt=V({},$e),$t=0,vr=Object.keys(r);$t<vr.length;$t++){var ut=vr[$t];$e[ut]=r[ut]}nt(le.config);var hr=je(Be,le.config,r,h);return $e=V({},Yt),hr}else{for(var Yt=V({},$e),Ir=0,zr=Object.keys(r);Ir<zr.length;Ir++){var ut=zr[Ir];$e[ut]=r[ut]}var hr=new Be(le.config);return $e=V({},Yt),hr}}}function Qt(s,u){return s<u?-1:s>u?1:0}function rr(s,u){return-1*Qt(s,u)}function jt(s){if(s==null)return s;for(var u=[],r=0,o=s;r<o.length;r++){var h=o[r];u.indexOf(h)===-1&&u.push(h)}return u}function jr(s){if(s==null)throw new w("Invalid value in obj: "+JSON.stringify(s));for(var u in s)if(s.hasOwnProperty(u))return!1;return!0}function Pr(s,u,r){if(r==null)return;if(s.indexOf(r)<0)throw new w(r+" is not a valid "+u+". Valid values are "+s+" or null/undefined.")}function _r(s,u,r,o){return r===void 0&&(r=0),o===void 0&&(o=Infinity),ht(r>=0),ht(o>=r),Array.isArray(s)&&s.length>=r&&s.length<=o&&s.every(function(h){return typeof h===u})}function ar(s,u){Array.isArray(s)?(i.util.assert(s.length>0,function(){return u+" is unexpectedly an empty array."}),s.forEach(function(r,o){return ar(r,"element "+(o+1)+" of "+u)})):i.util.assert(Number.isInteger(s)&&s>0,function(){return"Expected "+u+" to be a positive integer, but got "+(da(s)+".")})}function da(s){return s===null?"null":Array.isArray(s)?"["+s.map(function(u){return da(u)}).join(",")+"]":typeof s=="string"?'"'+s+'"':""+s}function Ha(s,u){var r=i.util.now(),o,h=function(){for(var b=[],T=0;T<arguments.length;T++)b[T]=arguments[T];var O=i.util.now();return O-r<u||(r=O,o=s.apply(void 0,b)),o};return h}function Tn(s){return s==="relu"?"relu":s==="linear"?"linear":s==="elu"?"elu":null}function ba(s,u){return i.tidy(function(){return i.sqrt(i.sum(i.mul(s,s),u,!0))})}var ka=function(s){M(u,s);function u(){return s!==null&&s.apply(this,arguments)||this}return u.prototype.getConfig=function(){return{}},u}(i.serialization.Serializable),ta=function(s){M(u,s);function u(r){var o=s.call(this)||this;return o.defaultMaxValue=2,o.defaultAxis=0,o.maxValue=r.maxValue!=null?r.maxValue:o.defaultMaxValue,o.axis=r.axis!=null?r.axis:o.defaultAxis,o}return u.prototype.apply=function(r){var o=this;return i.tidy(function(){var h=ba(r,o.axis),b=i.clipByValue(h,0,o.maxValue);return i.mul(r,i.div(b,i.add(z(),h)))})},u.prototype.getConfig=function(){return{maxValue:this.maxValue,axis:this.axis}},u.className="MaxNorm",u}(ka);i.serialization.registerClass(ta);var Ma=function(s){M(u,s);function u(r){var o=s.call(this)||this;return o.defaultAxis=0,o.axis=r.axis!=null?r.axis:o.defaultAxis,o}return u.prototype.apply=function(r){var o=this;return i.tidy(function(){return i.div(r,i.add(z(),ba(r,o.axis)))})},u.prototype.getConfig=function(){return{axis:this.axis}},u.className="UnitNorm",u}(ka);i.serialization.registerClass(Ma);var Ti=function(s){M(u,s);function u(){return s!==null&&s.apply(this,arguments)||this}return u.prototype.apply=function(r){return i.relu(r)},u.className="NonNeg",u}(ka);i.serialization.registerClass(Ti);var Bn=function(s){M(u,s);function u(r){var o=s.call(this)||this;return o.defaultMinValue=0,o.defaultMaxValue=1,o.defaultRate=1,o.defaultAxis=0,o.minValue=r.minValue!=null?r.minValue:o.defaultMinValue,o.maxValue=r.maxValue!=null?r.maxValue:o.defaultMaxValue,o.rate=r.rate!=null?r.rate:o.defaultRate,o.axis=r.axis!=null?r.axis:o.defaultAxis,o}return u.prototype.apply=function(r){var o=this;return i.tidy(function(){var h=ba(r,o.axis),b=i.add(i.mul(o.rate,i.clipByValue(h,o.minValue,o.maxValue)),i.mul(1-o.rate,h));return i.mul(r,i.div(b,i.add(z(),h)))})},u.prototype.getConfig=function(){return{minValue:this.minValue,maxValue:this.maxValue,rate:this.rate,axis:this.axis}},u.className="MinMaxNorm",u}(ka);i.serialization.registerClass(Bn);var ra={maxNorm:"MaxNorm",minMaxNor
becausethevaluedtypeis`+k.dtype+", but TensorArray dtype is "+this.dtype+".");if(this.size()===0&&(this.elementShape==null||this.elementShape.length===0)&&(this.elementShape=k.shape),ln(this.elementShape,k.shape,"TensorArray "+this.name+": Could not write to TensorArray index "+x+"."),K.read)throw new Error("TensorArray "+this.name+": Could not write to TensorArray index "+x+", because it has already been read.");if(K.written)throw new Error("TensorArray "+this.name+": Could not write to TensorArray index "+x+", because it has already been written.");K.tensor=k,i.keep(k),K.written=!0,this.tensors[x]=K},S.prototype.writeMany=function(x,k){var K=this;if(x.length!==k.length)throw new Error("TensorArray "+this.name+": could not write multiple tensors,"+("because the index size: "+x.length+" is not the same as tensors size: "+k.length+"."));x.forEach(function(Se,be){return K.write(Se,k[be])})},S.prototype.gather=function(x,k){if(!!k&&k!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but gather requested dtype "+k);if(x)x=x.slice(0,this.size());else{x=[];for(var K=0;K<this.size();K++)x.push(K)}if(x.length===0)return i.tensor([],[0].concat(this.elementShape));var Se=this.readMany(x);return ln(this.elementShape,Se[0].shape,"TensorArray shape mismatch: "),i.stack(Se,0)},S.prototype.concat=function(x){if(!!x&&x!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but concat requested dtype "+x);if(this.size()===0)return i.tensor([],[0].concat(this.elementShape));for(var k=[],K=0;K<this.size();K++)k.push(K);var Se=this.readMany(k);return ln(this.elementShape,Se[0].shape,"TensorArray shape mismatch: tensor array shape ("+this.elementShape+") vs first tensor shape ("+Se[0].shape+")"),i.concat(Se,0)},S.prototype.scatter=function(x,k){if(k.dtype!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but tensor has dtype "+k.dtype);if(x.length!==k.shape[0])throw new Error("Expected len(indices) == tensor.shape[0], but saw: "+x.length+" vs. "+k.shape[0]);var K=Math.max.apply(Math,de(x));if(!this.dynamicSize&&K>=this.maxSize)throw new Error("Max index must be < array size ("+K+" vs. "+this.maxSize+")");this.writeMany(x,i.unstack(k,0))},S.prototype.split=function(x,k){var K=this;if(k.dtype!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but tensor has dtype "+k.dtype);var Se=0,be=x.map(function(Lt){return Se+=Lt,Se});if(Se!==k.shape[0])throw new Error(`Expectedsumoflengthstobeequalto
tensor.shape[0],butsumoflengthsis
`+Se+", and tensor's shape is: "+k.shape);if(!this.dynamicSize&&x.length!==this.maxSize)throw new Error("TensorArray's size is not equal to the size of lengths ("+this.maxSize+" vs. "+x.length+"), and the TensorArray is not marked as dynamically resizeable");var Je=Se===0?0:k.size/Se,Pe=[];i.tidy(function(){k=i.reshape(k,[1,Se,Je]);for(var Lt=0;Lt<x.length;++Lt){var Wt=Lt===0?0:be[Lt-1],Gt=[0,Wt,0],Jt=[1,x[Lt],Je];Pe[Lt]=i.reshape(i.slice(k,Gt,Jt),K.elementShape)}return Pe});for(var gt=[],ft=0;ft<x.length;ft++)gt[ft]=ft;this.writeMany(gt,Pe)},S}(),Ai=function(){function S(x,k,K,Se){Se===void 0&&(Se=-1),this.tensors=x,this.elementShape=k,this.elementDtype=K,x!=null&&x.forEach(function(be){if(K!==be.dtype)throw new Error("Invalid data types; op elements "+K+", but list elements "+be.dtype);ln(k,be.shape,"TensorList shape mismatch: "),i.keep(be)}),this.idTensor=i.scalar(0),this.maxNumElements=Se,i.keep(this.idTensor)}return Object.defineProperty(S.prototype,"id",{get:function(){return this.idTensor.id},enumerable:!0,configurable:!0}),S.prototype.copy=function(){return new S(de(this.tensors),this.elementShape,this.elementDtype)},S.prototype.clearAndClose=function(x){this.tensors.forEach(function(k){(x==null||!x.has(k.id))&&k.dispose()}),this.tensors.length=0,this.idTensor.dispose()},S.prototype.size=function(){return this.tensors.length},S.prototype.stack=function(x,k,K){var Se=this;if(K===void 0&&(K=-1),k!==this.elementDtype)throw new Error("Invalid data types; op elements "+k+", but list elements "+this.elementDtype);if(K!==-1&&this.tensors.length!==K)throw new Error("Operation expected a list with "+K+" elements but got a list with "+this.tensors.length+" elements.");return ln(x,this.elementShape,"TensorList shape mismatch: "),i.tidy(function(){var be=Se.tensors.map(function(Je){return i.reshape(Je,x)});return i.stack(be,0)})},S.prototype.popBack=function(x,k){if(k!==this.elementDtype)throw new Error("Invalid data types; op elements "+k+", but list elements "+this.elementDtype);if(this.size()===0)throw new Error("Trying to pop from an empty list.");var K=this.tensors.pop();return ln(K.shape,x,"TensorList shape mismatch: "),i.reshape(K,x)},S.prototype.pushBack=function(x){if(x.dtype!==this.elementDtype)throw new Error("Invalid data types; op elements "+x.dtype+", but list elements "+this.elementDtype);if(ln(x.shape,this.elementShape,"TensorList shape mismatch: "),this.maxNumElements===this.size())throw new Error("Trying to push element into a full list.");i.keep(x),this.tensors.push(x)},S.prototype.resize=function(x){if(x<0)throw new Error("TensorListResize expects size to be non-negative. Got: "+x);if(this.maxNumElements!==-1&&x>this.maxNumElements)throw new Error("TensorListResize input size "+x+" is greater maxNumElement "+this.maxNumElements+".");this.tensors.length=x},S.prototype.getItem=function(x,k,K){if(K!==this.elementDtype)throw new Error("Invalid data types; op elements "+K+", but list elements "+this.elementDtype);if(x<0||x>this.tensors.length)throw new Error("Trying to access element "+x+" in a list with "+this.tensors.length+" elements.");if(this.tensors[x]==null)throw new Error("element at index "+x+" is null.");return ln(this.tensors[x].shape,k,"TensorList shape mismatch: "),this.tensors[x]},S.prototype.setItem=function(x,k){if(k.dtype!==this.elementDtype)throw new Error("Invalid data types; op elements "+k.dtype+", but list elements "+this.elementDtype);if(x<0||this.maxNumElements!==-1&&x>=this.maxNumElements)throw new Error("Trying to set element "+x+" in a list with max "+this.maxNumElements+" elements.");ln(this.elementShape,k.shape,"TensorList shape mismatch: "),i.keep(k),this.tensors[x]=k},S.prototype.gather=function(x,k,K){var Se=this;if(k!==this.elementDtype)throw new Error("Invalid data types; op elements "+k+", but list elements "+this.elementDtype);return ln(this.elementShape,K,"TensorList shape mismatch: "),x=x.slice(0,this.size()),x.length===0?i.tensor([],[0].concat(this.elementShape)):i.tidy(function(){var be=x.map(function(Je){return i.reshape(Se.tensors[Je],K)});return i.stack(be,0)
`).map(function(kt){return kt.endsWith("\r")&&(kt=kt.slice(0,-1)),kt}),[2,re]}})})},Y}(Yn),xn='"',Ia=Symbol("out"),Rr=Symbol("field"),Pa=Symbol("quote"),na=Symbol("quoteafterquote"),Ei=Symbol("quoteinquote"),Gi=function(pe){M(Y,pe);function Y(j,ne){var re=pe.call(this)||this;return re.input=j,re.hasHeader=!0,re.fullColumnNames=null,re.columnNamesValidated=!1,re.columnConfigs=null,re.configuredColumnsOnly=!1,re.delimiter=",",re.delimWhitespace=!1,re.base=new on(j),ne||(ne={}),re.hasHeader=!(ne.hasHeader===!1),re.fullColumnNames=ne.columnNames,re.columnConfigs=ne.columnConfigs,re.configuredColumnsOnly=ne.configuredColumnsOnly,ne.delimWhitespace?(i.util.assert(ne.delimiter==null,function(){return"Delimiter should not be provided when delimWhitespace is true."}),re.delimWhitespace=!0,re.delimiter=" "):re.delimiter=ne.delimiter?ne.delimiter:",",re}return Y.prototype.columnNames=function(){return V(this,void 0,void 0,function(){return oe(this,function(j){switch(j.label){case 0:return this.columnNamesValidated?[3,2]:[4,this.setColumnNames()];case 1:j.sent(),j.label=2;case 2:return[2,this.configuredColumnsOnly?Object.keys(this.columnConfigs):this.fullColumnNames]}})})},Y.prototype.setColumnNames=function(){return V(this,void 0,void 0,function(){var j,ne,re,Ue,kt,tt,ze,Ye=this;return oe(this,function(Dt){switch(Dt.label){case 0:return[4,this.maybeReadHeaderLine()];case 1:if(j=Dt.sent(),!this.fullColumnNames&&!j)throw new Error("Column names must be provided if there is no header line.");if(this.fullColumnNames&&j&&i.util.assert(j.length===this.fullColumnNames.length,function(){return"The length of provided columnNames ("+Ye.fullColumnNames.length.toString()+") does not match the length of the header line read from file ("+j.length.toString()+")."}),this.fullColumnNames||(this.fullColumnNames=j),ne=this.fullColumnNames.reduce(function(St,Mt){return St[Mt]=St[Mt]+1||1,St},{}),re=Object.keys(ne).filter(function(St){return ne[St]>1}),i.util.assert(re.length===0,function(){return"Duplicate column names found: "+re.toString()}),this.columnConfigs){for(Ue=0,kt=Object.keys(this.columnConfigs);Ue<kt.length;Ue++)if(tt=kt[Ue],ze=this.fullColumnNames.indexOf(tt),ze===-1)throw new Error('The key "'+tt+'" provided in columnConfigs does not match any of the column names ('+this.fullColumnNames.toString()+").")}return this.columnNamesValidated=!0,[2]}})})},Y.prototype.maybeReadHeaderLine=function(){return V(this,void 0,void 0,function(){var j,ne,re,Ue;return oe(this,function(kt){switch(kt.label){case 0:return this.hasHeader?[4,this.base.iterator()]:[3,3];case 1:return j=kt.sent(),[4,j.next()];case 2:if(ne=kt.sent(),ne.done)throw new Error("No data was found for CSV parsing.");return re=ne.value,Ue=this.parseRow(re,!1),[2,Ue];case 3:return[2,null]}})})},Y.prototype.iterator=function(){return V(this,void 0,void 0,function(){var j,ne=this;return oe(this,function(re){switch(re.label){case 0:return this.columnNamesValidated?[3,2]:[4,this.setColumnNames()];case 1:re.sent(),re.label=2;case 2:return[4,this.base.iterator()];case 3:return j=re.sent(),this.hasHeader&&(j=j.skip(1)),[2,j.map(function(Ue){return ne.makeDataElement(Ue)})]}})})},Y.prototype.makeDataElement=function(j){for(var ne=this.parseRow(j),re={},Ue={},kt=0;kt<this.fullColumnNames.length;kt++){var tt=this.fullColumnNames[kt],ze=this.columnConfigs?this.columnConfigs[tt]:null;if(this.configuredColumnsOnly&&!ze)continue;var Ye=ne[kt],Dt=null;if(Ye==="")if(ze&&ze.default!==void 0)Dt=ze.default;else{if(ze&&(ze.required||ze.isLabel))throw new Error("Required column "+tt+" is empty in this line: "+j);Dt=void 0}else{var St=Number(Ye);if(isNaN(St))ze&&ze.dtype==="bool"?Dt=this.getBoolean(Ye):Dt=Ye;else if(!ze||!ze.dtype)Dt=St;else switch(ze.dtype){case"float32":Dt=St;break;case"int32":Dt=Math.floor(St);break;case"bool":Dt=this.getBoolean(Ye);break;default:Dt=St}}ze&&ze.isLabel?Ue[tt]=Dt:re[tt]=Dt}return Object.keys(Ue).length===0?re:{xs:re,ys:Ue}},Y.prototype.getBoolean=function(j){return j==="1"||j.toLowerCase()==="true"?1:0},Y.prototype.parseRow=function(j,ne){ne===void 0&&(ne=!0);for(var re=[],
============================
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.
============================`));var H={};return this.data.set(H,{values:E,dtype:A,refCount:1}),H},ue.prototype.makeTensorInfo=function(E,D,A){var H;if(D==="string"&&A!=null&&A.length>0&&i.util.isString(A[0])){var se=A.map(function(te){return i.util.encodeString(te)});H=this.write(se,E,D)}else H=this.write(A,E,D);return{dataId:H,shape:E,dtype:D}},ue.prototype.incRef=function(E){var D=this.data.get(E);D.refCount++},ue.prototype.decRef=function(E){if(this.data.has(E)){var D=this.data.get(E);D.refCount--}},ue.prototype.move=function(E,D,A,H){this.data.set(E,{values:D,dtype:H,refCount:1})},ue.prototype.numDataIds=function(){return this.data.numDataIds()},ue.prototype.read=function(E){return oe(this,void 0,void 0,function(){return de(this,function(D){return[2,this.readSync(E)]})})},ue.prototype.readSync=function(E){var D=this.data.get(E),A=D.dtype,H=D.complexTensorInfos;if(A==="complex64"){var se=this.readSync(H.real.dataId),te=this.readSync(H.imag.dataId);return i.backend_util.mergeRealAndImagArrays(se,te)}return this.data.get(E).values},ue.prototype.bufferSync=function(E){var D=this.readSync(E.dataId),A=D;if(E.dtype==="string")try{A=D.map(function(H){return i.util.decodeString(H)})}catch(H){throw new Error("Failed to decode encoded string bytes into utf-8")}return i.buffer(E.shape,E.dtype,A)},ue.prototype.makeOutput=function(E,D,A){var H=this.write(E,D,A);return i.engine().makeTensorFromDataId(H,D,A,this)},ue.prototype.disposeData=function(E){if(this.data.has(E)){var D=this.data.get(E).complexTensorInfos;D!=null&&(this.disposeData(D.real.dataId),this.disposeData(D.imag.dataId)),this.data.delete(E)}},ue.prototype.disposeIntermediateTensorInfo=function(E){var D=E.dataId;if(this.data.has(D)){var A=this.data.get(D);A.refCount--,A.refCount<1&&this.disposeData(D)}},ue.prototype.time=function(E){return oe(this,void 0,void 0,function(){var D,A;return de(this,function(H){return D=i.util.now(),E(),A=i.util.now()-D,[2,{kernelMs:A}]})})},ue.prototype.memory=function(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}},ue.prototype.stridedSlice=function(E,D,A,H){X(E,"stridedSlice");var se=i.slice_util.computeOutShape(D,A,H);if(se.some(function(Ae){return Ae===0}))return i.tensor([],se);for(var te=i.buffer(se,E.dtype),_e=this.bufferSync(E),ce=0;ce<te.size;ce++){for(var fe=te.indexToLoc(ce),ve=new Array(fe.length),ge=0;ge<ve.length;ge++)ve[ge]=fe[ge]*H[ge]+D[ge];te.set.apply(te,[_e.get.apply(_e,ve)].concat(fe))}return te.toTensor()},ue.prototype.diag=function(E){for(var D=this.readSync(E.dataId),A=i.buffer([E.size,E.size],E.dtype),H=A.values,se=0;se<D.length;se++)H[se*E.size+se]=D[se];return A.toTensor()},ue.prototype.unstack=function(E,D){for(var A=E.shape[D],H=new Array(E.rank-1),se=0,te=0;te<E.rank;te++)te!==D&&(H[se++]=E.shape[te]);var _e=new Array(E.rank).fill(0),ce=E.shape.slice();ce[D]=1;for(var fe=new Array(A),te=0;te<fe.length;te++)_e[D]=te,fe[te]=i.slice(E,_e,ce).reshape(H);return fe},ue.prototype.reverse=function(E,D){X(E,"reverse");for(var A=i.buffer(E.shape,E.dtype),H=this.bufferSync(E),se=function(_e){var ce=A.indexToLoc(_e),fe=ce.slice();D.forEach(function(ve){return fe[ve]=E.shape[ve]-1-fe[ve]}),A.set.apply(A,[H.get.apply(H,fe)].concat(ce))},te=0;te<A.size;te++)se(te);return A.toTensor()},ue.prototype.neg=function(E){return X(E,"neg"),i.mul(i.scalar(-1),E)},ue.prototype.addN=function(E){var D=this;X(E,"addN");for(var A=E.map(function(fe){return D.readSync(fe.dataId)}),H=i.buffer(E[0].shape,E[0].dtype),se=H.values,te=0;te<E.length;te++)for(var _e=A[te],ce=0;ce<se.length;ce++)se[ce]+=_e[ce];return H.toTensor()},ue.prototype.softmax=function(E,D){var A=i.util.parseAxisParam([D],E.shape),H=i.max(E,A),se=i.backend_util.expandShapeToKeepDim(H.shape,A),te=i.sub(E,H.reshape(se)),_e=i.exp(te),ce=this.sum(_e,A).reshape(se);return i.div(_e,ce)},ue.prototype.pow=function(E,D){return X([E,D],"pow"),this.broadcastedBinaryOp(E,D,E.dtype,function(A,H){return Math.pow(A,H)})},ue.prototype.floorDiv=function(E,D){X([E,D],"floorDiv");var A=funct
returnmod(a,b);`,so="return (b >= 1.0) ? a : a * (b + 1.0);",Ta="return (a < 0.) ? b * a : a;",vn=function(){function f(p,l,m){this.variableNames=["A","B"],this.outputShape=i.backend_util.assertAndGetBroadcastShape(l,m),this.userCode=`
`}return f.prototype.getCustomSetupFunc=function(p){var l=this;return function(m,g){l.index==null&&(l.index=m.getUniformLocation(g,"index")),m.gl.uniform1f(l.index,p)}},f}();function xo(f,p){if(f===1)return""+p;if(f===2)return p+".x, "+p+".y";if(f===3)return p+".x, "+p+".y, "+p+".z";if(f===4)return p+".x, "+p+".y, "+p+".z, "+p+".w";throw Error("Cumulative sum for rank "+f+" is not yet supported")}function vs(f,p){if(f===1)return""+p;if(f===2)return p+".y";if(f===3)return p+".z";if(f===4)return p+".w";throw Error("Cumulative sum for rank "+f+" is not yet supported")}var Do=function(){function f(p){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=ee.DENSE;var l=st(p),m=tn();this.outputShape=p,this.userCode=`
`}return f}(),mr=function(){function f(p,l){this.variableNames=["x"];var m=p.length;if(m>4)throw new Error("WebGL backend: Reverse of rank-"+m+" tensor is not yet supported");if(this.outputShape=p,m===1){this.userCode=`
`}return f}(),ie=function(){function f(p,l,m){this.variableNames=["c","a","b"],this.outputShape=l;var g,I;if(m>4)throw Error("Where for rank "+m+" is not yet supported");if(m===1)I="resRC",g="resRC";else{for(var R=["resRC.x","resRC.y","resRC.z","resRC.w"],P=[],L=[],G=0;G<l.length;G++)L.push(""+R[G]),G<p&&P.push(""+R[G]);g=P.join(),I=L.join()}var Q=nn(m);this.userCode=`
`}return f}(),In=function(){function f(p){this.variableNames=["source"],this.outputShape=p,this.rank=p.length;var l=nn(this.rank),m="uniform int start["+this.rank+"];",g=Re(this.rank),I,R=p.map(function(P,L){return"sourceLoc."+wn[L]+" = start["+L+"] + coords."+wn[L]+";"});I=`
`+l+`sourceLoc;
`+l+`coords=getOutputCoords();
`+R.join(`
`)+`
`,this.userCode=`
`+m+`
voidmain(){
`+I+`
setOutput(getSource(`+g+`));
}
`}return f.prototype.getCustomSetupFunc=function(p){var l=this;if(p.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the "+("length of start ("+p.length+")"));return function(m,g){if(l.startLoc==null&&(l.startLoc=m.getUniformLocationNoThrow(g,"start"),l.startLoc==null))return;m.gl.uniform1iv(l.startLoc,p)}},f}(),wn=["x","y","z","w","u","v"];function Re(f){if(f===1)return"sourceLoc";if(f<=6)return wn.slice(0,f).map(function(p){return"sourceLoc."+p}).join(",");throw Error("Slicing for rank "+f+" is not yet supported")}var Un=function(){function f(p){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=p,this.rank=p.length;var l=nn(this.rank),m=Vr("coords",this.rank),g=Vr("sourceLoc",this.rank),I=this.rank===1?"sourceLoc":"vec2("+g.slice(-2).join()+")",R="getChannel(getSource("+g.join()+"), "+I+")",P=`
`}return f.prototype.getCustomSetupFunc=function(p){var l=this;if(p.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the "+("length of start ("+p.length+")"));return function(m,g){if(l.startLoc==null&&(l.startLoc=m.getUniformLocationNoThrow(g,"start"),l.startLoc==null))return;m.gl.uniform1iv(l.startLoc,p)}},f}(),Ln=function(){function f(p,l,m){this.variableNames=["x"],this.outputShape=m;var g=m.length,I=nn(m.length),R=nn(m.length),P="";if(g===1)P="coords * strides + begin";else{var L=0;P=m.map(function(G,Q){return L++,m.length===1?"coords * strides["+Q+"] + begin["+Q+"]":"coords["+(L-1)+"] * strides["+Q+"] + begin["+Q+"]"}).join(",")}this.userCode=`
`+I+" begin = "+I+"("+p+`);
`+I+" strides = "+I+"("+l+`);
voidmain(){
`+R+`coords=getOutputCoords();
setOutput(getX(`+P+`));
}
`}return f}(),Oa=function(){function f(p){this.gpgpu=p,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}return f.prototype.acquireTexture=function(p,l,m){var g=xa(l,m),I=_a(p,g,m);I in this.freeTextures||(this.freeTextures[I]=[]),I in this.usedTextures||(this.usedTextures[I]=[]);var R=Ja(p,g,this.gpgpu.gl,this.gpgpu.textureConfig,m);if(this.freeTextures[I].length>0){this.numFreeTextures--,this.numUsedTextures++,this._numBytesFree-=R,this.log();var P=this.freeTextures[I].shift();return this.usedTextures[I].push(P),P}var L;return g===xe.PACKED_2X2_FLOAT32?L=this.gpgpu.createPackedMatrixTexture(p[0],p[1]):g===xe.PACKED_2X2_FLOAT16?L=this.gpgpu.createFloat16PackedMatrixTexture(p[0],p[1]):g===xe.UNPACKED_FLOAT32?L=this.gpgpu.createFloat32MatrixTexture(p[0],p[1]):g===xe.UNPACKED_FLOAT16?L=this.gpgpu.createFloat16MatrixTexture(p[0],p[1]):g===xe.PACKED_4X1_UNSIGNED_BYTE&&(L=this.gpgpu.createUnsignedBytesMatrixTexture(p[0],p[1])),this.usedTextures[I].push(L),this.numUsedTextures++,this._numBytesAllocated+=R,this.log(),L},f.prototype.releaseTexture=function(p,l,m,g){if(this.freeTextures==null)return;var I=xa(m,g),R=_a(l,I,g);R in this.freeTextures||(this.freeTextures[R]=[]);var P=Ja(l,I,this.gpgpu.gl,this.gpgpu.textureConfig,g),L=i.env().get("WEBGL_DELETE_TEXTURE_THRESHOLD");L!==-1&&this._numBytesAllocated>L?(this.gpgpu.deleteMatrixTexture(p),this._numBytesAllocated-=P):(this.freeTextures[R].push(p),this.numFreeTextures++,this._numBytesFree+=P),this.numUsedTextures--;var G=this.usedTextures[R],Q=G.indexOf(p);if(Q<0)throw new Error("Cannot release a texture that was never provided by this texture manager");G.splice(Q,1),this.log()},f.prototype.log=function(){if(!this.logEnabled)return;var p=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+p+")");var l=this._numBytesFree/this._numBytesAllocated;console.log("Bytes allocated: "+this._numBytesAllocated),console.log("Bytes unused: "+this._numBytesFree+" ("+Math.round(100*l)+"%)")},Object.defineProperty(f.prototype,"numBytesAllocated",{get:function(){return this._numBytesAllocated},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"numBytesFree",{get:function(){return this._numBytesFree},enumerable:!0,configurable:!0}),f.prototype.getNumUsedTextures=function(){return this.numUsedTextures},f.prototype.getNumFreeTextures=function(){return this.numFreeTextures},f.prototype.dispose=function(){var p=this;if(this.freeTextures==null)return;for(var l in this.freeTextures)this.freeTextures[l].forEach(function(m){p.gpgpu.deleteMatrixTexture(m)});for(var l in this.usedTextures)this.usedTextures[l].forEach(function(g){p.gpgpu.deleteMatrixTexture(g)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0},f}();function An(f,p){var l=f;if(p===l.R32F)return 4;if(p===l.R16F)return 2;if(p===l.RGBA32F)return 16;if(p===f.RGBA)return 16;if(p===l.RGBA16F)return 8;throw new Error("Unknown internal format "+p)}function Ja(f,p,l,m,g){var I=Wa(p,m),R;if(g){var P=ht(f[0],f[1]),L=P[0],G=P[1];R=L*G}else{var Q=We(f[0],f[1]),ke=Q[0],Ce=Q[1];R=ke*Ce}var Fe=An(l,I);return R*Fe}function Wa(f,p){switch(f){case xe.PACKED_2X2_FLOAT32:return ue(p);case xe.PACKED_2X2_FLOAT16:return D(p);case xe.UNPACKED_FLOAT32:return ki(p);case xe.UNPACKED_FLOAT16:return Lo(p);case xe.PACKED_4X1_UNSIGNED_BYTE:return ns(p);default:throw new Error("Unknown physical texture type "+f)}}function $a(f){return i.env().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?f?xe.PACKED_2X2_FLOAT32:xe.UNPACKED_FLOAT32:f?xe.PACKED_2X2_FLOAT16:xe.UNPACKED_FLOAT16}function xa(f,p){if(f===w.UPLOAD)return xe.PACKED_2X2_FLOAT32;if(f===w.RENDER||f==null)return $a(p);if(f===w.DOWNLOAD||f===w.PIXELS)return xe.PACKED_4X1_UNSIGNED_BYTE;throw new Error("Unknown logical texture type "+f)}function _a(f,p,l){return f[0]+"_"+f[1]+"_"+p+"_"+l}var Zi=function(){function f(p,l){this.variableNames=["A"];for(va
voidmain(){
`+I+`resRC=getOutputCoords();
setOutput(getA(`+R+`));
}
`}return f}();function Bi(f){var p=f.length;if(p>5)throw Error("Tile for rank "+p+" is not yet supported");if(p===1)return"imod(resRC, "+f[0]+")";for(var l=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],m=[],g=0;g<f.length;g++)m.push("imod("+l[g]+", "+f[g]+")");return m.join()}var Mr=function(){function f(p,l){this.variableNames=["A"],this.outputShape=p,this.userCode=`
`}return f}(),gl=i.backend_util.segment_util,xl=i.kernel_impls.split,Ru=i.kernel_impls.tile,gc=i.kernel_impls.topkImpl,Ws=i.kernel_impls.whereImpl,xc=1e-7,Qi=1e-4,lu={};function dr(f){return f in lu||(lu[f]={}),lu[f]}function Us(f,p){if(p===void 0&&(p=!1),f==="linear")return p?vc:as;if(f==="relu")return p?lo:dn;if(f==="elu")return p?cu:Fn;if(f==="relu6")return p?Uo:Bo;if(f==="prelu")return p?Da:Ta;throw new Error("Activation "+f+" has not been implemented for the WebGL backend.")}var Ho=128,Au=600;function _c(){return i.env().global.screen==null?1024:i.env().global.screen.height*i.env().global.screen.width*window.devicePixelRatio*Au/1024/1024}var Fu=1e3,Go=function(f){M(p,f);function p(l){var m=f.call(this)||this;if(m.pendingRead=new WeakMap,m.pendingDisposal=new WeakSet,m.dataRefCount=new WeakMap,m.numBytesInGPU=0,m.uploadWaitMs=0,m.downloadWaitMs=0,m.warnedAboutMemory=!1,m.warnedAboutCPUBackend=!1,m.pendingDeletes=0,m.disposed=!1,!i.env().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(l==null){var g=z(i.env().getNumber("WEBGL_VERSION"));m.binaryCache=dr(i.env().getNumber("WEBGL_VERSION")),m.gpgpu=new Oe(g),m.canvas=g.canvas,m.gpgpuCreatedLocally=!0}else m.gpgpu=l,m.binaryCache={},m.gpgpuCreatedLocally=!1,m.canvas=l.gl.canvas;return m.textureManager=new Oa(m.gpgpu),m.numMBBeforeWarning=_c(),m.texData=new i.DataStorage(m,i.engine()),m}return p.prototype.numDataIds=function(){return this.texData.numDataIds()+(this.cpuBackend?this.cpuBackend.numDataIds():0)-this.pendingDeletes},p.prototype.write=function(l,m,g){if((i.env().getBool("WEBGL_CHECK_NUMERICAL_PROBLEMS")||i.env().getBool("DEBUG"))&&this.checkNumericalProblems(l),g==="complex64"&&l!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");var I={};return this.texData.set(I,{shape:m,dtype:g,values:l,usage:w.UPLOAD,refCount:1,complexParentRefCount:0}),I},p.prototype.incRef=function(l){var m=this.texData.get(l);m.refCount++},p.prototype.decRef=function(l){if(this.texData.has(l)){var m=this.texData.get(l);m.refCount--}},p.prototype.move=function(l,m,g,I){if(i.env().getBool("DEBUG")&&this.checkNumericalProblems(m),I==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(l,{shape:g,dtype:I,values:m,usage:w.UPLOAD,refCount:1,complexParentRefCount:0})},p.prototype.disposeIntermediateTensorInfo=function(l){var m=l.dataId;if(this.texData.has(m)){var g=this.texData.get(m);g.refCount--,g.refCount<1&&this.disposeData(m)}},p.prototype.readSync=function(l){var m=this.texData.get(l),g=m.values,I=m.dtype,R=m.complexTensorInfos,P=m.slice,L=m.shape,G=m.isPacked;if(P!=null){var Q=void 0;G?Q=new os(L,Ss):Q=new Mr(L,Ss);var ke=this.runWebGLProgram(Q,[{dataId:l,shape:L,dtype:I}],I),Ce=this.readSync(ke.dataId);return this.disposeIntermediateTensorInfo(ke),Ce}if(g!=null)return this.convertAndCacheOnCPU(l);if(I==="string")return g;var Fe=this.activeTimers!=null,Ee;Fe&&(Ee=i.util.now());var Ge;if(I==="complex64"){var Qe=this.readSync(R.real.dataId),s=this.readSync(R.imag.dataId);Ge=i.backend_util.mergeRealAndImagArrays(Qe,s)}else Ge=this.getValuesFromTexture(l);return Fe&&(this.downloadWaitMs+=i.util.now()-Ee),this.convertAndCacheOnCPU(l,Ge)},p.prototype.read=function(l){return V(this,void 0,void 0,function(){var m,g,I,R,P,L,G,Q,ke,Ce,Fe,Ee,Ge,Qe,s,u,r,o,h,b,T,O;return oe(this,function(q){switch(q.label){case 0:if(this.pendingRead.has(l))return m=this.pendingRead.get(l),[2,new Promise(function(Z){return m.push(Z)})];if(g=this.texData.get(l),I=g.values,R=g.shape,P=g.slice,L=g.dtype,G=g.complexTensorInfos,Q=g.isPacked,P!=null)return ke=void 0,Q?ke=new os(R,Ss):ke=new Mr(R,Ss),Ce=this.runWebGLProgram(ke,[{dataId:l,shape:R,dtype:L}],L),Fe=this.read(Ce.dataId),this.disposeIntermediateTensorInfo(Ce),[2,Fe];if(I!=null)return[2,this.convertAndCacheOnCPU(l)];if(!i.env().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&i.env().getNumber("WEBGL_VERSION")===2)throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");re
`}return f}();function mu(f,p,l){var m=f.indexOf(p),g=f.map(function(I,R){return R===m?I+" - "+l:I});return g.join()}function Pc(f){var p=f.inputs,l=f.backend,m=p.input,g=l.texData.get(m.dataId);return ho({inputs:{x:g.complexTensorInfos.imag},backend:l})}var Pu={kernelName:i.Imag,backendName:"webgl",kernelFunc:Pc};function bl(f,p,l){var m=[Ga(f.shape)].concat(Sa(f.shape)),g={dtype:f.dtype,shape:m,dataId:f.dataId},I=[Ga(p)].concat(Sa(p)),R=new ir(I,m),P=!0,L=l.runWebGLProgram(R,[g],f.dtype,null,P);return{dataId:L.dataId,shape:p,dtype:L.dtype}}function Ji(f){var p=f.inputs,l=f.backend,m=f.attrs,g=p.x,I=m.shape,R=l,P=i.util.sizeFromShape(g.shape),L=i.util.inferFromImplicitShape(I,P),G=i.util.sizeFromShape(L);i.util.assert(P===G,function(){return"The new shape ("+L+") has "+G+" elements and the old "+("shape ("+g.shape+") has "+P+" elements. The new shape and old ")+"shape must have the same number of elements."});var Q=R.texData.get(g.dataId);return Q.isPacked&&!xn(g.shape,L)&&!(Q.texture!==null&&xn(Q.shape,L))?bl(g,L,R):(R.incRef(g.dataId),{dataId:g.dataId,shape:L,dtype:g.dtype})}var Bu={kernelName:i.Reshape,backendName:"webgl",kernelFunc:Ji};function us(f,p,l){var m=f[0].dtype;if(m==="complex64"){var g=f.map(function(r){return $n({inputs:{input:r},backend:l})}),I=f.map(function(r){return Pc({inputs:{input:r},backend:l})}),R=us(g,p,l),P=us(I,p,l),L=po({inputs:{real:R,imag:P},backend:l});return g.forEach(function(r){return l.disposeIntermediateTensorInfo(r)}),I.forEach(function(r){return l.disposeIntermediateTensorInfo(r)}),l.disposeIntermediateTensorInfo(R),l.disposeIntermediateTensorInfo(P),L}if(f.length>i.env().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){var G=Math.floor(f.length/2),Q=us(f.slice(0,G),p,l),ke=us(f.slice(G),p,l),Ce=us([Q,ke],p,l);return l.disposeIntermediateTensorInfo(Q),l.disposeIntermediateTensorInfo(ke),Ce}if(i.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&f[0].shape.length>1){var Fe=new Lc(f.map(function(r){return r.shape}),p);return l.runWebGLProgram(Fe,f,m)}var Ee=i.backend_util.computeOutShape(f.map(function(r){return r.shape}),p),Ge=f.map(function(r){return Ji({inputs:{x:r},attrs:{shape:[-1,i.util.sizeFromShape(r.shape.slice(p))]},backend:l})}),Qe=new zc(Ge.map(function(r){return r.shape})),s=l.runWebGLProgram(Qe,Ge,m);Ge.forEach(function(r){return l.disposeIntermediateTensorInfo(r)});var u=Ji({inputs:{x:s},attrs:{shape:Ee},backend:l});return l.disposeIntermediateTensorInfo(s),u}function kl(f){var p=f.inputs,l=f.backend,m=f.attrs,g=m.axis,I=i.util.parseAxisParam(g,p[0].shape)[0],R=i.backend_util.computeOutShape(p.map(function(G){return G.shape}),I);if(i.util.sizeFromShape(R)===0)return l.makeTensorInfo(R,p[0].dtype,[]);var P=p.filter(function(G){return i.util.sizeFromShape(G.shape)>0});if(P.length===1)return P[0];var L=P.map(function(G){return G.shape});return i.backend_util.assertParamsConsistent(L,I),us(P,I,l)}var Bc={kernelName:i.Concat,backendName:"webgl",kernelFunc:kl},yu=hu+`
`,Gc=fo({opSnippet:Vc,packedOpSnippet:Hc,checkOutOfBounds:!0}),jc={kernelName:i.Div,backendName:"webgl",kernelFunc:Gc},Wu=function(){function f(p,l,m){this.variableNames=["real","imag"];var g=l[1];this.outputShape=l;var I=m?"2.0 * "+Math.PI:"-2.0 * "+Math.PI,R=m?g+".0":"1.0",P;if(p==="real")P="return real * expR - imag * expI;";else if(p==="imag")P="return real * expI + imag * expR;";else throw new Error('FFT component must be either "real" or "imag", got '+p+".");this.userCode=`
`}async function Xp(){if(Nn.busy)return null;Nn.busy=!0;const N=document.getElementById("video"),i=document.getElementById("canvas"),we=document.getElementById("log"),M=N.srcObject?N.srcObject.getVideoTracks()[0].readyState==="live"&&N.readyState>2&&!N.paused:!1;let V="";if(Xo("setting up camera"),!navigator.mediaDevices)return V="camera access not supported",we.innerText+=`
${V}`,Ko(V),Xo(V),null;let oe;const de={audio:!1,video:{facingMode:Nn.facing?"user":"environment",resizeMode:"none",width:{ideal:window.innerWidth},height:{ideal:window.innerHeight}}};try{oe=await navigator.mediaDevices.getUserMedia(de)}catch(z){z.name==="PermissionDeniedError"?V="camera permission denied":z.name==="SourceUnavailableError"?V="camera not available":V="camera error",we.innerText+=`
${V}`,Xo(V),Ko(z)}if(oe)N.srcObject=oe;else return null;const X=oe.getVideoTracks()[0],Te=X.getSettings();return Ko("camera constraints:",de,"window:",{width:window.innerWidth,height:window.innerHeight},"settings:",Te,"track:",X),bh={name:X.label,width:Te.width,height:Te.height,facing:Te.facingMode==="user"?"front":"back"},new Promise(z=>{N.onloadeddata=async()=>{N.width=N.videoWidth,N.height=N.videoHeight,i.width=N.width,i.height=N.height,i.style.width=i.width>i.height?"100vw":"",i.style.height=i.width>i.height?"":"100vh";const he=14+6*i.width/window.innerWidth;Nn.baseFont=Nn.baseFontProto.replace(/{size}/,`${he}px`),M&&N.play(),Nn.busy=!1,Xo(""),z(N)}})}function nx(N,i,we){uc||(Ko("creating worker thread"),uc=new Worker(Nn.worker,{type:"module"}),uc.warned=!1,uc.addEventListener("message",M=>{uc.warned||(Ko("warning: cannot transfer canvas from worked thread"),Ko("warning: image will not show filter effects"),uc.warned=!0),Kp(N,M.data.result,we)})),uc.postMessage({image:i.data.buffer,width:we.width,height:we.height},[i.data.buffer])}function qp(N,i){var M;jp=performance.now();const we=N.srcObject&&N.srcObject.getVideoTracks()[0].readyState==="live"&&N.readyState>2&&!N.paused;if(!we&&N.srcObject){N.srcObject.getVideoTracks()[0].readyState==="live"&&N.readyState<=2?setTimeout(()=>qp(N,i),500):Ko(`cameranotready:trackstate:${(M=N.srcObject)==null?void0:M.getVideoTracks()[0].readyState}streamstate:${N.readyState}`);return}if(Xo(""),Nn.useWorker){const V=new OffscreenCanvas(i.width,i.height),oe=V.getContext("2d");oe.drawImage(N,0,0,N.width,N.height,0,0,i.width,i.height);const de=oe.getImageData(0,0,i.width,i.height);nx(N,de,i)}else tr.detect(N).then(V=>{V.error?Ko(V.error):Kp(N,V,i),tr.config.profile&&Ko("profile data:",tr.profile())})}async function ax(N){return jp=performance.now(),new Promise(i=>{const we=new Image;we.onload=async()=>{Ko("Processing image:",we.src);const M=document.getElementById("canvas");we.width=we.naturalWidth,we.height=we.naturalHeight,M.width=tr.config.filter.width&&tr.config.filter.width>0?tr.config.filter.width:we.naturalWidth,M.height=tr.config.filter.height&&tr.config.filter.height>0?tr.config.filter.height:we.naturalHeight;const V=await tr.detect(we);Kp(we,V,M);const oe=document.createElement("canvas");oe.className="thumbnail",oe.width=window.innerWidth/(Nn.columns+.1),oe.height=M.height/(window.innerWidth/oe.width);const de=oe.getContext("2d");de.drawImage(M,0,0,M.width,M.height,0,0,oe.width,oe.height),document.getElementById("samples-container").appendChild(oe),we.src="",i(!0)},we.src=N})}async function ix(){tr.config.videoOptimized=!0,document.getElementById("samples-container").style.display="none",document.getElementById("canvas").style.display="block";const N=document.getElementById("video"),i=document.getElementById("canvas");Nn.baseLineHeight=Nn.baseLineHeightProto,N.srcObject!==null&&!N.paused?(document.getElementById("play").style.display="block",Xo("paused"),N.pause()):(await Xp(),document.getElementById("play").style.display="none",Xo(""),N.play()),qp(N,i)}async function ox(){document.getElementById("play").style.display="none",tr.config.videoOptimized=!1;const N=12+Math.trunc(12*Nn.columns*window.innerWidth/document.body.clientWidth);Nn.baseFont=Nn.baseFontProto.replace(/{size}/,`${N}px`),Nn.baseLineHeight=Nn.baseLineHeightProto*Nn.columns,document.getElementById("canvas").style.display="none",document.getElementById("samples-container").style.display="block",Ko("Running detection of sample images"),Xo("processing images"),document.getElementById("samples-container").innerHTML="";for(const i of Nn.samples)await ax(i);Xo("")}function sx(){Pn=new Gp(document.body,"...",{top:"1rem",right:"1rem"});const N=Pn.addButton("Start Video","Pause Video",()=>ix());Pn.addButton("Process Images","Process Images",()=>ox()),document.getElementById("play").addEventListener("click",()=>N.click()),Pn.addHTML('<hr style="min-width: 200px; border-style: inset; border-color: dimgray">'),Pn.addList("Backend",["cpu","webgl","wasm","webgpu"],tr.config.backend,i=>tr.config.backend=i),Pn.addBool("A